aboutsummaryrefslogtreecommitdiff
path: root/tests/test_pandora/test_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_pandora/test_client.py')
-rw-r--r--tests/test_pandora/test_client.py134
1 files changed, 134 insertions, 0 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)