Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #944 from matrix-org/rav/devices_returns_list
Browse files Browse the repository at this point in the history
make /devices return a list
  • Loading branch information
dbkr authored Jul 21, 2016
2 parents 2c28e25 + 55abbe1 commit 68a92af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 5 additions & 5 deletions synapse/handlers/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ def get_devices_by_user(self, user_id):
Args:
user_id (str):
Returns:
defer.Deferred: dict[str, dict[str, X]]: map from device_id to
info on the device
defer.Deferred: list[dict[str, X]]: info on each 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(
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)

defer.returnValue(devices)
Expand Down
11 changes: 7 additions & 4 deletions tests/handlers/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,31 @@ def test_get_devices_by_user(self):
yield self._record_users()

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({
"user_id": user1,
"device_id": "xyz",
"display_name": "display 0",
"last_seen_ip": None,
"last_seen_ts": None,
}, res["xyz"])
}, device_map["xyz"])
self.assertDictContainsSubset({
"user_id": user1,
"device_id": "fco",
"display_name": "display 1",
"last_seen_ip": "ip1",
"last_seen_ts": 1000000,
}, res["fco"])
}, device_map["fco"])
self.assertDictContainsSubset({
"user_id": user1,
"device_id": "abc",
"display_name": "display 2",
"last_seen_ip": "ip3",
"last_seen_ts": 3000000,
}, res["abc"])
}, device_map["abc"])

@defer.inlineCallbacks
def test_get_device(self):
Expand Down

0 comments on commit 68a92af

Please sign in to comment.