summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2016-07-20 17:58:44 +0100
committerRichard van der Hoff <richard@matrix.org>2016-07-21 12:00:29 +0100
commit406f7aa0f6ca7433e52433485824e80b79930498 (patch)
treeaee4eb5c403d7f22b077e43c7c5cb5bc86453937 /tests
parentMerge branch 'rav/get_devices_api' into develop (diff)
downloadsynapse-406f7aa0f6ca7433e52433485824e80b79930498.tar.xz
Implement GET /device/{deviceId}
Diffstat (limited to 'tests')
-rw-r--r--tests/handlers/test_device.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/tests/handlers/test_device.py b/tests/handlers/test_device.py
index b05aa9bb55..73f09874d8 100644
--- a/tests/handlers/test_device.py
+++ b/tests/handlers/test_device.py
@@ -19,6 +19,8 @@ import synapse.handlers.device
 import synapse.storage
 from tests import unittest, utils
 
+user1 = "@boris:aaa"
+user2 = "@theresa:bbb"
 
 class DeviceTestCase(unittest.TestCase):
     def __init__(self, *args, **kwargs):
@@ -78,16 +80,7 @@ class DeviceTestCase(unittest.TestCase):
 
     @defer.inlineCallbacks
     def test_get_devices_by_user(self):
-        # check this works for both devices which have a recorded client_ip,
-        # and those which don't.
-        user1 = "@boris:aaa"
-        user2 = "@theresa:bbb"
-        yield self._record_user(user1, "xyz", "display 0")
-        yield self._record_user(user1, "fco", "display 1", "token1", "ip1")
-        yield self._record_user(user1, "abc", "display 2", "token2", "ip2")
-        yield self._record_user(user1, "abc", "display 2", "token3", "ip3")
-
-        yield self._record_user(user2, "def", "dispkay", "token4", "ip4")
+        yield self._record_users()
 
         res = yield self.handler.get_devices_by_user(user1)
         self.assertEqual(3, len(res.keys()))
@@ -114,6 +107,30 @@ class DeviceTestCase(unittest.TestCase):
         }, res["abc"])
 
     @defer.inlineCallbacks
+    def test_get_device(self):
+        yield self._record_users()
+
+        res = yield self.handler.get_device(user1, "abc")
+        self.assertDictContainsSubset({
+            "user_id": user1,
+            "device_id": "abc",
+            "display_name": "display 2",
+            "last_seen_ip": "ip3",
+            "last_seen_ts": 3000000,
+        }, res)
+
+    @defer.inlineCallbacks
+    def _record_users(self):
+        # check this works for both devices which have a recorded client_ip,
+        # and those which don't.
+        yield self._record_user(user1, "xyz", "display 0")
+        yield self._record_user(user1, "fco", "display 1", "token1", "ip1")
+        yield self._record_user(user1, "abc", "display 2", "token2", "ip2")
+        yield self._record_user(user1, "abc", "display 2", "token3", "ip3")
+
+        yield self._record_user(user2, "def", "dispkay", "token4", "ip4")
+
+    @defer.inlineCallbacks
     def _record_user(self, user_id, device_id, display_name,
                      access_token=None, ip=None):
         device_id = yield self.handler.check_device_registered(