From 0028b37573b802a21f1b4328da011cd2c0ea5686 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Thu, 18 Feb 2021 18:42:55 +0000 Subject: [PATCH] Fix tests; update them to check new call arguments The List type args were changed to Iterables as we now pass Sets to this method instead. Iterable is more correct as well, as the method only iterates over it (and passes the state to send_presence, which also wants an Iterable). --- synapse/federation/sender/__init__.py | 2 +- synapse/handlers/presence.py | 2 +- tests/handlers/test_presence.py | 14 ++++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/synapse/federation/sender/__init__.py b/synapse/federation/sender/__init__.py index 97fc4d0a82b4..24ebc4b8031f 100644 --- a/synapse/federation/sender/__init__.py +++ b/synapse/federation/sender/__init__.py @@ -474,7 +474,7 @@ async def send_presence(self, states: List[UserPresenceState]): self._processing_pending_presence = False def send_presence_to_destinations( - self, states: List[UserPresenceState], destinations: List[str] + self, states: Iterable[UserPresenceState], destinations: Iterable[str] ) -> None: """Send the given presence states to the given destinations. destinations (list[str]) diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 9dbc37ef72f2..58d064b96d27 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -898,7 +898,7 @@ async def _handle_state_delta(self, deltas): # Send out user presence updates for each destination for destination, user_state_set in presence_destinations.items(): self.federation.send_presence_to_destinations( - states=user_state_set, destinations=[destination] + destinations=[destination], states=user_state_set ) async def _on_user_joined_room( diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py index be2ee26f07cf..996c6141982a 100644 --- a/tests/handlers/test_presence.py +++ b/tests/handlers/test_presence.py @@ -521,7 +521,7 @@ def test_remote_joins(self): ) self.assertEqual(expected_state.state, PresenceState.ONLINE) self.federation_sender.send_presence_to_destinations.assert_called_once_with( - destinations=["server2"], states=[expected_state] + destinations=["server2"], states={expected_state} ) # @@ -533,7 +533,7 @@ def test_remote_joins(self): self.federation_sender.send_presence.assert_not_called() self.federation_sender.send_presence_to_destinations.assert_called_once_with( - destinations=["server3"], states=[expected_state] + destinations=["server3"], states={expected_state} ) def test_remote_gets_presence_when_local_user_joins(self): @@ -584,8 +584,14 @@ def test_remote_gets_presence_when_local_user_joins(self): self.presence_handler.current_state_for_user("@test2:server") ) self.assertEqual(expected_state.state, PresenceState.ONLINE) - self.federation_sender.send_presence_to_destinations.assert_called_once_with( - destinations={"server2", "server3"}, states=[expected_state] + self.assertEqual( + self.federation_sender.send_presence_to_destinations.call_count, 2 + ) + self.federation_sender.send_presence_to_destinations.assert_any_call( + destinations=["server3"], states={expected_state} + ) + self.federation_sender.send_presence_to_destinations.assert_any_call( + destinations=["server2"], states={expected_state} ) def _add_new_user(self, room_id, user_id):