aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2019-04-07 19:07:31 +0000
committerMike Crute <mike@crute.us>2019-04-07 19:07:31 +0000
commitf394e36d82a85aff881812163ade0ec87888c86b (patch)
tree7257972752510871bb1245dd951dfbee950fe65f /tests
parent88204c0999c49b79c6cf63a15f29dee5eadc31d6 (diff)
downloadpydora-f394e36d82a85aff881812163ade0ec87888c86b.tar.bz2
pydora-f394e36d82a85aff881812163ade0ec87888c86b.tar.xz
pydora-f394e36d82a85aff881812163ade0ec87888c86b.zip
Remove 'no cover' pragmas
Diffstat (limited to 'tests')
-rw-r--r--tests/test_pandora/test_client.py134
-rw-r--r--tests/test_pandora/test_models.py93
2 files changed, 219 insertions, 8 deletions
diff --git a/tests/test_pandora/test_client.py b/tests/test_pandora/test_client.py
index 9945bff..69eac65 100644
--- a/tests/test_pandora/test_client.py
+++ b/tests/test_pandora/test_client.py
@@ -3,6 +3,10 @@ from unittest.mock import Mock, call, patch
3 3
4from pandora import errors 4from pandora import errors
5from pandora.models.ad import AdItem 5from pandora.models.ad import AdItem
6from pandora.models.station import Station
7from pandora.models.station import StationList
8from pandora.models.search import SearchResult
9from pandora.models.bookmark import BookmarkList
6from pandora.models.playlist import AdditionalAudioUrl 10from pandora.models.playlist import AdditionalAudioUrl
7from pandora.client import APIClient, BaseAPIClient 11from pandora.client import APIClient, BaseAPIClient
8from tests.test_pandora.test_models import TestAdItem 12from tests.test_pandora.test_models import TestAdItem
@@ -253,3 +257,133 @@ class TestAdditionalUrls(TestCase):
253 includeTrackLength=True, 257 includeTrackLength=True,
254 stationToken='token_mock', 258 stationToken='token_mock',
255 xplatformAdCapable=True)]) 259 xplatformAdCapable=True)])
260
261
262# On the surface this test class seems dumb because it's mostly just exercising
263# pass-throughs to the transport but it exists to ensure no subtle errors get
264# introduced to API client methods that will only be spotted at runtime (import
265# errors, etc...)
266class TestAPIClientExhaustive(TestCase):
267
268 def setUp(self):
269 self.transport = Mock()
270 self.api = APIClient(self.transport, "puser", "ppass", "device")
271
272 def test_register_ad(self):
273 self.api.register_ad("sid", "tokens")
274 self.transport.assert_called_with(
275 "ad.registerAd", stationId="sid", adTrackingTokens="tokens")
276
277 def test_share_music(self):
278 self.api.share_music("token", "foo@example.com")
279 self.transport.assert_called_with(
280 "music.shareMusic", musicToken="token", email="foo@example.com")
281
282 def test_transform_shared_station(self):
283 self.api.transform_shared_station("token")
284 self.transport.assert_called_with(
285 "station.transformSharedStation", stationToken="token")
286
287 def test_share_station(self):
288 self.api.share_station("sid", "token", "foo@example.com")
289 self.transport.assert_called_with(
290 "station.shareStation", stationId="sid", stationToken="token",
291 emails=("foo@example.com",))
292
293 def test_sleep_song(self):
294 self.api.sleep_song("token")
295 self.transport.assert_called_with("user.sleepSong", trackToken="token")
296
297 def test_set_quick_mix(self):
298 self.api.set_quick_mix("id")
299 self.transport.assert_called_with(
300 "user.setQuickMix", quickMixStationIds=("id",))
301
302 def test_explain_track(self):
303 self.api.explain_track("token")
304 self.transport.assert_called_with(
305 "track.explainTrack", trackToken="token")
306
307 def test_rename_station(self):
308 self.api.rename_station("token", "name")
309 self.transport.assert_called_with(
310 "station.renameStation", stationToken="token", stationName="name")
311
312 def test_delete_station(self):
313 self.api.delete_station("token")
314 self.transport.assert_called_with(
315 "station.deleteStation", stationToken="token")
316
317 def test_delete_music(self):
318 self.api.delete_music("seed")
319 self.transport.assert_called_with("station.deleteMusic", seedId="seed")
320
321 def test_delete_feedback(self):
322 self.api.delete_feedback("id")
323 self.transport.assert_called_with(
324 "station.deleteFeedback", feedbackId="id")
325
326 def test_add_music(self):
327 self.api.add_music("mt", "st")
328 self.transport.assert_called_with(
329 "station.addMusic", musicToken="mt", stationToken="st")
330
331 def test_add_feedback(self):
332 self.api.add_feedback("token", False)
333 self.transport.assert_called_with(
334 "station.addFeedback", trackToken="token", isPositive=False)
335
336 def test_add_artist_bookmark(self):
337 self.api.add_artist_bookmark("tt")
338 self.transport.assert_called_with(
339 "bookmark.addArtistBookmark", trackToken="tt")
340
341 def test_add_song_bookmark(self):
342 self.api.add_song_bookmark("tt")
343 self.transport.assert_called_with(
344 "bookmark.addSongBookmark", trackToken="tt")
345
346 def test_delete_song_bookmark(self):
347 self.api.delete_song_bookmark("bt")
348 self.transport.assert_called_with(
349 "bookmark.deleteSongBookmark", bookmarkToken="bt")
350
351 def test_delete_artist_bookmark(self):
352 self.api.delete_artist_bookmark("bt")
353 self.transport.assert_called_with(
354 "bookmark.deleteArtistBookmark", bookmarkToken="bt")
355
356 def test_get_station_list_checksum(self):
357 self.transport.return_value = {"checksum": "foo"}
358 self.assertEqual("foo", self.api.get_station_list_checksum())
359 self.transport.assert_called_with("user.getStationListChecksum")
360
361 # The following methods use the bare minimum JSON required to construct the
362 # models for more detailed model tests look at test_models instead
363
364 def test_get_station_list(self):
365 self.transport.return_value = {"stations": []}
366 self.assertIsInstance(self.api.get_station_list(), StationList)
367 self.transport.assert_called_with(
368 "user.getStationList", includeStationArtUrl=True)
369
370 def test_get_bookmarks(self):
371 self.transport.return_value = {}
372 self.assertIsInstance(self.api.get_bookmarks(), BookmarkList)
373 self.transport.assert_called_with("user.getBookmarks")
374
375 def test_get_station(self):
376 self.transport.return_value = {}
377 self.assertIsInstance(self.api.get_station("st"), Station)
378 self.transport.assert_called_with(
379 "station.getStation", stationToken="st",
380 includeExtendedAttributes=True)
381
382 def test_search(self):
383 self.transport.return_value = {}
384 self.assertIsInstance(self.api.search(
385 "text", include_near_matches=True, include_genre_stations=True),
386 SearchResult)
387 self.transport.assert_called_with(
388 "music.search", searchText="text", includeNearMatches=True,
389 includeGenreStations=True)
diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py
index 0d37ca0..cb650df 100644
--- a/tests/test_pandora/test_models.py
+++ b/tests/test_pandora/test_models.py
@@ -277,6 +277,11 @@ class TestPlaylistItemModel(TestCase):
277 AUDIO_URL_NO_MAP = {"audioUrl": "foo"} 277 AUDIO_URL_NO_MAP = {"audioUrl": "foo"}
278 WEIRD_FORMAT = {"audioUrlMap": {"highQuality": {}}} 278 WEIRD_FORMAT = {"audioUrlMap": {"highQuality": {}}}
279 279
280 def setUp(self):
281 self.client = Mock()
282 self.playlist = plm.PlaylistItem(self.client)
283 self.playlist.track_token = "token"
284
280 def test_audio_url_without_map(self): 285 def test_audio_url_without_map(self):
281 item = plm.PlaylistItem.from_json(Mock(), self.AUDIO_URL_NO_MAP) 286 item = plm.PlaylistItem.from_json(Mock(), self.AUDIO_URL_NO_MAP)
282 self.assertEqual(item.bitrate, 64) 287 self.assertEqual(item.bitrate, 64)
@@ -293,20 +298,57 @@ class TestPlaylistItemModel(TestCase):
293 self.assertIsNone(item.encoding) 298 self.assertIsNone(item.encoding)
294 self.assertIsNone(item.audio_url) 299 self.assertIsNone(item.audio_url)
295 300
301 def test_thumbs_up(self):
302 self.playlist.thumbs_up()
303 self.client.add_feedback.assert_called_with("token", True)
304
305 def test_thumbs_down(self):
306 self.playlist.thumbs_down()
307 self.client.add_feedback.assert_called_with("token", False)
308
309 def test_bookmark_song(self):
310 self.playlist.bookmark_song()
311 self.client.add_song_bookmark.assert_called_with("token")
312
313 def test_bookmark_artist(self):
314 self.playlist.bookmark_artist()
315 self.client.add_artist_bookmark.assert_called_with("token")
316
317 def test_sleep_song(self):
318 self.playlist.sleep()
319 self.client.sleep_song.assert_called_with("token")
320
296 321
297class TestPlaylistModel(TestCase): 322class TestPlaylistModel(TestCase):
298 323
324 def setUp(self):
325 self.client = Mock()
326 self.playlist = plm.PlaylistModel(self.client)
327
299 def test_unplayable_get_is_playable(self): 328 def test_unplayable_get_is_playable(self):
300 playlist = plm.PlaylistModel(Mock()) 329 self.playlist.audio_url = ""
301 playlist.audio_url = "" 330 self.assertFalse(self.playlist.get_is_playable())
302 self.assertFalse(playlist.get_is_playable())
303 331
304 def test_playable_get_is_playable(self): 332 def test_playable_get_is_playable(self):
305 client = Mock() 333 self.playlist.audio_url = "foo"
306 playlist = plm.PlaylistModel(client) 334 self.playlist.get_is_playable()
307 playlist.audio_url = "foo" 335 self.client.transport.test_url.assert_called_with("foo")
308 playlist.get_is_playable() 336
309 client.transport.test_url.assert_called_with("foo") 337 def test_not_implemented_interface_methods(self):
338 with self.assertRaises(NotImplementedError):
339 self.playlist.thumbs_up()
340
341 with self.assertRaises(NotImplementedError):
342 self.playlist.thumbs_down()
343
344 with self.assertRaises(NotImplementedError):
345 self.playlist.bookmark_song()
346
347 with self.assertRaises(NotImplementedError):
348 self.playlist.bookmark_artist()
349
350 with self.assertRaises(NotImplementedError):
351 self.playlist.sleep()
310 352
311 353
312class TestAdItem(TestCase): 354class TestAdItem(TestCase):
@@ -393,6 +435,13 @@ class TestAdItem(TestCase):
393 assert self.result.register_ad.called 435 assert self.result.register_ad.called
394 assert super_mock.called 436 assert super_mock.called
395 437
438 def test_noop_methods(self):
439 self.assertIsNone(self.result.thumbs_up())
440 self.assertIsNone(self.result.thumbs_down())
441 self.assertIsNone(self.result.bookmark_song())
442 self.assertIsNone(self.result.bookmark_artist())
443 self.assertIsNone(self.result.sleep())
444
396 445
397class TestSearchResultItem(TestCase): 446class TestSearchResultItem(TestCase):
398 447
@@ -471,6 +520,12 @@ class TestSearchResultItem(TestCase):
471 sm.SearchResultItem.from_json( 520 sm.SearchResultItem.from_json(
472 self.api_client_mock, self.UNKNOWN_JSON_DATA) 521 self.api_client_mock, self.UNKNOWN_JSON_DATA)
473 522
523 def test_interface(self):
524 result = sm.SearchResultItem(self.api_client_mock)
525
526 with self.assertRaises(NotImplementedError):
527 result.create_station()
528
474 529
475class TestArtistSearchResultItem(TestCase): 530class TestArtistSearchResultItem(TestCase):
476 531
@@ -642,6 +697,19 @@ class TestGenreStationList(TestCase):
642 self.assertTrue(stations.has_changed()) 697 self.assertTrue(stations.has_changed())
643 698
644 699
700class TestGenreStation(TestCase):
701
702 TEST_DATA = {"categoryName": "foo", "stations": []}
703
704 def test_get_playlist_throws_exception(self):
705 api_client = Mock()
706 genre_station = stm.GenreStation.from_json(api_client, self.TEST_DATA)
707
708 with self.assertRaisesRegex(
709 NotImplementedError, "Genre stations do not have playlists.*"):
710 genre_station.get_playlist()
711
712
645class TestStationList(TestCase): 713class TestStationList(TestCase):
646 714
647 TEST_DATA = { 715 TEST_DATA = {
@@ -694,3 +762,12 @@ class TestPandoraType(TestCase):
694 def test_it_returns_genre_for_unknown_string(self): 762 def test_it_returns_genre_for_unknown_string(self):
695 pt = plm.PandoraType.from_string("FOO") 763 pt = plm.PandoraType.from_string("FOO")
696 self.assertIs(plm.PandoraType.GENRE, pt) 764 self.assertIs(plm.PandoraType.GENRE, pt)
765
766
767class TestSyntheticField(TestCase):
768
769 def test_interface(self):
770 sf = m.SyntheticField(field="foo")
771
772 with self.assertRaises(NotImplementedError):
773 sf.formatter(None, None, None)