@defer.inlineCallbacks
    def setUp(self):
        self.clock = MockClock()

        self.mock_http_client = Mock(spec=[])
        self.mock_http_client.put_json = DeferredMockCallable()

        self.mock_federation_resource = MockHttpResource()

        mock_notifier = Mock(spec=["on_new_event"])
        self.on_new_event = mock_notifier.on_new_event

        self.auth = Mock(spec=[])

        hs = yield setup_test_homeserver(
            auth=self.auth,
            clock=self.clock,
            datastore=Mock(spec=[
                # Bits that Federation needs
                "prep_send_transaction",
                "delivered_txn",
                "get_received_txn_response",
                "set_received_txn_response",
                "get_destination_retry_timings",
            ]),
            handlers=None,
            notifier=mock_notifier,
            resource_for_client=Mock(),
            resource_for_federation=self.mock_federation_resource,
            http_client=self.mock_http_client,
            keyring=Mock(),
        )
        hs.handlers = JustTypingNotificationHandlers(hs)

        self.handler = hs.get_handlers().typing_notification_handler

        self.event_source = hs.get_event_sources().sources["typing"]

        self.datastore = hs.get_datastore()
        retry_timings_res = {
            "destination": "",
            "retry_last_ts": 0,
            "retry_interval": 0,
        }
        self.datastore.get_destination_retry_timings.return_value = (
            defer.succeed(retry_timings_res)
        )

        def get_received_txn_response(*args):
            return defer.succeed(None)
        self.datastore.get_received_txn_response = get_received_txn_response

        self.room_id = "a-room"

        # Mock the RoomMemberHandler
        hs.handlers.room_member_handler = Mock(spec=[])
        self.room_member_handler = hs.handlers.room_member_handler

        self.room_members = []

        def get_rooms_for_user(user):
            if user in self.room_members:
                return defer.succeed([self.room_id])
            else:
                return defer.succeed([])
        self.room_member_handler.get_rooms_for_user = get_rooms_for_user

        def get_room_members(room_id):
            if room_id == self.room_id:
                return defer.succeed(self.room_members)
            else:
                return defer.succeed([])
        self.room_member_handler.get_room_members = get_room_members

        def get_joined_rooms_for_user(user):
            if self.room_members in user:
                return defer.succeed([self.room_id])
            else:
                return defer.succeed([])
        self.room_member_handler.get_joined_rooms_for_user = get_joined_rooms_for_user

        @defer.inlineCallbacks
        def fetch_room_distributions_into(
            room_id, localusers=None, remotedomains=None, ignore_user=None
        ):
            members = yield get_room_members(room_id)
            for member in members:
                if ignore_user is not None and member == ignore_user:
                    continue

                if hs.is_mine(member):
                    if localusers is not None:
                        localusers.add(member)
                else:
                    if remotedomains is not None:
                        remotedomains.add(member.domain)
        self.room_member_handler.fetch_room_distributions_into = (
            fetch_room_distributions_into
        )

        def check_joined_room(room_id, user_id):
            if user_id not in [u.to_string() for u in self.room_members]:
                raise AuthError(401, "User is not in the room")

        self.auth.check_joined_room = check_joined_room

        # Some local users to test with
        self.u_apple = UserID.from_string("@apple:test")
        self.u_banana = UserID.from_string("@banana:test")

        # Remote user
        self.u_onion = UserID.from_string("@onion:farm")
dataset/ETHPy150Open matrix-org/synapse/tests/handlers/test_typing.py/TypingNotificationsTestCase.setUp/swapped operands of `in`