aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2017-10-07 23:26:51 +0000
committerMike Crute <mike@crute.us>2017-10-07 23:26:51 +0000
commit91f2b2d5a2d053aa3c0f0691418d2949b1aba983 (patch)
treed11f73833089246124b84ab14da841f15c9a8215
parent0e9e780dafe201e60c76e1b29264afd67349c2d1 (diff)
downloadpydora-91f2b2d5a2d053aa3c0f0691418d2949b1aba983.tar.bz2
pydora-91f2b2d5a2d053aa3c0f0691418d2949b1aba983.tar.xz
pydora-91f2b2d5a2d053aa3c0f0691418d2949b1aba983.zip
Run flake8 on tests
-rw-r--r--tests/__init__.py1
-rw-r--r--tests/test_pandora/test_client.py34
-rw-r--r--tests/test_pandora/test_clientbuilder.py14
-rw-r--r--tests/test_pandora/test_models.py126
-rw-r--r--tests/test_pandora/test_transport.py12
-rw-r--r--tests/test_pandora/test_util.py (renamed from tests/test_pandora/test_utils.py)0
-rw-r--r--tests/test_pydora/test_utils.py28
7 files changed, 128 insertions, 87 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
index e080ee5..80793cf 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,5 +1,6 @@
1import os 1import os
2from unittest import TestLoader 2from unittest import TestLoader
3 3
4
4def discover_suite(): 5def discover_suite():
5 return TestLoader().discover(os.path.dirname(__file__)) 6 return TestLoader().discover(os.path.dirname(__file__))
diff --git a/tests/test_pandora/test_client.py b/tests/test_pandora/test_client.py
index 8d93e4c..f88b755 100644
--- a/tests/test_pandora/test_client.py
+++ b/tests/test_pandora/test_client.py
@@ -65,13 +65,12 @@ class TestCallingAPIClient(TestCase):
65 transport.assert_has_calls([call("method"), call("method")]) 65 transport.assert_has_calls([call("method"), call("method")])
66 66
67 def test_playlist_fetches_ads(self): 67 def test_playlist_fetches_ads(self):
68 fake_playlist = { "items": [ 68 fake_playlist = {"items": [
69 { "songName": "test" }, 69 {"songName": "test"},
70 { "adToken": "foo" }, 70 {"adToken": "foo"},
71 { "songName": "test" }, 71 {"songName": "test"},
72 ]} 72 ]}
73 with patch.object( 73 with patch.object(APIClient, '__call__', return_value=fake_playlist):
74 APIClient, '__call__', return_value=fake_playlist) as mock:
75 client = APIClient(Mock(), None, None, None, None) 74 client = APIClient(Mock(), None, None, None, None)
76 client._authenticate = Mock() 75 client._authenticate = Mock()
77 76
@@ -88,10 +87,10 @@ class TestCallingAPIClient(TestCase):
88 client.get_playlist('token_mock') 87 client.get_playlist('token_mock')
89 88
90 playlist_mock.assert_has_calls([call("station.getPlaylist", 89 playlist_mock.assert_has_calls([call("station.getPlaylist",
91 audioAdPodCapable=True, 90 audioAdPodCapable=True,
92 includeTrackLength=True, 91 includeTrackLength=True,
93 stationToken='token_mock', 92 stationToken='token_mock',
94 xplatformAdCapable=True)]) 93 xplatformAdCapable=True)])
95 94
96 95
97class TestGettingQualities(TestCase): 96class TestGettingQualities(TestCase):
@@ -118,8 +117,10 @@ class TestGettingQualities(TestCase):
118class TestGettingAds(TestCase): 117class TestGettingAds(TestCase):
119 118
120 def test_get_ad_item_(self): 119 def test_get_ad_item_(self):
121 with patch.object(APIClient, '__call__', 120 metamock = patch.object(
122 return_value=TestAdItem.JSON_DATA) as ad_metadata_mock: 121 APIClient, '__call__', return_value=TestAdItem.JSON_DATA)
122
123 with metamock as ad_metadata_mock:
123 transport = Mock(side_effect=[errors.InvalidAuthToken(), None]) 124 transport = Mock(side_effect=[errors.InvalidAuthToken(), None])
124 125
125 client = APIClient(transport, None, None, None, None) 126 client = APIClient(transport, None, None, None, None)
@@ -129,10 +130,9 @@ class TestGettingAds(TestCase):
129 assert ad_item.station_id == 'id_mock' 130 assert ad_item.station_id == 'id_mock'
130 assert ad_item.ad_token == 'token_mock' 131 assert ad_item.ad_token == 'token_mock'
131 132
132 ad_metadata_mock.assert_has_calls([call("ad.getAdMetadata", 133 ad_metadata_mock.assert_has_calls([
133 adToken='token_mock', 134 call("ad.getAdMetadata", adToken='token_mock',
134 returnAdTrackingTokens=True, 135 returnAdTrackingTokens=True, supportAudioAds=True)])
135 supportAudioAds=True)])
136 136
137 def test_get_ad_item_with_no_station_id_specified_raises_exception(self): 137 def test_get_ad_item_with_no_station_id_specified_raises_exception(self):
138 transport = Mock(side_effect=[errors.InvalidAuthToken(), None]) 138 transport = Mock(side_effect=[errors.InvalidAuthToken(), None])
@@ -175,7 +175,7 @@ class TestCreatingGenreStation(TestCase):
175 def test_has_initial_checksum(self): 175 def test_has_initial_checksum(self):
176 fake_data = { 176 fake_data = {
177 "categories": [ 177 "categories": [
178 { "categoryName": "foo", "stations": [] }, 178 {"categoryName": "foo", "stations": []},
179 ], 179 ],
180 180
181 # Not actually part of the genre station response but is needed to 181 # Not actually part of the genre station response but is needed to
diff --git a/tests/test_pandora/test_clientbuilder.py b/tests/test_pandora/test_clientbuilder.py
index b02a4d1..0105c09 100644
--- a/tests/test_pandora/test_clientbuilder.py
+++ b/tests/test_pandora/test_clientbuilder.py
@@ -11,8 +11,8 @@ class TestTranslatingDict(TestCase):
11 11
12 class TestDict(cb.TranslatingDict): 12 class TestDict(cb.TranslatingDict):
13 13
14 KEY_TRANSLATIONS = { "FOO": "BAR" } 14 KEY_TRANSLATIONS = {"FOO": "BAR"}
15 VALUE_TRANSLATIONS = { "BAZ": lambda v: v + 1 } 15 VALUE_TRANSLATIONS = {"BAZ": lambda v: v + 1}
16 callback_value = None 16 callback_value = None
17 17
18 def was_translated(self, from_key, to_key): 18 def was_translated(self, from_key, to_key):
@@ -22,7 +22,7 @@ class TestTranslatingDict(TestCase):
22 self.dct = self.TestDict() 22 self.dct = self.TestDict()
23 23
24 def test_construction_with_dict(self): 24 def test_construction_with_dict(self):
25 dct = self.TestDict({ "BIZ": 1, "BUZ": 2 }) 25 dct = self.TestDict({"BIZ": 1, "BUZ": 2})
26 26
27 self.assertEqual(1, dct["BIZ"]) 27 self.assertEqual(1, dct["BIZ"])
28 self.assertEqual(2, dct["BUZ"]) 28 self.assertEqual(2, dct["BUZ"])
@@ -42,7 +42,7 @@ class TestTranslatingDict(TestCase):
42 self.assertEqual(True, self.dct["BAR"]) 42 self.assertEqual(True, self.dct["BAR"])
43 43
44 def test_value_translation(self): 44 def test_value_translation(self):
45 dct = self.TestDict({ " Baz": 41 }) 45 dct = self.TestDict({" Baz": 41})
46 46
47 self.assertEqual(42, dct["BAZ"]) 47 self.assertEqual(42, dct["BAZ"])
48 48
@@ -96,8 +96,8 @@ class TestSettingsDictBuilder(TestCase):
96 96
97 self.assertEqual({}, client.transport._http.proxies) 97 self.assertEqual({}, client.transport._http.proxies)
98 self.assertEqual(DEFAULT_API_HOST, client.transport.api_host) 98 self.assertEqual(DEFAULT_API_HOST, client.transport.api_host)
99 self.assertEqual(APIClient.MED_AUDIO_QUALITY, 99 self.assertEqual(
100 client.default_audio_quality) 100 APIClient.MED_AUDIO_QUALITY, client.default_audio_quality)
101 101
102 def test_validate_client(self): 102 def test_validate_client(self):
103 client = TestSettingsDictBuilder._build_maximal() 103 client = TestSettingsDictBuilder._build_maximal()
@@ -125,7 +125,7 @@ class TestFileBasedBuilder(TestCase):
125 DEFAULT_CONFIG_FILE = "foo" 125 DEFAULT_CONFIG_FILE = "foo"
126 126
127 def parse_config(self): 127 def parse_config(self):
128 return { "USER": { "USERNAME": "U", "PASSWORD": "P" }} 128 return {"USER": {"USERNAME": "U", "PASSWORD": "P"}}
129 129
130 def build_from_settings_dict(self, config): 130 def build_from_settings_dict(self, config):
131 mock = Mock() 131 mock = Mock()
diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py
index 42f1fbd..914f09e 100644
--- a/tests/test_pandora/test_models.py
+++ b/tests/test_pandora/test_models.py
@@ -37,7 +37,7 @@ class TestModelMetaClass(TestCase):
37 37
38class TestPandoraModel(TestCase): 38class TestPandoraModel(TestCase):
39 39
40 JSON_DATA = { "field2": ["test2"], "field3": 41 } 40 JSON_DATA = {"field2": ["test2"], "field3": 41}
41 41
42 class TestModel(m.PandoraModel): 42 class TestModel(m.PandoraModel):
43 43
@@ -57,7 +57,7 @@ class TestPandoraModel(TestCase):
57 57
58 def test_json_to_date(self): 58 def test_json_to_date(self):
59 expected = datetime(2015, 7, 18, 3, 8, 17) 59 expected = datetime(2015, 7, 18, 3, 8, 17)
60 result = m.PandoraModel.json_to_date(None, { "time": 1437188897616 }) 60 result = m.PandoraModel.json_to_date(None, {"time": 1437188897616})
61 # Python2.7 doesn't restore microseconds and we don't care about 61 # Python2.7 doesn't restore microseconds and we don't care about
62 # it anyhow so just remove it for this test 62 # it anyhow so just remove it for this test
63 self.assertEqual(expected, result.replace(microsecond=0)) 63 self.assertEqual(expected, result.replace(microsecond=0))
@@ -113,8 +113,8 @@ class TestPandoraListModel(TestCase):
113 JSON_DATA = { 113 JSON_DATA = {
114 "field1": 42, 114 "field1": 42,
115 "field2": [ 115 "field2": [
116 { "idx": "foo", "fieldS1": "Foo" }, 116 {"idx": "foo", "fieldS1": "Foo"},
117 { "idx": "bar", "fieldS1": "Bar" }, 117 {"idx": "bar", "fieldS1": "Bar"},
118 ] 118 ]
119 } 119 }
120 120
@@ -166,11 +166,12 @@ class TestPandoraDictListModel(TestCase):
166 JSON_DATA = { 166 JSON_DATA = {
167 "field1": 42, 167 "field1": 42,
168 "fieldD1": [ 168 "fieldD1": [
169 { "dictKey": "Foobear", 169 {
170 "listKey": [ 170 "dictKey": "Foobear",
171 { "idx": "foo", "fieldS1": "Foo" }, 171 "listKey": [
172 { "idx": "bar", "fieldS1": "Bar" }, 172 {"idx": "foo", "fieldS1": "Foo"},
173 ] 173 {"idx": "bar", "fieldS1": "Bar"},
174 ]
174 } 175 }
175 ] 176 ]
176 } 177 }
@@ -205,11 +206,8 @@ class TestPandoraDictListModel(TestCase):
205 206
206class TestPlaylistItemModel(TestCase): 207class TestPlaylistItemModel(TestCase):
207 208
208 AUDIO_URL_NO_MAP = { "audioUrl": "foo" } 209 AUDIO_URL_NO_MAP = {"audioUrl": "foo"}
209 WEIRD_FORMAT = { "audioUrlMap": { 210 WEIRD_FORMAT = {"audioUrlMap": {"highQuality": {}}}
210 "highQuality": {
211 }
212 }}
213 211
214 def test_audio_url_without_map(self): 212 def test_audio_url_without_map(self):
215 item = pm.PlaylistItem.from_json(Mock(), self.AUDIO_URL_NO_MAP) 213 item = pm.PlaylistItem.from_json(Mock(), self.AUDIO_URL_NO_MAP)
@@ -248,19 +246,30 @@ class TestAdItem(TestCase):
248 JSON_DATA = { 246 JSON_DATA = {
249 'audioUrlMap': { 247 'audioUrlMap': {
250 'mediumQuality': { 248 'mediumQuality': {
251 'audioUrl': 'med_url_mock', 'bitrate': '64', 'protocol': 'http', 'encoding': 'aacplus' 249 'audioUrl': 'med_url_mock',
250 'bitrate': '64',
251 'protocol': 'http',
252 'encoding': 'aacplus'
252 }, 253 },
253 'highQuality': { 254 'highQuality': {
254 'audioUrl': 'high_url_mock', 'bitrate': '64', 'protocol': 'http', 'encoding': 'aacplus' 255 'audioUrl': 'high_url_mock',
256 'bitrate': '64',
257 'protocol': 'http',
258 'encoding': 'aacplus'
255 }, 259 },
256 'lowQuality': { 260 'lowQuality': {
257 'audioUrl': 'low_url_mock', 'bitrate': '32', 'protocol': 'http', 'encoding': 'aacplus'}}, 261 'audioUrl': 'low_url_mock',
258 'clickThroughUrl': 'click_url_mock', 262 'bitrate': '32',
259 'imageUrl': 'img_url_mock', 263 'protocol': 'http',
260 'companyName': '', 264 'encoding': 'aacplus'
261 'title': '', 265 }
262 'trackGain': '0.0', 266 },
263 'adTrackingTokens': ['token_1_mock', 'token_2_mock'] 267 'clickThroughUrl': 'click_url_mock',
268 'imageUrl': 'img_url_mock',
269 'companyName': '',
270 'title': '',
271 'trackGain': '0.0',
272 'adTrackingTokens': ['token_1_mock', 'token_2_mock']
264 } 273 }
265 274
266 def setUp(self): 275 def setUp(self):
@@ -279,7 +288,7 @@ class TestAdItem(TestCase):
279 288
280 assert self.result._api_client.register_ad.called 289 assert self.result._api_client.register_ad.called
281 290
282 def test_register_ad_raises_exception_if_no_tracking_tokens_available(self): 291 def test_register_ad_raises_if_no_tracking_tokens_available(self):
283 with self.assertRaises(ParameterMissing): 292 with self.assertRaises(ParameterMissing):
284 self.result.tracking_tokens = [] 293 self.result.tracking_tokens = []
285 self.result._api_client.register_ad = Mock(spec=pm.AdItem) 294 self.result._api_client.register_ad = Mock(spec=pm.AdItem)
@@ -299,8 +308,8 @@ class TestAdItem(TestCase):
299 def test_prepare_playback_raises_paramater_missing(self): 308 def test_prepare_playback_raises_paramater_missing(self):
300 with patch.object(pm.PlaylistModel, 'prepare_playback') as super_mock: 309 with patch.object(pm.PlaylistModel, 'prepare_playback') as super_mock:
301 310
302 self.result.register_ad = Mock(side_effect=ParameterMissing('No ad tracking tokens provided for ' 311 self.result.register_ad = Mock(side_effect=ParameterMissing(
303 'registration.') 312 'No ad tracking tokens provided for registration.')
304 ) 313 )
305 self.assertRaises(ParameterMissing, self.result.prepare_playback) 314 self.assertRaises(ParameterMissing, self.result.prepare_playback)
306 assert self.result.register_ad.called 315 assert self.result.register_ad.called
@@ -310,8 +319,8 @@ class TestAdItem(TestCase):
310 with patch.object(pm.PlaylistModel, 'prepare_playback') as super_mock: 319 with patch.object(pm.PlaylistModel, 'prepare_playback') as super_mock:
311 320
312 self.result.tracking_tokens = [] 321 self.result.tracking_tokens = []
313 self.result.register_ad = Mock(side_effect=ParameterMissing('No ad tracking tokens provided for ' 322 self.result.register_ad = Mock(side_effect=ParameterMissing(
314 'registration.')) 323 'No ad tracking tokens provided for registration.'))
315 self.result.prepare_playback() 324 self.result.prepare_playback()
316 assert self.result.register_ad.called 325 assert self.result.register_ad.called
317 assert super_mock.called 326 assert super_mock.called
@@ -354,7 +363,8 @@ class TestSearchResultItem(TestCase):
354 363
355 def setUp(self): 364 def setUp(self):
356 self.api_client_mock = Mock(spec=APIClient) 365 self.api_client_mock = Mock(spec=APIClient)
357 self.api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY 366 self.api_client_mock.default_audio_quality = \
367 APIClient.HIGH_AUDIO_QUALITY
358 368
359 def test_is_song(self): 369 def test_is_song(self):
360 result = pm.SearchResultItem.from_json( 370 result = pm.SearchResultItem.from_json(
@@ -412,17 +422,22 @@ class TestArtistSearchResultItem(TestCase):
412 422
413 def setUp(self): 423 def setUp(self):
414 self.api_client_mock = Mock(spec=APIClient) 424 self.api_client_mock = Mock(spec=APIClient)
415 self.api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY 425 self.api_client_mock.default_audio_quality = \
426 APIClient.HIGH_AUDIO_QUALITY
416 427
417 def test_repr(self): 428 def test_repr(self):
418 result = pm.SearchResultItem.from_json( 429 result = pm.SearchResultItem.from_json(
419 self.api_client_mock, self.ARTIST_JSON_DATA) 430 self.api_client_mock, self.ARTIST_JSON_DATA)
420 expected = ("ArtistSearchResultItem(artist='artist_name_mock', likely_match=False, score=100, token='R0000000')") 431 expected = (
432 "ArtistSearchResultItem(artist='artist_name_mock', "
433 "likely_match=False, score=100, token='R0000000')")
421 self.assertEqual(expected, repr(result)) 434 self.assertEqual(expected, repr(result))
422 435
423 result = pm.SearchResultItem.from_json( 436 result = pm.SearchResultItem.from_json(
424 self.api_client_mock, self.COMPOSER_JSON_DATA) 437 self.api_client_mock, self.COMPOSER_JSON_DATA)
425 expected = ("ArtistSearchResultItem(artist='composer_name_mock', likely_match=False, score=100, token='C0000000')") 438 expected = (
439 "ArtistSearchResultItem(artist='composer_name_mock', "
440 "likely_match=False, score=100, token='C0000000')")
426 self.assertEqual(expected, repr(result)) 441 self.assertEqual(expected, repr(result))
427 442
428 def test_create_station(self): 443 def test_create_station(self):
@@ -431,7 +446,8 @@ class TestArtistSearchResultItem(TestCase):
431 result._api_client.create_station = Mock() 446 result._api_client.create_station = Mock()
432 447
433 result.create_station() 448 result.create_station()
434 result._api_client.create_station.assert_called_with(artist_token=result.token) 449 result._api_client.create_station.assert_called_with(
450 artist_token=result.token)
435 451
436 452
437class TestSongSearchResultItem(TestCase): 453class TestSongSearchResultItem(TestCase):
@@ -445,12 +461,15 @@ class TestSongSearchResultItem(TestCase):
445 461
446 def setUp(self): 462 def setUp(self):
447 self.api_client_mock = Mock(spec=APIClient) 463 self.api_client_mock = Mock(spec=APIClient)
448 self.api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY 464 self.api_client_mock.default_audio_quality = \
465 APIClient.HIGH_AUDIO_QUALITY
449 466
450 def test_repr(self): 467 def test_repr(self):
451 result = pm.SearchResultItem.from_json( 468 result = pm.SearchResultItem.from_json(
452 self.api_client_mock, self.SONG_JSON_DATA) 469 self.api_client_mock, self.SONG_JSON_DATA)
453 expected = ("SongSearchResultItem(artist='artist_name_mock', score=100, song_name='song_name_mock', token='S0000000')") 470 expected = (
471 "SongSearchResultItem(artist='artist_name_mock', score=100, "
472 "song_name='song_name_mock', token='S0000000')")
454 self.assertEqual(expected, repr(result)) 473 self.assertEqual(expected, repr(result))
455 474
456 def test_create_station(self): 475 def test_create_station(self):
@@ -459,7 +478,8 @@ class TestSongSearchResultItem(TestCase):
459 result._api_client.create_station = Mock() 478 result._api_client.create_station = Mock()
460 479
461 result.create_station() 480 result.create_station()
462 result._api_client.create_station.assert_called_with(track_token=result.token) 481 result._api_client.create_station.assert_called_with(
482 track_token=result.token)
463 483
464 484
465class TestGenreStationSearchResultItem(TestCase): 485class TestGenreStationSearchResultItem(TestCase):
@@ -472,12 +492,15 @@ class TestGenreStationSearchResultItem(TestCase):
472 492
473 def setUp(self): 493 def setUp(self):
474 self.api_client_mock = Mock(spec=APIClient) 494 self.api_client_mock = Mock(spec=APIClient)
475 self.api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY 495 self.api_client_mock.default_audio_quality = \
496 APIClient.HIGH_AUDIO_QUALITY
476 497
477 def test_repr(self): 498 def test_repr(self):
478 result = pm.SearchResultItem.from_json( 499 result = pm.SearchResultItem.from_json(
479 self.api_client_mock, self.GENRE_JSON_DATA) 500 self.api_client_mock, self.GENRE_JSON_DATA)
480 expected = ("GenreStationSearchResultItem(score=100, station_name='station_name_mock', token='G0000000')") 501 expected = (
502 "GenreStationSearchResultItem(score=100, "
503 "station_name='station_name_mock', token='G0000000')")
481 self.assertEqual(expected, repr(result)) 504 self.assertEqual(expected, repr(result))
482 505
483 def test_create_station(self): 506 def test_create_station(self):
@@ -486,7 +509,8 @@ class TestGenreStationSearchResultItem(TestCase):
486 result._api_client.create_station = Mock() 509 result._api_client.create_station = Mock()
487 510
488 result.create_station() 511 result.create_station()
489 result._api_client.create_station.assert_called_with(search_token=result.token) 512 result._api_client.create_station.assert_called_with(
513 search_token=result.token)
490 514
491 515
492class TestSearchResult(TestCase): 516class TestSearchResult(TestCase):
@@ -516,14 +540,20 @@ class TestSearchResult(TestCase):
516 def setUp(self): 540 def setUp(self):
517 api_client_mock = Mock(spec=APIClient) 541 api_client_mock = Mock(spec=APIClient)
518 api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY 542 api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY
519 self.result = pm.SearchResult.from_json(api_client_mock, self.JSON_DATA) 543 self.result = pm.SearchResult.from_json(
544 api_client_mock, self.JSON_DATA)
520 545
521 def test_repr(self): 546 def test_repr(self):
522 expected = ("SearchResult(artists=[ArtistSearchResultItem(artist='artist_mock', likely_match=False, score=80, " 547 expected = (
523 "token='R000000')], explanation='', genre_stations=[GenreStationSearchResultItem(score=50, " 548 "SearchResult(artists=[ArtistSearchResultItem("
524 "station_name='station_mock', token='G0000')], nearest_matches_available=True, " 549 "artist='artist_mock', likely_match=False, score=80, "
525 "songs=[SongSearchResultItem(artist='song_artist_mock', score=100, song_name='song_name_mock', " 550 "token='R000000')], explanation='', genre_stations=["
526 "token='S0000000')])") 551 "GenreStationSearchResultItem(score=50, "
552 "station_name='station_mock', token='G0000')], "
553 "nearest_matches_available=True, "
554 "songs=[SongSearchResultItem(artist='song_artist_mock', "
555 "score=100, song_name='song_name_mock', "
556 "token='S0000000')])")
527 self.assertEqual(expected, repr(self.result)) 557 self.assertEqual(expected, repr(self.result))
528 558
529 559
@@ -532,7 +562,7 @@ class TestGenreStationList(TestCase):
532 TEST_DATA = { 562 TEST_DATA = {
533 "checksum": "bar", 563 "checksum": "bar",
534 "categories": [ 564 "categories": [
535 { "categoryName": "foo", "stations": [] }, 565 {"categoryName": "foo", "stations": []},
536 ] 566 ]
537 } 567 }
538 568
@@ -561,8 +591,8 @@ class TestStationList(TestCase):
561 591
562class TestBookmark(TestCase): 592class TestBookmark(TestCase):
563 593
564 SONG_BOOKMARK = { "songName": "foo", "bookmarkToken": "token" } 594 SONG_BOOKMARK = {"songName": "foo", "bookmarkToken": "token"}
565 ARTIST_BOOKMARK = { "artistName": "foo", "bookmarkToken": "token" } 595 ARTIST_BOOKMARK = {"artistName": "foo", "bookmarkToken": "token"}
566 596
567 def setUp(self): 597 def setUp(self):
568 self.client = Mock() 598 self.client = Mock()
diff --git a/tests/test_pandora/test_transport.py b/tests/test_pandora/test_transport.py
index 08e3292..ff9c572 100644
--- a/tests/test_pandora/test_transport.py
+++ b/tests/test_pandora/test_transport.py
@@ -164,7 +164,7 @@ class TestParseResponse(TestCase):
164 164
165 def test_with_valid_response(self): 165 def test_with_valid_response(self):
166 res = self.transport._parse_response(self.VALID_MSG_JSON) 166 res = self.transport._parse_response(self.VALID_MSG_JSON)
167 self.assertEqual({ "foo": "bar" }, res) 167 self.assertEqual({"foo": "bar"}, res)
168 168
169 def test_with_valid_response_no_body(self): 169 def test_with_valid_response_no_body(self):
170 res = self.transport._parse_response(self.VALID_MSG_NO_BODY_JSON) 170 res = self.transport._parse_response(self.VALID_MSG_NO_BODY_JSON)
@@ -208,9 +208,9 @@ class TestTransportRequestPrep(TestCase):
208 208
209 self.transport._http = http 209 self.transport._http = http
210 res = self.transport._make_http_request( 210 res = self.transport._make_http_request(
211 "/url", b"data", { "a":None, "b":"c" }) 211 "/url", b"data", {"a": None, "b": "c"})
212 212
213 http.post.assert_called_with("/url", data=b"data", params={"b":"c"}) 213 http.post.assert_called_with("/url", data=b"data", params={"b": "c"})
214 retval.raise_for_status.assert_called_with() 214 retval.raise_for_status.assert_called_with()
215 215
216 self.assertEqual("foo", res) 216 self.assertEqual("foo", res)
@@ -223,7 +223,7 @@ class TestTransportRequestPrep(TestCase):
223 self.transport.start_time = 23 223 self.transport.start_time = 23
224 224
225 with patch.object(time, "time", return_value=20): 225 with patch.object(time, "time", return_value=20):
226 val = self.transport._build_data("foo", {"a":"b", "c":None}) 226 val = self.transport._build_data("foo", {"a": "b", "c": None})
227 227
228 val = json.loads(val) 228 val = json.loads(val)
229 self.assertEqual("b", val["a"]) 229 self.assertEqual("b", val["a"])
@@ -238,7 +238,7 @@ class TestTransportRequestPrep(TestCase):
238 238
239 with patch.object(time, "time", return_value=20): 239 with patch.object(time, "time", return_value=20):
240 val = self.transport._build_data( 240 val = self.transport._build_data(
241 t.APITransport.NO_ENCRYPT[0], {"a":"b", "c":None}) 241 t.APITransport.NO_ENCRYPT[0], {"a": "b", "c": None})
242 242
243 val = json.loads(val) 243 val = json.loads(val)
244 self.assertEqual("b", val["a"]) 244 self.assertEqual("b", val["a"])
@@ -324,7 +324,7 @@ class TestEncryptor(TestCase):
324 324
325 def test_decrypt(self): 325 def test_decrypt(self):
326 self.assertEqual( 326 self.assertEqual(
327 { "foo": "bar" }, self.cryptor.decrypt(self.ENCODED_JSON)) 327 {"foo": "bar"}, self.cryptor.decrypt(self.ENCODED_JSON))
328 328
329 def test_encrypt(self): 329 def test_encrypt(self):
330 self.assertEqual( 330 self.assertEqual(
diff --git a/tests/test_pandora/test_utils.py b/tests/test_pandora/test_util.py
index 2b4ca83..2b4ca83 100644
--- a/tests/test_pandora/test_utils.py
+++ b/tests/test_pandora/test_util.py
diff --git a/tests/test_pydora/test_utils.py b/tests/test_pydora/test_utils.py
index 5334ff6..9900913 100644
--- a/tests/test_pydora/test_utils.py
+++ b/tests/test_pydora/test_utils.py
@@ -16,11 +16,16 @@ class TestIterateForever(TestCase):
16 16
17 def test_handle_missing_params_exception_due_to_missing_ad_tokens(self): 17 def test_handle_missing_params_exception_due_to_missing_ad_tokens(self):
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 admock = patch.object(
20 APIClient, 'register_ad',
21 side_effect=ParameterMissing("ParameterMissing"))
20 22
21 station = Station.from_json(self.client, {'stationToken': 'token_mock'}) 23 with admock:
22 ad_mock = AdItem.from_json(self.client, {'station_id': 'id_mock'}) 24 station = Station.from_json(
23 get_playlist_mock.return_value=iter([ad_mock]) 25 self.client, {'stationToken': 'token_mock'})
26 ad_mock = AdItem.from_json(
27 self.client, {'station_id': 'id_mock'})
28 get_playlist_mock.return_value = iter([ad_mock])
24 29
25 station_iter = iterate_forever(station.get_playlist) 30 station_iter = iterate_forever(station.get_playlist)
26 31
@@ -28,12 +33,17 @@ class TestIterateForever(TestCase):
28 self.assertEqual(ad_mock, next_track) 33 self.assertEqual(ad_mock, next_track)
29 34
30 def test_reraise_missing_params_exception(self): 35 def test_reraise_missing_params_exception(self):
31 with patch.object(APIClient, 'get_playlist', side_effect=ParameterMissing("ParameterMissing")) as get_playlist_mock: 36 plmock = patch.object(
32 with self.assertRaises(ParameterMissing): 37 APIClient, 'get_playlist',
38 side_effect=ParameterMissing("ParameterMissing"))
33 39
34 station = Station.from_json(self.client, {'stationToken': 'token_mock'}) 40 with plmock as get_playlist_mock:
35 track_mock = PlaylistItem.from_json(self.client, {'token': 'token_mock'}) 41 with self.assertRaises(ParameterMissing):
36 get_playlist_mock.return_value=iter([track_mock]) 42 station = Station.from_json(
43 self.client, {'stationToken': 'token_mock'})
44 track_mock = PlaylistItem.from_json(
45 self.client, {'token': 'token_mock'})
46 get_playlist_mock.return_value = iter([track_mock])
37 47
38 station_iter = iterate_forever(station.get_playlist) 48 station_iter = iterate_forever(station.get_playlist)
39 next(station_iter) 49 next(station_iter)