def test_write_emoticon_data(self) -> None: fixture_dir_name = self.fixture_file_name("", "rocketchat_fixtures") rocketchat_data = rocketchat_data_to_dict(fixture_dir_name) output_dir = self.make_import_output_dir("rocketchat") with self.assertLogs(level="INFO"): zerver_realmemoji = build_custom_emoji( realm_id=3, custom_emoji_data=rocketchat_data["custom_emoji"], output_dir=output_dir, ) self.assert_length(zerver_realmemoji, 5) self.assertEqual(zerver_realmemoji[0]["name"], "tick") self.assertEqual(zerver_realmemoji[0]["file_name"], "tick.png") self.assertEqual(zerver_realmemoji[0]["realm"], 3) self.assertEqual(zerver_realmemoji[0]["deactivated"], False) self.assertEqual(zerver_realmemoji[1]["name"], "check") self.assertEqual(zerver_realmemoji[1]["file_name"], "tick.png") self.assertEqual(zerver_realmemoji[1]["realm"], 3) self.assertEqual(zerver_realmemoji[1]["deactivated"], False) self.assertEqual(zerver_realmemoji[2]["name"], "zulip") self.assertEqual(zerver_realmemoji[2]["file_name"], "zulip.png") self.assertEqual(zerver_realmemoji[2]["realm"], 3) self.assertEqual(zerver_realmemoji[2]["deactivated"], False) records_file = os.path.join(output_dir, "emoji", "records.json") with open(records_file, "rb") as f: records_json = orjson.loads(f.read()) self.assertEqual(records_json[0]["name"], "tick") self.assertEqual(records_json[0]["file_name"], "tick.png") self.assertEqual(records_json[0]["realm_id"], 3) self.assertEqual(records_json[1]["name"], "check") self.assertEqual(records_json[1]["file_name"], "tick.png") self.assertEqual(records_json[1]["realm_id"], 3) self.assertTrue(os.path.isfile(records_json[0]["path"])) self.assertEqual(records_json[2]["name"], "zulip") self.assertEqual(records_json[2]["file_name"], "zulip.png") self.assertEqual(records_json[2]["realm_id"], 3) self.assertTrue(os.path.isfile(records_json[2]["path"]))
def test_build_reactions(self) -> None: fixture_dir_name = self.fixture_file_name("", "rocketchat_fixtures") rocketchat_data = rocketchat_data_to_dict(fixture_dir_name) output_dir = self.make_import_output_dir("rocketchat") with self.assertLogs(level="INFO"): zerver_realmemoji = build_custom_emoji( realm_id=3, custom_emoji_data=rocketchat_data["custom_emoji"], output_dir=output_dir, ) total_reactions: List[ZerverFieldsT] = [] reactions = [ { "name": "grin", "user_id": 3 }, { "name": "grinning", "user_id": 3 }, { "name": "innocent", "user_id": 2 }, { "name": "star_struck", "user_id": 4 }, { "name": "heart", "user_id": 3 }, { "name": "rocket", "user_id": 4 }, { "name": "check", "user_id": 2 }, { "name": "zulip", "user_id": 3 }, { "name": "harry-ron", "user_id": 4 }, ] build_reactions( total_reactions=total_reactions, reactions=reactions, message_id=3, zerver_realmemoji=zerver_realmemoji, ) # :grin: and :star_struck: are not present in Zulip's default # emoji set, or in Reaction.UNICODE_EMOJI reaction type. self.assert_length(total_reactions, 7) grinning_emoji_code = name_to_codepoint["grinning"] innocent_emoji_code = name_to_codepoint["innocent"] heart_emoji_code = name_to_codepoint["heart"] rocket_emoji_code = name_to_codepoint["rocket"] realmemoji_code = {} for emoji in zerver_realmemoji: realmemoji_code[emoji["name"]] = emoji["id"] self.assertEqual( self.get_set(total_reactions, "reaction_type"), {Reaction.UNICODE_EMOJI, Reaction.REALM_EMOJI}, ) self.assertEqual( self.get_set(total_reactions, "emoji_name"), { "grinning", "innocent", "heart", "rocket", "check", "zulip", "harry-ron" }, ) self.assertEqual( self.get_set(total_reactions, "emoji_code"), { grinning_emoji_code, innocent_emoji_code, heart_emoji_code, rocket_emoji_code, realmemoji_code["check"], realmemoji_code["zulip"], realmemoji_code["harry-ron"], }, ) self.assertEqual(self.get_set(total_reactions, "user_profile"), {2, 3, 4}) self.assert_length(self.get_set(total_reactions, "id"), 7) self.assert_length(self.get_set(total_reactions, "message"), 1)