aboutsummaryrefslogtreecommitdiff
path: root/tests/test_pandora/test_models.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_pandora/test_models.py')
-rw-r--r--tests/test_pandora/test_models.py78
1 files changed, 41 insertions, 37 deletions
diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py
index 8e0e0b5..8cfbd9d 100644
--- a/tests/test_pandora/test_models.py
+++ b/tests/test_pandora/test_models.py
@@ -5,8 +5,12 @@ from unittest.mock import Mock, patch
5from pandora.client import APIClient 5from pandora.client import APIClient
6from pandora.errors import ParameterMissing 6from pandora.errors import ParameterMissing
7 7
8import pandora.models.ad as am
8import pandora.models._base as m 9import pandora.models._base as m
9import pandora.models.pandora as pm 10import pandora.models.search as sm
11import pandora.models.station as stm
12import pandora.models.bookmark as bm
13import pandora.models.playlist as plm
10 14
11 15
12class TestField(TestCase): 16class TestField(TestCase):
@@ -59,7 +63,7 @@ class TestAdditionalUrlField(TestCase):
59 '_paramAdditionalUrls': ['foo'] 63 '_paramAdditionalUrls': ['foo']
60 } 64 }
61 65
62 field = pm.AdditionalUrlField("additionalAudioUrl") 66 field = plm.AdditionalUrlField("additionalAudioUrl")
63 67
64 ret = field.formatter(None, dummy_data, 'test') 68 ret = field.formatter(None, dummy_data, 'test')
65 69
@@ -73,7 +77,7 @@ class TestAdditionalUrlField(TestCase):
73 ] 77 ]
74 } 78 }
75 79
76 field = pm.AdditionalUrlField("additionalAudioUrl") 80 field = plm.AdditionalUrlField("additionalAudioUrl")
77 81
78 ret = field.formatter(None, dummy_data, ['foo', 'bar']) 82 ret = field.formatter(None, dummy_data, ['foo', 'bar'])
79 83
@@ -274,7 +278,7 @@ class TestPlaylistItemModel(TestCase):
274 WEIRD_FORMAT = {"audioUrlMap": {"highQuality": {}}} 278 WEIRD_FORMAT = {"audioUrlMap": {"highQuality": {}}}
275 279
276 def test_audio_url_without_map(self): 280 def test_audio_url_without_map(self):
277 item = pm.PlaylistItem.from_json(Mock(), self.AUDIO_URL_NO_MAP) 281 item = plm.PlaylistItem.from_json(Mock(), self.AUDIO_URL_NO_MAP)
278 self.assertEqual(item.bitrate, 64) 282 self.assertEqual(item.bitrate, 64)
279 self.assertEqual(item.encoding, "aacplus") 283 self.assertEqual(item.encoding, "aacplus")
280 self.assertEqual(item.audio_url, "foo") 284 self.assertEqual(item.audio_url, "foo")
@@ -284,7 +288,7 @@ class TestPlaylistItemModel(TestCase):
284 # valid url... but I didn't add the original code so just going to test it 288 # valid url... but I didn't add the original code so just going to test it
285 # and leave it alone for now ~mcrute 289 # and leave it alone for now ~mcrute
286 def test_empty_quality_map_url_is_map(self): 290 def test_empty_quality_map_url_is_map(self):
287 item = pm.PlaylistItem.from_json(Mock(), self.WEIRD_FORMAT) 291 item = plm.PlaylistItem.from_json(Mock(), self.WEIRD_FORMAT)
288 self.assertIsNone(item.bitrate) 292 self.assertIsNone(item.bitrate)
289 self.assertIsNone(item.encoding) 293 self.assertIsNone(item.encoding)
290 self.assertIsNone(item.audio_url) 294 self.assertIsNone(item.audio_url)
@@ -293,13 +297,13 @@ class TestPlaylistItemModel(TestCase):
293class TestPlaylistModel(TestCase): 297class TestPlaylistModel(TestCase):
294 298
295 def test_unplayable_get_is_playable(self): 299 def test_unplayable_get_is_playable(self):
296 playlist = pm.PlaylistModel(Mock()) 300 playlist = plm.PlaylistModel(Mock())
297 playlist.audio_url = "" 301 playlist.audio_url = ""
298 self.assertFalse(playlist.get_is_playable()) 302 self.assertFalse(playlist.get_is_playable())
299 303
300 def test_playable_get_is_playable(self): 304 def test_playable_get_is_playable(self):
301 client = Mock() 305 client = Mock()
302 playlist = pm.PlaylistModel(client) 306 playlist = plm.PlaylistModel(client)
303 playlist.audio_url = "foo" 307 playlist.audio_url = "foo"
304 playlist.get_is_playable() 308 playlist.get_is_playable()
305 client.transport.test_url.assert_called_with("foo") 309 client.transport.test_url.assert_called_with("foo")
@@ -339,7 +343,7 @@ class TestAdItem(TestCase):
339 def setUp(self): 343 def setUp(self):
340 api_client_mock = Mock(spec=APIClient) 344 api_client_mock = Mock(spec=APIClient)
341 api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY 345 api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY
342 self.result = pm.AdItem.from_json(api_client_mock, self.JSON_DATA) 346 self.result = am.AdItem.from_json(api_client_mock, self.JSON_DATA)
343 self.result.station_id = 'station_id_mock' 347 self.result.station_id = 'station_id_mock'
344 self.result.ad_token = 'token_mock' 348 self.result.ad_token = 'token_mock'
345 349
@@ -355,14 +359,14 @@ class TestAdItem(TestCase):
355 def test_register_ad_raises_if_no_tracking_tokens_available(self): 359 def test_register_ad_raises_if_no_tracking_tokens_available(self):
356 with self.assertRaises(ParameterMissing): 360 with self.assertRaises(ParameterMissing):
357 self.result.tracking_tokens = [] 361 self.result.tracking_tokens = []
358 self.result._api_client.register_ad = Mock(spec=pm.AdItem) 362 self.result._api_client.register_ad = Mock(spec=am.AdItem)
359 363
360 self.result.register_ad('id_mock') 364 self.result.register_ad('id_mock')
361 365
362 assert self.result._api_client.register_ad.called 366 assert self.result._api_client.register_ad.called
363 367
364 def test_prepare_playback(self): 368 def test_prepare_playback(self):
365 with patch.object(pm.PlaylistModel, 'prepare_playback') as super_mock: 369 with patch.object(plm.PlaylistModel, 'prepare_playback') as super_mock:
366 370
367 self.result.register_ad = Mock() 371 self.result.register_ad = Mock()
368 self.result.prepare_playback() 372 self.result.prepare_playback()
@@ -370,7 +374,7 @@ class TestAdItem(TestCase):
370 assert super_mock.called 374 assert super_mock.called
371 375
372 def test_prepare_playback_raises_paramater_missing(self): 376 def test_prepare_playback_raises_paramater_missing(self):
373 with patch.object(pm.PlaylistModel, 'prepare_playback') as super_mock: 377 with patch.object(plm.PlaylistModel, 'prepare_playback') as super_mock:
374 378
375 self.result.register_ad = Mock(side_effect=ParameterMissing( 379 self.result.register_ad = Mock(side_effect=ParameterMissing(
376 'No ad tracking tokens provided for registration.') 380 'No ad tracking tokens provided for registration.')
@@ -380,7 +384,7 @@ class TestAdItem(TestCase):
380 assert not super_mock.called 384 assert not super_mock.called
381 385
382 def test_prepare_playback_handles_paramater_missing_if_no_tokens(self): 386 def test_prepare_playback_handles_paramater_missing_if_no_tokens(self):
383 with patch.object(pm.PlaylistModel, 'prepare_playback') as super_mock: 387 with patch.object(plm.PlaylistModel, 'prepare_playback') as super_mock:
384 388
385 self.result.tracking_tokens = [] 389 self.result.tracking_tokens = []
386 self.result.register_ad = Mock(side_effect=ParameterMissing( 390 self.result.register_ad = Mock(side_effect=ParameterMissing(
@@ -431,7 +435,7 @@ class TestSearchResultItem(TestCase):
431 APIClient.HIGH_AUDIO_QUALITY 435 APIClient.HIGH_AUDIO_QUALITY
432 436
433 def test_is_song(self): 437 def test_is_song(self):
434 result = pm.SearchResultItem.from_json( 438 result = sm.SearchResultItem.from_json(
435 self.api_client_mock, self.SONG_JSON_DATA) 439 self.api_client_mock, self.SONG_JSON_DATA)
436 assert result.is_song 440 assert result.is_song
437 assert not result.is_artist 441 assert not result.is_artist
@@ -439,7 +443,7 @@ class TestSearchResultItem(TestCase):
439 assert not result.is_genre_station 443 assert not result.is_genre_station
440 444
441 def test_is_artist(self): 445 def test_is_artist(self):
442 result = pm.SearchResultItem.from_json( 446 result = sm.SearchResultItem.from_json(
443 self.api_client_mock, self.ARTIST_JSON_DATA) 447 self.api_client_mock, self.ARTIST_JSON_DATA)
444 assert not result.is_song 448 assert not result.is_song
445 assert result.is_artist 449 assert result.is_artist
@@ -447,7 +451,7 @@ class TestSearchResultItem(TestCase):
447 assert not result.is_genre_station 451 assert not result.is_genre_station
448 452
449 def test_is_composer(self): 453 def test_is_composer(self):
450 result = pm.SearchResultItem.from_json( 454 result = sm.SearchResultItem.from_json(
451 self.api_client_mock, self.COMPOSER_JSON_DATA) 455 self.api_client_mock, self.COMPOSER_JSON_DATA)
452 assert not result.is_song 456 assert not result.is_song
453 assert not result.is_artist 457 assert not result.is_artist
@@ -455,7 +459,7 @@ class TestSearchResultItem(TestCase):
455 assert not result.is_genre_station 459 assert not result.is_genre_station
456 460
457 def test_is_genre_station(self): 461 def test_is_genre_station(self):
458 result = pm.SearchResultItem.from_json( 462 result = sm.SearchResultItem.from_json(
459 self.api_client_mock, self.GENRE_JSON_DATA) 463 self.api_client_mock, self.GENRE_JSON_DATA)
460 assert not result.is_song 464 assert not result.is_song
461 assert not result.is_artist 465 assert not result.is_artist
@@ -464,7 +468,7 @@ class TestSearchResultItem(TestCase):
464 468
465 def test_fails_if_unknown(self): 469 def test_fails_if_unknown(self):
466 with self.assertRaises(NotImplementedError): 470 with self.assertRaises(NotImplementedError):
467 pm.SearchResultItem.from_json( 471 sm.SearchResultItem.from_json(
468 self.api_client_mock, self.UNKNOWN_JSON_DATA) 472 self.api_client_mock, self.UNKNOWN_JSON_DATA)
469 473
470 474
@@ -490,14 +494,14 @@ class TestArtistSearchResultItem(TestCase):
490 APIClient.HIGH_AUDIO_QUALITY 494 APIClient.HIGH_AUDIO_QUALITY
491 495
492 def test_repr(self): 496 def test_repr(self):
493 result = pm.SearchResultItem.from_json( 497 result = sm.SearchResultItem.from_json(
494 self.api_client_mock, self.ARTIST_JSON_DATA) 498 self.api_client_mock, self.ARTIST_JSON_DATA)
495 expected = ( 499 expected = (
496 "ArtistSearchResultItem(artist='artist_name_mock', " 500 "ArtistSearchResultItem(artist='artist_name_mock', "
497 "likely_match=False, score=100, token='R0000000')") 501 "likely_match=False, score=100, token='R0000000')")
498 self.assertEqual(expected, repr(result)) 502 self.assertEqual(expected, repr(result))
499 503
500 result = pm.SearchResultItem.from_json( 504 result = sm.SearchResultItem.from_json(
501 self.api_client_mock, self.COMPOSER_JSON_DATA) 505 self.api_client_mock, self.COMPOSER_JSON_DATA)
502 expected = ( 506 expected = (
503 "ArtistSearchResultItem(artist='composer_name_mock', " 507 "ArtistSearchResultItem(artist='composer_name_mock', "
@@ -505,7 +509,7 @@ class TestArtistSearchResultItem(TestCase):
505 self.assertEqual(expected, repr(result)) 509 self.assertEqual(expected, repr(result))
506 510
507 def test_create_station(self): 511 def test_create_station(self):
508 result = pm.SearchResultItem.from_json( 512 result = sm.SearchResultItem.from_json(
509 self.api_client_mock, self.ARTIST_JSON_DATA) 513 self.api_client_mock, self.ARTIST_JSON_DATA)
510 result._api_client.create_station = Mock() 514 result._api_client.create_station = Mock()
511 515
@@ -529,7 +533,7 @@ class TestSongSearchResultItem(TestCase):
529 APIClient.HIGH_AUDIO_QUALITY 533 APIClient.HIGH_AUDIO_QUALITY
530 534
531 def test_repr(self): 535 def test_repr(self):
532 result = pm.SearchResultItem.from_json( 536 result = sm.SearchResultItem.from_json(
533 self.api_client_mock, self.SONG_JSON_DATA) 537 self.api_client_mock, self.SONG_JSON_DATA)
534 expected = ( 538 expected = (
535 "SongSearchResultItem(artist='artist_name_mock', score=100, " 539 "SongSearchResultItem(artist='artist_name_mock', score=100, "
@@ -537,7 +541,7 @@ class TestSongSearchResultItem(TestCase):
537 self.assertEqual(expected, repr(result)) 541 self.assertEqual(expected, repr(result))
538 542
539 def test_create_station(self): 543 def test_create_station(self):
540 result = pm.SearchResultItem.from_json( 544 result = sm.SearchResultItem.from_json(
541 self.api_client_mock, self.SONG_JSON_DATA) 545 self.api_client_mock, self.SONG_JSON_DATA)
542 result._api_client.create_station = Mock() 546 result._api_client.create_station = Mock()
543 547
@@ -560,7 +564,7 @@ class TestGenreStationSearchResultItem(TestCase):
560 APIClient.HIGH_AUDIO_QUALITY 564 APIClient.HIGH_AUDIO_QUALITY
561 565
562 def test_repr(self): 566 def test_repr(self):
563 result = pm.SearchResultItem.from_json( 567 result = sm.SearchResultItem.from_json(
564 self.api_client_mock, self.GENRE_JSON_DATA) 568 self.api_client_mock, self.GENRE_JSON_DATA)
565 expected = ( 569 expected = (
566 "GenreStationSearchResultItem(score=100, " 570 "GenreStationSearchResultItem(score=100, "
@@ -568,7 +572,7 @@ class TestGenreStationSearchResultItem(TestCase):
568 self.assertEqual(expected, repr(result)) 572 self.assertEqual(expected, repr(result))
569 573
570 def test_create_station(self): 574 def test_create_station(self):
571 result = pm.SearchResultItem.from_json( 575 result = sm.SearchResultItem.from_json(
572 self.api_client_mock, self.GENRE_JSON_DATA) 576 self.api_client_mock, self.GENRE_JSON_DATA)
573 result._api_client.create_station = Mock() 577 result._api_client.create_station = Mock()
574 578
@@ -604,7 +608,7 @@ class TestSearchResult(TestCase):
604 def setUp(self): 608 def setUp(self):
605 api_client_mock = Mock(spec=APIClient) 609 api_client_mock = Mock(spec=APIClient)
606 api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY 610 api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY
607 self.result = pm.SearchResult.from_json( 611 self.result = sm.SearchResult.from_json(
608 api_client_mock, self.JSON_DATA) 612 api_client_mock, self.JSON_DATA)
609 613
610 def test_repr(self): 614 def test_repr(self):
@@ -634,7 +638,7 @@ class TestGenreStationList(TestCase):
634 api_client = Mock() 638 api_client = Mock()
635 api_client.get_station_list_checksum.return_value = "foo" 639 api_client.get_station_list_checksum.return_value = "foo"
636 640
637 stations = pm.GenreStationList.from_json(api_client, self.TEST_DATA) 641 stations = stm.GenreStationList.from_json(api_client, self.TEST_DATA)
638 self.assertTrue(stations.has_changed()) 642 self.assertTrue(stations.has_changed())
639 643
640 644
@@ -649,7 +653,7 @@ class TestStationList(TestCase):
649 api_client = Mock() 653 api_client = Mock()
650 api_client.get_station_list_checksum.return_value = "foo" 654 api_client.get_station_list_checksum.return_value = "foo"
651 655
652 stations = pm.StationList.from_json(api_client, self.TEST_DATA) 656 stations = stm.StationList.from_json(api_client, self.TEST_DATA)
653 self.assertTrue(stations.has_changed()) 657 self.assertTrue(stations.has_changed())
654 658
655 659
@@ -662,31 +666,31 @@ class TestBookmark(TestCase):
662 self.client = Mock() 666 self.client = Mock()
663 667
664 def test_is_song_bookmark(self): 668 def test_is_song_bookmark(self):
665 s = pm.Bookmark.from_json(self.client, self.SONG_BOOKMARK) 669 s = bm.Bookmark.from_json(self.client, self.SONG_BOOKMARK)
666 a = pm.Bookmark.from_json(self.client, self.ARTIST_BOOKMARK) 670 a = bm.Bookmark.from_json(self.client, self.ARTIST_BOOKMARK)
667 671
668 self.assertTrue(s.is_song_bookmark) 672 self.assertTrue(s.is_song_bookmark)
669 self.assertFalse(a.is_song_bookmark) 673 self.assertFalse(a.is_song_bookmark)
670 674
671 def test_delete_song_bookmark(self): 675 def test_delete_song_bookmark(self):
672 pm.Bookmark.from_json(self.client, self.SONG_BOOKMARK).delete() 676 bm.Bookmark.from_json(self.client, self.SONG_BOOKMARK).delete()
673 self.client.delete_song_bookmark.assert_called_with("token") 677 self.client.delete_song_bookmark.assert_called_with("token")
674 678
675 def test_delete_artist_bookmark(self): 679 def test_delete_artist_bookmark(self):
676 pm.Bookmark.from_json(self.client, self.ARTIST_BOOKMARK).delete() 680 bm.Bookmark.from_json(self.client, self.ARTIST_BOOKMARK).delete()
677 self.client.delete_artist_bookmark.assert_called_with("token") 681 self.client.delete_artist_bookmark.assert_called_with("token")
678 682
679 683
680class TestPandoraType(TestCase): 684class TestPandoraType(TestCase):
681 685
682 def test_it_can_be_built_from_a_model(self): 686 def test_it_can_be_built_from_a_model(self):
683 pt = pm.PandoraType.from_model(None, "TR") 687 pt = plm.PandoraType.from_model(None, "TR")
684 self.assertIs(pm.PandoraType.TRACK, pt) 688 self.assertIs(plm.PandoraType.TRACK, pt)
685 689
686 def test_it_can_be_built_from_string(self): 690 def test_it_can_be_built_from_string(self):
687 pt = pm.PandoraType.from_string("TR") 691 pt = plm.PandoraType.from_string("TR")
688 self.assertIs(pm.PandoraType.TRACK, pt) 692 self.assertIs(plm.PandoraType.TRACK, pt)
689 693
690 def test_it_returns_genre_for_unknown_string(self): 694 def test_it_returns_genre_for_unknown_string(self):
691 pt = pm.PandoraType.from_string("FOO") 695 pt = plm.PandoraType.from_string("FOO")
692 self.assertIs(pm.PandoraType.GENRE, pt) 696 self.assertIs(plm.PandoraType.GENRE, pt)