summary refs log tree commit diff
path: root/tests/handlers
diff options
context:
space:
mode:
authorDavid Baker <dbkr@users.noreply.github.com>2016-07-21 13:41:42 +0100
committerGitHub <noreply@github.com>2016-07-21 13:41:42 +0100
commit2c28e25bdae253aa31ec61ac7672f15e2b053963 (patch)
treea23e906f2d2400496b835f4b687e5649aec9c29d /tests/handlers
parentMerge pull request #942 from matrix-org/rav/fix_register_deviceid (diff)
parentFix PEP8 errors (diff)
downloadsynapse-2c28e25bdae253aa31ec61ac7672f15e2b053963.tar.xz
Merge pull request #943 from matrix-org/rav/get_device_api
Implement GET /device/{deviceId}
Diffstat (limited to 'tests/handlers')
-rw-r--r--tests/handlers/test_device.py38
1 files changed, 28 insertions, 10 deletions
diff --git a/tests/handlers/test_device.py b/tests/handlers/test_device.py
index b05aa9bb55..87c3c75aea 100644
--- a/tests/handlers/test_device.py
+++ b/tests/handlers/test_device.py
@@ -19,6 +19,9 @@ 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 +81,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 +108,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(