diff options
Diffstat (limited to 'tests/test_pandora/test_models.py')
-rw-r--r-- | tests/test_pandora/test_models.py | 126 |
1 files changed, 78 insertions, 48 deletions
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 | ||
38 | class TestPandoraModel(TestCase): | 38 | class 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 | ||
206 | class TestPlaylistItemModel(TestCase): | 207 | class 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 | ||
437 | class TestSongSearchResultItem(TestCase): | 453 | class 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 | ||
465 | class TestGenreStationSearchResultItem(TestCase): | 485 | class 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 | ||
492 | class TestSearchResult(TestCase): | 516 | class 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 | ||
562 | class TestBookmark(TestCase): | 592 | class 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() |