aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjcass <john.cass77@gmail.com>2015-12-28 16:23:57 +0200
committerjcass <john.cass77@gmail.com>2015-12-28 16:23:57 +0200
commitd2a520dbf6257986128d14a6c7d23aa37725d5e3 (patch)
tree847cf884fe129f8ff4d6cfef243b7b55cd3fa720 /tests
parenteb91a5c00701689085b6f427d62e487f417c6f51 (diff)
downloadpydora-d2a520dbf6257986128d14a6c7d23aa37725d5e3.tar.bz2
pydora-d2a520dbf6257986128d14a6c7d23aa37725d5e3.tar.xz
pydora-d2a520dbf6257986128d14a6c7d23aa37725d5e3.zip
Handle IOErrors and ValueErrors when attempting to register ads.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_pandora/test_models.py23
-rw-r--r--tests/test_pandora/test_transport.py2
-rw-r--r--tests/test_pydora/test_utils.py14
3 files changed, 24 insertions, 15 deletions
diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py
index ecd8cf1..06c988c 100644
--- a/tests/test_pandora/test_models.py
+++ b/tests/test_pandora/test_models.py
@@ -205,19 +205,19 @@ class TestAdItem(TestCase):
205 JSON_DATA = { 205 JSON_DATA = {
206 'audioUrlMap': { 206 'audioUrlMap': {
207 'mediumQuality': { 207 'mediumQuality': {
208 'audioUrl': 'mock_med_url', 'bitrate': '64', 'protocol': 'http', 'encoding': 'aacplus' 208 'audioUrl': 'med_url_mock', 'bitrate': '64', 'protocol': 'http', 'encoding': 'aacplus'
209 }, 209 },
210 'highQuality': { 210 'highQuality': {
211 'audioUrl': 'mock_high_url', 'bitrate': '64', 'protocol': 'http', 'encoding': 'aacplus' 211 'audioUrl': 'high_url_mock', 'bitrate': '64', 'protocol': 'http', 'encoding': 'aacplus'
212 }, 212 },
213 'lowQuality': { 213 'lowQuality': {
214 'audioUrl': 'mock_low_url', 'bitrate': '32', 'protocol': 'http', 'encoding': 'aacplus'}}, 214 'audioUrl': 'low_url_mock', 'bitrate': '32', 'protocol': 'http', 'encoding': 'aacplus'}},
215 'clickThroughUrl': 'mock_click_url', 215 'clickThroughUrl': 'click_url_mock',
216 'imageUrl': 'mock_img_url', 216 'imageUrl': 'img_url_mock',
217 'companyName': '', 217 'companyName': '',
218 'title': '', 218 'title': '',
219 'trackGain': '0.0', 219 'trackGain': '0.0',
220 'adTrackingTokens': ['mock_token_1', 'mock_token_2'] 220 'adTrackingTokens': ['token_1_mock', 'token_2_mock']
221 } 221 }
222 222
223 def setUp(self): 223 def setUp(self):
@@ -230,10 +230,19 @@ class TestAdItem(TestCase):
230 230
231 def test_register_ad(self): 231 def test_register_ad(self):
232 self.result._api_client.register_ad = Mock() 232 self.result._api_client.register_ad = Mock()
233 self.result.register_ad('id_dummy') 233 self.result.register_ad('id_mock')
234 234
235 assert self.result._api_client.register_ad.called 235 assert self.result._api_client.register_ad.called
236 236
237 def test_register_ad_raises_exception_if_no_tracking_tokens_available(self):
238 with self.assertRaises(ValueError):
239 self.result.tracking_tokens = []
240 self.result._api_client.register_ad = Mock(spec=AdItem)
241
242 self.result.register_ad('id_mock')
243
244 assert self.result._api_client.register_ad.called
245
237 def test_prepare_playback(self): 246 def test_prepare_playback(self):
238 with patch.object(PlaylistModel, 'prepare_playback') as super_mock: 247 with patch.object(PlaylistModel, 'prepare_playback') as super_mock:
239 248
diff --git a/tests/test_pandora/test_transport.py b/tests/test_pandora/test_transport.py
index 59d4cea..bdd549c 100644
--- a/tests/test_pandora/test_transport.py
+++ b/tests/test_pandora/test_transport.py
@@ -6,7 +6,7 @@ from pandora.py2compat import Mock, call
6from tests.test_pandora.test_clientbuilder import TestSettingsDictBuilder 6from tests.test_pandora.test_clientbuilder import TestSettingsDictBuilder
7 7
8 8
9class SysCallError(Exception): 9class SysCallError(IOError):
10 pass 10 pass
11 11
12 12
diff --git a/tests/test_pydora/test_utils.py b/tests/test_pydora/test_utils.py
index 64cdf74..e5a81b5 100644
--- a/tests/test_pydora/test_utils.py
+++ b/tests/test_pydora/test_utils.py
@@ -18,22 +18,22 @@ class TestIterateForever(TestCase):
18 with patch.object(APIClient, 'get_playlist') as get_playlist_mock: 18 with patch.object(APIClient, 'get_playlist') as get_playlist_mock:
19 with patch.object(APIClient, 'register_ad', side_effect=ParameterMissing("ParameterMissing")): 19 with patch.object(APIClient, 'register_ad', side_effect=ParameterMissing("ParameterMissing")):
20 20
21 station = Station.from_json(self.client, {'stationToken': 'dummy_token'}) 21 station = Station.from_json(self.client, {'stationToken': 'mock_token'})
22 dummy_ad = AdItem.from_json(self.client, {'station_id': 'dummy_id'}) 22 ad_mock = AdItem.from_json(self.client, {'station_id': 'mock_id'})
23 get_playlist_mock.return_value=iter([dummy_ad]) 23 get_playlist_mock.return_value=iter([ad_mock])
24 24
25 station_iter = iterate_forever(station.get_playlist) 25 station_iter = iterate_forever(station.get_playlist)
26 26
27 next_track = station_iter.next() 27 next_track = station_iter.next()
28 self.assertEqual(dummy_ad, next_track) 28 self.assertEqual(ad_mock, next_track)
29 29
30 def test_reraise_missing_params_exception(self): 30 def test_reraise_missing_params_exception(self):
31 with patch.object(APIClient, 'get_playlist', side_effect=ParameterMissing("ParameterMissing")) as get_playlist_mock: 31 with patch.object(APIClient, 'get_playlist', side_effect=ParameterMissing("ParameterMissing")) as get_playlist_mock:
32 with self.assertRaises(ParameterMissing): 32 with self.assertRaises(ParameterMissing):
33 33
34 station = Station.from_json(self.client, {'stationToken': 'dummy_token'}) 34 station = Station.from_json(self.client, {'stationToken': 'mock_token'})
35 dummy_track = PlaylistItem.from_json(self.client, {'token': 'dummy_token'}) 35 mock_track = PlaylistItem.from_json(self.client, {'token': 'mock_token'})
36 get_playlist_mock.return_value=iter([dummy_track]) 36 get_playlist_mock.return_value=iter([mock_track])
37 37
38 station_iter = iterate_forever(station.get_playlist) 38 station_iter = iterate_forever(station.get_playlist)
39 station_iter.next() 39 station_iter.next()