mirror of https://github.com/zulip/zulip.git
slack importer: Cleanup build_zerver_usermessage.
This commit is contained in:
parent
b358fb2c42
commit
5efe05d5b6
|
@ -600,7 +600,7 @@ def channel_message_to_zerver_message(REALM_ID: int, users: List[ZerverFieldsT],
|
|||
zerver_message.append(zulip_message)
|
||||
|
||||
# construct usermessages
|
||||
zerver_usermessage, usermessage_id_count = build_zerver_usermessage(
|
||||
usermessage_id_count = build_zerver_usermessage(
|
||||
zerver_usermessage, usermessage_id_count, usermessage_id_list,
|
||||
zerver_subscription, recipient_id, mentioned_users_id, message_id)
|
||||
|
||||
|
@ -617,8 +617,7 @@ def get_message_sending_user(message: ZerverFieldsT) -> str:
|
|||
def build_zerver_usermessage(zerver_usermessage: List[ZerverFieldsT], usermessage_id_count: int,
|
||||
usermessage_id_list: List[int],
|
||||
zerver_subscription: List[ZerverFieldsT], recipient_id: int,
|
||||
mentioned_users_id: List[int],
|
||||
message_id: int) -> Tuple[List[ZerverFieldsT], int]:
|
||||
mentioned_users_id: List[int], message_id: int) -> int:
|
||||
for subscription in zerver_subscription:
|
||||
if subscription['recipient'] == recipient_id:
|
||||
flags_mask = 1 # For read
|
||||
|
@ -632,7 +631,7 @@ def build_zerver_usermessage(zerver_usermessage: List[ZerverFieldsT], usermessag
|
|||
message=message_id)
|
||||
usermessage_id_count += 1
|
||||
zerver_usermessage.append(usermessage)
|
||||
return zerver_usermessage, usermessage_id_count
|
||||
return usermessage_id_count
|
||||
|
||||
def do_convert_data(slack_zip_file: str, realm_subdomain: str, output_dir: str, token: str) -> None:
|
||||
check_subdomain_available(realm_subdomain)
|
||||
|
|
|
@ -392,25 +392,21 @@ class SlackImporter(ZulipTestCase):
|
|||
mentioned_users_id = [12, 3, 16]
|
||||
message_id = 9
|
||||
|
||||
test_zerver_usermessage, test_usermessage_id = build_zerver_usermessage(zerver_usermessage,
|
||||
usermessage_id_count,
|
||||
usermessage_id_list,
|
||||
zerver_subscription,
|
||||
recipient_id,
|
||||
mentioned_users_id,
|
||||
message_id)
|
||||
test_usermessage_id = build_zerver_usermessage(zerver_usermessage, usermessage_id_count,
|
||||
usermessage_id_list, zerver_subscription,
|
||||
recipient_id, mentioned_users_id, message_id)
|
||||
self.assertEqual(test_usermessage_id, 4)
|
||||
|
||||
self.assertEqual(test_zerver_usermessage[0]['flags_mask'], 1)
|
||||
self.assertEqual(test_zerver_usermessage[0]['id'], 3)
|
||||
self.assertEqual(test_zerver_usermessage[0]['message'], message_id)
|
||||
self.assertEqual(test_zerver_usermessage[1]['user_profile'],
|
||||
self.assertEqual(zerver_usermessage[0]['flags_mask'], 1)
|
||||
self.assertEqual(zerver_usermessage[0]['id'], 3)
|
||||
self.assertEqual(zerver_usermessage[0]['message'], message_id)
|
||||
self.assertEqual(zerver_usermessage[1]['user_profile'],
|
||||
zerver_subscription[2]['user_profile'])
|
||||
self.assertEqual(test_zerver_usermessage[1]['flags_mask'], 9)
|
||||
self.assertEqual(test_zerver_usermessage[3]['id'], 11)
|
||||
self.assertEqual(test_zerver_usermessage[3]['message'], message_id)
|
||||
self.assertEqual(zerver_usermessage[1]['flags_mask'], 9)
|
||||
self.assertEqual(zerver_usermessage[3]['id'], 11)
|
||||
self.assertEqual(zerver_usermessage[3]['message'], message_id)
|
||||
|
||||
@mock.patch("zerver.lib.slack_data_to_zulip_data.build_zerver_usermessage", return_value = [[], 2])
|
||||
@mock.patch("zerver.lib.slack_data_to_zulip_data.build_zerver_usermessage", return_value = 2)
|
||||
def test_channel_message_to_zerver_message(self, mock_build_zerver_usermessage: mock.Mock) -> None:
|
||||
|
||||
user_data = [{"id": "U066MTL5U", "name": "john doe", "deleted": False, "real_name": "John"},
|
||||
|
|
Loading…
Reference in New Issue