1
0

test_client_ips.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 OpenMarket Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from twisted.internet import defer
  16. import tests.unittest
  17. import tests.utils
  18. class ClientIpStoreTestCase(tests.unittest.TestCase):
  19. def __init__(self, *args, **kwargs):
  20. super(ClientIpStoreTestCase, self).__init__(*args, **kwargs)
  21. self.store = None # type: synapse.storage.DataStore
  22. self.clock = None # type: tests.utils.MockClock
  23. @defer.inlineCallbacks
  24. def setUp(self):
  25. hs = yield tests.utils.setup_test_homeserver()
  26. self.store = hs.get_datastore()
  27. self.clock = hs.get_clock()
  28. @defer.inlineCallbacks
  29. def test_insert_new_client_ip(self):
  30. self.clock.now = 12345678
  31. user_id = "@user:id"
  32. yield self.store.insert_client_ip(
  33. user_id,
  34. "access_token", "ip", "user_agent", "device_id",
  35. )
  36. result = yield self.store.get_last_client_ip_by_device(user_id, "device_id")
  37. r = result[(user_id, "device_id")]
  38. self.assertDictContainsSubset(
  39. {
  40. "user_id": user_id,
  41. "device_id": "device_id",
  42. "access_token": "access_token",
  43. "ip": "ip",
  44. "user_agent": "user_agent",
  45. "last_seen": 12345678000,
  46. },
  47. r
  48. )