mirror of https://github.com/zulip/zulip.git
import_util: Support huddles in SubscriberHandler.
This commit is contained in:
parent
edee1251c8
commit
bf5f531e90
|
@ -22,16 +22,29 @@ ZerverFieldsT = Dict[str, Any]
|
|||
class SubscriberHandler:
|
||||
def __init__(self) -> None:
|
||||
self.stream_info = dict() # type: Dict[int, Set[int]]
|
||||
self.huddle_info = dict() # type: Dict[int, Set[int]]
|
||||
|
||||
def set_info(self,
|
||||
stream_id: int,
|
||||
users: Set[int]) -> None:
|
||||
self.stream_info[stream_id] = users
|
||||
users: Set[int],
|
||||
stream_id: Optional[int]=None,
|
||||
huddle_id: Optional[int]=None,
|
||||
) -> None:
|
||||
if stream_id is not None:
|
||||
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,
|
||||
stream_id: int) -> Set[int]:
|
||||
users = self.stream_info[stream_id]
|
||||
return users
|
||||
stream_id: Optional[int]=None,
|
||||
huddle_id: Optional[int]=None) -> Set[int]:
|
||||
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,
|
||||
other_product: str) -> List[ZerverFieldsT]:
|
||||
|
|
|
@ -188,9 +188,9 @@ class MatterMostImporter(ZulipTestCase):
|
|||
ron_id = user_id_mapper.get("ron")
|
||||
harry_id = user_id_mapper.get("harry")
|
||||
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_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("gryffindor-common-room")), {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=stream_id_mapper.get("dumbledores-army")), {ron_id, harry_id})
|
||||
|
||||
# Converting channel data when a user's `teams` value is `null`.
|
||||
self.username_to_user["ron"].update({"teams": None})
|
||||
|
@ -205,9 +205,9 @@ class MatterMostImporter(ZulipTestCase):
|
|||
)
|
||||
harry_id = user_id_mapper.get("harry")
|
||||
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_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("gryffindor-common-room")), {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=stream_id_mapper.get("dumbledores-army")), {harry_id})
|
||||
|
||||
team_name = "slytherin"
|
||||
zerver_stream = convert_channel_data(
|
||||
|
@ -224,8 +224,8 @@ class MatterMostImporter(ZulipTestCase):
|
|||
pansy_id = user_id_mapper.get("pansy")
|
||||
snape_id = user_id_mapper.get("snape")
|
||||
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_mapper.get("slytherin-quidditch-team")), {malfoy_id, pansy_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=stream_id_mapper.get("slytherin-quidditch-team")), {malfoy_id, pansy_id})
|
||||
|
||||
def test_write_emoticon_data(self) -> None:
|
||||
output_dir = self.make_import_output_dir("mattermost")
|
||||
|
|
Loading…
Reference in New Issue