Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tests: Verify emoji codes.
Steve Howell6ec5a5193ad7
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex 9f991bcdad8..7abf2cecaaa 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -82,7 +82,9 @@ from zerver.lib.webhooks.common import (from zerver.models import (Client,Message,+ Reaction,Realm,+ RealmEmoji,Recipient,Stream,Subscription,@@ -1412,6 +1414,34 @@ Output:),)+ def verify_emoji_code_foreign_keys(self) -> None:+ """+ DB tables that refer to RealmEmoji use int(emoji_code) as the+ foreign key. Those tables tend to de-normalize emoji_name due+ to our inherintance-based setup. This helper makes sure those+ invariants are intact, which is particularly tricky during+ the import/export process (or during conversions from things+ like Slack/RocketChat/MatterMost/etc.).+ """+ dct = {}++ for row in RealmEmoji.objects.all():+ dct[row.id] = row++ if not dct:+ raise AssertionError("test needs RealmEmoji rows")++ count = 0+ for row in Reaction.objects.filter(reaction_type=Reaction.REALM_EMOJI):+ realm_emoji_id = int(row.emoji_code)+ assert realm_emoji_id in dct+ self.assertEqual(dct[realm_emoji_id].name, row.emoji_name)+ self.assertEqual(dct[realm_emoji_id].realm_id, row.user_profile.realm_id)+ count += 1++ if count == 0:+ raise AssertionError("test is meaningless without any pertinent rows")+class WebhookTestCase(ZulipTestCase):"""Shared test class for all incoming webhooks tests.diff --git a/zerver/tests/test_mattermost_importer.py b/zerver/tests/test_mattermost_importer.pyindex a2c71f592f8..cc1101dd383 100644--- a/zerver/tests/test_mattermost_importer.py+++ b/zerver/tests/test_mattermost_importer.py@@ -719,6 +719,8 @@ class MatterMostImporter(ZulipTestCase):for message in messages:self.assertIsNotNone(message.rendered_content)+ self.verify_emoji_code_foreign_keys()+def test_do_convert_data_with_direct_messages(self) -> None:mattermost_data_dir = self.fixture_file_name("direct_channel", "mattermost_fixtures")output_dir = self.make_import_output_dir("mattermost")@@ -914,3 +916,5 @@ class MatterMostImporter(ZulipTestCase):messages = Message.objects.filter(sender__in=realm_users)for message in messages:self.assertIsNotNone(message.rendered_content)++ self.verify_emoji_code_foreign_keys()diff --git a/zerver/tests/test_rocketchat_importer.py b/zerver/tests/test_rocketchat_importer.pyindex c12c19d76db..d1c7b92af50 100644--- a/zerver/tests/test_rocketchat_importer.py+++ b/zerver/tests/test_rocketchat_importer.py@@ -1025,3 +1025,5 @@ class RocketChatImporter(ZulipTestCase):personal_messages[0].content,"Hey @**Hermione Granger** :grin:, how's everything going?",)++ self.verify_emoji_code_foreign_keys()