Ejemplo n.º 1
0
    def test_convert_huddle_data(self) -> None:
        fixture_dir_name = self.fixture_file_name("", "rocketchat_fixtures")
        rocketchat_data = rocketchat_data_to_dict(fixture_dir_name)

        realm_id = 3
        domain_name = "zulip.com"

        user_handler = UserHandler()
        subscriber_handler = SubscriberHandler()
        user_id_mapper = IdMapper()
        huddle_id_mapper = IdMapper()

        user_id_to_user_map = map_user_id_to_user(rocketchat_data["user"])

        process_users(
            user_id_to_user_map=user_id_to_user_map,
            realm_id=realm_id,
            domain_name=domain_name,
            user_handler=user_handler,
            user_id_mapper=user_id_mapper,
        )

        room_id_to_room_map: Dict[str, Dict[str, Any]] = {}
        team_id_to_team_map: Dict[str, Dict[str, Any]] = {}
        dsc_id_to_dsc_map: Dict[str, Dict[str, Any]] = {}
        direct_id_to_direct_map: Dict[str, Dict[str, Any]] = {}
        huddle_id_to_huddle_map: Dict[str, Dict[str, Any]] = {}
        livechat_id_to_livechat_map: Dict[str, Dict[str, Any]] = {}

        categorize_channels_and_map_with_id(
            channel_data=rocketchat_data["room"],
            room_id_to_room_map=room_id_to_room_map,
            team_id_to_team_map=team_id_to_team_map,
            dsc_id_to_dsc_map=dsc_id_to_dsc_map,
            direct_id_to_direct_map=direct_id_to_direct_map,
            huddle_id_to_huddle_map=huddle_id_to_huddle_map,
            livechat_id_to_livechat_map=livechat_id_to_livechat_map,
        )

        zerver_huddle = convert_huddle_data(
            huddle_id_to_huddle_map=huddle_id_to_huddle_map,
            huddle_id_mapper=huddle_id_mapper,
            user_id_mapper=user_id_mapper,
            subscriber_handler=subscriber_handler,
        )

        self.assert_length(zerver_huddle, 1)

        rc_huddle_id = rocketchat_data["room"][12]["_id"]
        self.assertTrue(huddle_id_mapper.has(rc_huddle_id))

        huddle_id = huddle_id_mapper.get(rc_huddle_id)
        self.assertEqual(subscriber_handler.get_users(huddle_id=huddle_id),
                         {3, 4, 5})
    def test_map_receiver_id_to_recipient_id(self) -> None:
        fixture_dir_name = self.fixture_file_name("", "rocketchat_fixtures")
        rocketchat_data = rocketchat_data_to_dict(fixture_dir_name)

        realm_id = 3
        domain_name = "zulip.com"

        user_handler = UserHandler()
        subscriber_handler = SubscriberHandler()
        user_id_mapper = IdMapper()
        stream_id_mapper = IdMapper()
        huddle_id_mapper = IdMapper()

        user_id_to_user_map = map_user_id_to_user(rocketchat_data["user"])

        process_users(
            user_id_to_user_map=user_id_to_user_map,
            realm_id=realm_id,
            domain_name=domain_name,
            user_handler=user_handler,
            user_id_mapper=user_id_mapper,
        )

        room_id_to_room_map: Dict[str, Dict[str, Any]] = {}
        team_id_to_team_map: Dict[str, Dict[str, Any]] = {}
        dsc_id_to_dsc_map: Dict[str, Dict[str, Any]] = {}
        direct_id_to_direct_map: Dict[str, Dict[str, Any]] = {}
        huddle_id_to_huddle_map: Dict[str, Dict[str, Any]] = {}

        categorize_channels_and_map_with_id(
            channel_data=rocketchat_data["room"],
            room_id_to_room_map=room_id_to_room_map,
            team_id_to_team_map=team_id_to_team_map,
            dsc_id_to_dsc_map=dsc_id_to_dsc_map,
            direct_id_to_direct_map=direct_id_to_direct_map,
            huddle_id_to_huddle_map=huddle_id_to_huddle_map,
        )

        zerver_stream = convert_channel_data(
            room_id_to_room_map=room_id_to_room_map,
            team_id_to_team_map=team_id_to_team_map,
            stream_id_mapper=stream_id_mapper,
            realm_id=realm_id,
        )

        zerver_huddle = convert_huddle_data(
            huddle_id_to_huddle_map=huddle_id_to_huddle_map,
            huddle_id_mapper=huddle_id_mapper,
            user_id_mapper=user_id_mapper,
            subscriber_handler=subscriber_handler,
        )

        all_users = user_handler.get_all_users()

        zerver_recipient = build_recipients(
            zerver_userprofile=all_users,
            zerver_stream=zerver_stream,
            zerver_huddle=zerver_huddle,
        )

        stream_id_to_recipient_id: Dict[int, int] = {}
        user_id_to_recipient_id: Dict[int, int] = {}
        huddle_id_to_recipient_id: Dict[int, int] = {}

        map_receiver_id_to_recipient_id(
            zerver_recipient=zerver_recipient,
            stream_id_to_recipient_id=stream_id_to_recipient_id,
            user_id_to_recipient_id=user_id_to_recipient_id,
            huddle_id_to_recipient_id=huddle_id_to_recipient_id,
        )

        # 6 for streams and 6 for users.
        self.assert_length(zerver_recipient, 13)
        self.assert_length(stream_id_to_recipient_id, 6)
        self.assert_length(user_id_to_recipient_id, 6)
        self.assert_length(huddle_id_to_recipient_id, 1)

        # First user recipients are built, followed by stream recipients in `build_recipients`.
        self.assertEqual(
            user_id_to_recipient_id[zerver_recipient[0]["type_id"]],
            zerver_recipient[0]["id"])
        self.assertEqual(
            user_id_to_recipient_id[zerver_recipient[1]["type_id"]],
            zerver_recipient[1]["id"])

        self.assertEqual(
            stream_id_to_recipient_id[zerver_recipient[6]["type_id"]],
            zerver_recipient[6]["id"])
        self.assertEqual(
            stream_id_to_recipient_id[zerver_recipient[7]["type_id"]],
            zerver_recipient[7]["id"])

        self.assertEqual(
            huddle_id_to_recipient_id[zerver_recipient[12]["type_id"]],
            zerver_recipient[12]["id"])