test_import_export: Add test coverage for OnboardingUserMessage.

This commit is contained in:
Prakhar Pratyush 2024-07-22 20:21:07 +05:30 committed by Tim Abbott
parent e0bcf72521
commit 6838a7302d
1 changed files with 44 additions and 0 deletions

View File

@ -69,6 +69,7 @@ from zerver.models import (
MutedUser,
NamedUserGroup,
OnboardingStep,
OnboardingUserMessage,
Reaction,
Realm,
RealmAuditLog,
@ -435,6 +436,16 @@ class RealmImportExportTest(ExportFile):
realm_user_default.default_language = "de"
realm_user_default.save()
welcome_bot = get_system_bot(settings.WELCOME_BOT, realm.id)
onboarding_message_id = self.send_stream_message(
welcome_bot, str(Realm.ZULIP_SANDBOX_CHANNEL_NAME), recipient_realm=realm
)
OnboardingUserMessage.objects.create(
realm=realm,
message_id=onboarding_message_id,
flags=OnboardingUserMessage.flags.starred,
)
self.export_realm_and_create_auditlog(realm)
data = read_json("realm.json")
@ -487,6 +498,15 @@ class RealmImportExportTest(ExportFile):
self.assertFalse("direct_members" in exported_namedusergroups[2])
self.assertFalse("direct_subgroups" in exported_namedusergroups[2])
exported_onboarding_usermessages = data["zerver_onboardingusermessage"]
self.assert_length(exported_onboarding_usermessages, 1)
self.assertEqual(exported_onboarding_usermessages[0]["message"], onboarding_message_id)
self.assertEqual(
exported_onboarding_usermessages[0]["flags_mask"],
OnboardingUserMessage.flags.starred.mask,
)
self.assertEqual(exported_onboarding_usermessages[0]["realm"], realm.id)
data = read_json("messages-000001.json")
um = UserMessage.objects.all()[0]
exported_um = self.find_by_id(data["zerver_usermessage"], um.id)
@ -932,6 +952,19 @@ class RealmImportExportTest(ExportFile):
realm_user_default.twenty_four_hour_time = True
realm_user_default.save()
# Data to test import of onboarding usermessages
onboarding_message_id = self.send_stream_message(
cross_realm_bot,
str(Realm.ZULIP_SANDBOX_CHANNEL_NAME),
"onboarding message",
recipient_realm=original_realm,
)
OnboardingUserMessage.objects.create(
realm=original_realm,
message_id=onboarding_message_id,
flags=OnboardingUserMessage.flags.starred,
)
# We want to have an extra, malformed RealmEmoji with no .author
# to test that upon import that gets fixed.
with get_test_image_file("img.png") as img_file:
@ -1488,6 +1521,17 @@ class RealmImportExportTest(ExportFile):
"twenty_four_hour_time": realm_user_default.twenty_four_hour_time,
}
@getter
def get_onboarding_usermessages(r: Realm) -> set[tuple[str, Any]]:
tups = {
(rec.message.content, rec.flags.mask)
for rec in OnboardingUserMessage.objects.filter(realm_id=r.id)
}
self.assertEqual(
tups, {("onboarding message", OnboardingUserMessage.flags.starred.mask)}
)
return tups
return getters
def test_import_realm_with_invalid_email_addresses_fails_validation(self) -> None: