mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-09-09 13:52:00 +00:00
make /devices return a list
Turns out I specced this to return a list of devices rather than a dict of them
This commit is contained in:
parent
2c28e25bda
commit
55abbe1850
@ -79,17 +79,17 @@ class DeviceHandler(BaseHandler):
|
|||||||
Args:
|
Args:
|
||||||
user_id (str):
|
user_id (str):
|
||||||
Returns:
|
Returns:
|
||||||
defer.Deferred: dict[str, dict[str, X]]: map from device_id to
|
defer.Deferred: list[dict[str, X]]: info on each device
|
||||||
info on the device
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
devices = yield self.store.get_devices_by_user(user_id)
|
device_map = yield self.store.get_devices_by_user(user_id)
|
||||||
|
|
||||||
ips = yield self.store.get_last_client_ip_by_device(
|
ips = yield self.store.get_last_client_ip_by_device(
|
||||||
devices=((user_id, device_id) for device_id in devices.keys())
|
devices=((user_id, device_id) for device_id in device_map.keys())
|
||||||
)
|
)
|
||||||
|
|
||||||
for device in devices.values():
|
devices = device_map.values()
|
||||||
|
for device in devices:
|
||||||
_update_device_from_client_ips(device, ips)
|
_update_device_from_client_ips(device, ips)
|
||||||
|
|
||||||
defer.returnValue(devices)
|
defer.returnValue(devices)
|
||||||
|
@ -84,28 +84,31 @@ class DeviceTestCase(unittest.TestCase):
|
|||||||
yield self._record_users()
|
yield self._record_users()
|
||||||
|
|
||||||
res = yield self.handler.get_devices_by_user(user1)
|
res = yield self.handler.get_devices_by_user(user1)
|
||||||
self.assertEqual(3, len(res.keys()))
|
self.assertEqual(3, len(res))
|
||||||
|
device_map = {
|
||||||
|
d["device_id"]: d for d in res
|
||||||
|
}
|
||||||
self.assertDictContainsSubset({
|
self.assertDictContainsSubset({
|
||||||
"user_id": user1,
|
"user_id": user1,
|
||||||
"device_id": "xyz",
|
"device_id": "xyz",
|
||||||
"display_name": "display 0",
|
"display_name": "display 0",
|
||||||
"last_seen_ip": None,
|
"last_seen_ip": None,
|
||||||
"last_seen_ts": None,
|
"last_seen_ts": None,
|
||||||
}, res["xyz"])
|
}, device_map["xyz"])
|
||||||
self.assertDictContainsSubset({
|
self.assertDictContainsSubset({
|
||||||
"user_id": user1,
|
"user_id": user1,
|
||||||
"device_id": "fco",
|
"device_id": "fco",
|
||||||
"display_name": "display 1",
|
"display_name": "display 1",
|
||||||
"last_seen_ip": "ip1",
|
"last_seen_ip": "ip1",
|
||||||
"last_seen_ts": 1000000,
|
"last_seen_ts": 1000000,
|
||||||
}, res["fco"])
|
}, device_map["fco"])
|
||||||
self.assertDictContainsSubset({
|
self.assertDictContainsSubset({
|
||||||
"user_id": user1,
|
"user_id": user1,
|
||||||
"device_id": "abc",
|
"device_id": "abc",
|
||||||
"display_name": "display 2",
|
"display_name": "display 2",
|
||||||
"last_seen_ip": "ip3",
|
"last_seen_ip": "ip3",
|
||||||
"last_seen_ts": 3000000,
|
"last_seen_ts": 3000000,
|
||||||
}, res["abc"])
|
}, device_map["abc"])
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_get_device(self):
|
def test_get_device(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user