import_util: Support huddles in SubscriberHandler.

This commit is contained in:
Vishnu Ks 2019-08-27 10:01:07 +00:00 committed by Tim Abbott
parent edee1251c8
commit bf5f531e90
2 changed files with 27 additions and 14 deletions

View File

@ -22,16 +22,29 @@ ZerverFieldsT = Dict[str, Any]
class SubscriberHandler: class SubscriberHandler:
def __init__(self) -> None: def __init__(self) -> None:
self.stream_info = dict() # type: Dict[int, Set[int]] self.stream_info = dict() # type: Dict[int, Set[int]]
self.huddle_info = dict() # type: Dict[int, Set[int]]
def set_info(self, def set_info(self,
stream_id: int, users: Set[int],
users: Set[int]) -> None: stream_id: Optional[int]=None,
huddle_id: Optional[int]=None,
) -> None:
if stream_id is not None:
self.stream_info[stream_id] = users self.stream_info[stream_id] = users
elif huddle_id is not None:
self.huddle_info[huddle_id] = users
else:
raise AssertionError("stream_id or huddle_id is required")
def get_users(self, def get_users(self,
stream_id: int) -> Set[int]: stream_id: Optional[int]=None,
users = self.stream_info[stream_id] huddle_id: Optional[int]=None) -> Set[int]:
return users if stream_id is not None:
return self.stream_info[stream_id]
elif huddle_id is not None:
return self.huddle_info[huddle_id]
else:
raise AssertionError("stream_id or huddle_id is required")
def build_zerver_realm(realm_id: int, realm_subdomain: str, time: float, def build_zerver_realm(realm_id: int, realm_subdomain: str, time: float,
other_product: str) -> List[ZerverFieldsT]: other_product: str) -> List[ZerverFieldsT]:

View File

@ -188,9 +188,9 @@ class MatterMostImporter(ZulipTestCase):
ron_id = user_id_mapper.get("ron") ron_id = user_id_mapper.get("ron")
harry_id = user_id_mapper.get("harry") harry_id = user_id_mapper.get("harry")
self.assertEqual({ron_id, harry_id}, {1, 2}) self.assertEqual({ron_id, harry_id}, {1, 2})
self.assertEqual(subscriber_handler.get_users(stream_id_mapper.get("gryffindor-common-room")), {ron_id, harry_id}) self.assertEqual(subscriber_handler.get_users(stream_id=stream_id_mapper.get("gryffindor-common-room")), {ron_id, harry_id})
self.assertEqual(subscriber_handler.get_users(stream_id_mapper.get("gryffindor-quidditch-team")), {ron_id, harry_id}) self.assertEqual(subscriber_handler.get_users(stream_id=stream_id_mapper.get("gryffindor-quidditch-team")), {ron_id, harry_id})
self.assertEqual(subscriber_handler.get_users(stream_id_mapper.get("dumbledores-army")), {ron_id, harry_id}) self.assertEqual(subscriber_handler.get_users(stream_id=stream_id_mapper.get("dumbledores-army")), {ron_id, harry_id})
# Converting channel data when a user's `teams` value is `null`. # Converting channel data when a user's `teams` value is `null`.
self.username_to_user["ron"].update({"teams": None}) self.username_to_user["ron"].update({"teams": None})
@ -205,9 +205,9 @@ class MatterMostImporter(ZulipTestCase):
) )
harry_id = user_id_mapper.get("harry") harry_id = user_id_mapper.get("harry")
self.assertIn(harry_id, {1, 2}) self.assertIn(harry_id, {1, 2})
self.assertEqual(subscriber_handler.get_users(stream_id_mapper.get("gryffindor-common-room")), {harry_id}) self.assertEqual(subscriber_handler.get_users(stream_id=stream_id_mapper.get("gryffindor-common-room")), {harry_id})
self.assertEqual(subscriber_handler.get_users(stream_id_mapper.get("gryffindor-quidditch-team")), {harry_id}) self.assertEqual(subscriber_handler.get_users(stream_id=stream_id_mapper.get("gryffindor-quidditch-team")), {harry_id})
self.assertEqual(subscriber_handler.get_users(stream_id_mapper.get("dumbledores-army")), {harry_id}) self.assertEqual(subscriber_handler.get_users(stream_id=stream_id_mapper.get("dumbledores-army")), {harry_id})
team_name = "slytherin" team_name = "slytherin"
zerver_stream = convert_channel_data( zerver_stream = convert_channel_data(
@ -224,8 +224,8 @@ class MatterMostImporter(ZulipTestCase):
pansy_id = user_id_mapper.get("pansy") pansy_id = user_id_mapper.get("pansy")
snape_id = user_id_mapper.get("snape") snape_id = user_id_mapper.get("snape")
self.assertEqual({malfoy_id, pansy_id, snape_id}, {3, 4, 5}) self.assertEqual({malfoy_id, pansy_id, snape_id}, {3, 4, 5})
self.assertEqual(subscriber_handler.get_users(stream_id_mapper.get("slytherin-common-room")), {malfoy_id, pansy_id, snape_id}) self.assertEqual(subscriber_handler.get_users(stream_id=stream_id_mapper.get("slytherin-common-room")), {malfoy_id, pansy_id, snape_id})
self.assertEqual(subscriber_handler.get_users(stream_id_mapper.get("slytherin-quidditch-team")), {malfoy_id, pansy_id}) self.assertEqual(subscriber_handler.get_users(stream_id=stream_id_mapper.get("slytherin-quidditch-team")), {malfoy_id, pansy_id})
def test_write_emoticon_data(self) -> None: def test_write_emoticon_data(self) -> None:
output_dir = self.make_import_output_dir("mattermost") output_dir = self.make_import_output_dir("mattermost")