diff options
author | Sean Quah <8349537+squahtx@users.noreply.github.com> | 2021-10-12 11:24:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-12 11:24:05 +0100 |
commit | b8b905c4ea8a0d922d34d469f7d220f53def1b53 (patch) | |
tree | a3d209e24324f9eed6f491afe321ff4482d0678e /tests/storage/test_client_ips.py | |
parent | Fix opentracing and Prometheus metrics for replication requests (#10996) (diff) | |
download | synapse-b8b905c4ea8a0d922d34d469f7d220f53def1b53.tar.xz |
Fix inconsistent behavior of `get_last_client_by_ip` (#10970)
Make `get_last_client_by_ip` return the same dictionary structure regardless of whether the data has been persisted to the database. This change will allow slightly cleaner type hints to be applied later on.
Diffstat (limited to 'tests/storage/test_client_ips.py')
-rw-r--r-- | tests/storage/test_client_ips.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/storage/test_client_ips.py b/tests/storage/test_client_ips.py index dada4f98c9..0e4013ebea 100644 --- a/tests/storage/test_client_ips.py +++ b/tests/storage/test_client_ips.py @@ -147,6 +147,49 @@ class ClientIpStoreTestCase(unittest.HomeserverTestCase): ) @parameterized.expand([(False,), (True,)]) + def test_get_last_client_ip_by_device(self, after_persisting: bool): + """Test `get_last_client_ip_by_device` for persisted and unpersisted data""" + self.reactor.advance(12345678) + + user_id = "@user:id" + device_id = "MY_DEVICE" + + # Insert a user IP + self.get_success( + self.store.store_device( + user_id, + device_id, + "display name", + ) + ) + self.get_success( + self.store.insert_client_ip( + user_id, "access_token", "ip", "user_agent", device_id + ) + ) + + if after_persisting: + # Trigger the storage loop + self.reactor.advance(10) + + result = self.get_success( + self.store.get_last_client_ip_by_device(user_id, device_id) + ) + + self.assertEqual( + result, + { + (user_id, device_id): { + "user_id": user_id, + "device_id": device_id, + "ip": "ip", + "user_agent": "user_agent", + "last_seen": 12345678000, + }, + }, + ) + + @parameterized.expand([(False,), (True,)]) def test_get_user_ip_and_agents(self, after_persisting: bool): """Test `get_user_ip_and_agents` for persisted and unpersisted data""" self.reactor.advance(12345678) |