Skip to content

Commit

Permalink
Implement get_devices + add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thp committed Dec 29, 2009
1 parent 37a4294 commit 2202b7d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 12 additions & 1 deletion mygpoclient/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def __init__(self, device_id, caption, type, subscriptions):
self.type = type
self.subscriptions = int(subscriptions)

@classmethod
def from_dictionary(cls, d):
return cls(d['id'], d['caption'], d['type'], d['subscriptions'])

class EpisodeAction(object):
"""This class encapsulates an episode action
Expand Down Expand Up @@ -208,7 +212,14 @@ def get_devices(self):
list to the user or to determine device IDs to pull
the subscription list from.
"""
return []
uri = self._locator.device_list_uri()
dicts = self._client.GET(uri)
if dicts is None:
raise InvalidResponse('No response received')

try:
return [PodcastDevice.from_dictionary(d) for d in dicts]
except KeyError:
raise InvalidResponse('Missing keys in device list response')


19 changes: 18 additions & 1 deletion mygpoclient/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@ def test_updateDeviceSettings_returnsTrue(self):
self.assertEquals(result, True)
self.assert_http_request_count(1)

def test_getDevices_raisesInvalidResponse_onEmptyResponse(self):
self.set_http_response_value('')
self.assertRaises(api.InvalidResponse, self.client.get_devices)

def test_getDevices_raisesInvalidResponse_onMissingKeys(self):
self.set_http_response_value("""
[
{"id": "gpodder.on.my.phone",
"type": "mobile",
"subscriptions": 42},
{"id": "95dce59cf340123fa",
"caption": "The Lappy",
"subscriptions": 4711}
]
""")
self.assertRaises(api.InvalidResponse, self.client.get_devices)

def test_getDevices_returnsDeviceList(self):
self.set_http_response_value("""
[
Expand All @@ -252,7 +269,7 @@ def test_getDevices_returnsDeviceList(self):
{"id": "95dce59cf340123fa",
"caption": "The Lappy",
"type": "laptop",
"subscriptions": 4711},
"subscriptions": 4711}
]
""")
devices = self.client.get_devices()
Expand Down

0 comments on commit 2202b7d

Please sign in to comment.