From d1b45499b3234a8a7417bdf290f28d3626ed9f76 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Sat, 19 Dec 2020 21:22:24 +0000 Subject: Use correct token when creating stations Track tokens should only be used when creating stations from tracks not from search results. Also return the created station from the search models when a station is created. Fixes #63 Closes #64 --- pandora/client.py | 10 ++++++++-- pandora/models/search.py | 6 +++--- tests/test_pandora/test_client.py | 9 ++++++++- tests/test_pandora/test_models.py | 6 +++--- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pandora/client.py b/pandora/client.py index a98056c..e39b2cc 100644 --- a/pandora/client.py +++ b/pandora/client.py @@ -218,7 +218,11 @@ class APIClient(BaseAPIClient): ) def create_station( - self, search_token=None, artist_token=None, track_token=None + self, + search_token=None, + artist_token=None, + track_token=None, + song_token=None, ): from .models.station import Station @@ -227,7 +231,9 @@ class APIClient(BaseAPIClient): if search_token: kwargs = {"musicToken": search_token} elif artist_token: - kwargs = {"trackToken": artist_token, "musicType": "artist"} + kwargs = {"musicToken": artist_token, "musicType": "artist"} + elif song_token: + kwargs = {"musicToken": song_token, "musicType": "song"} elif track_token: kwargs = {"trackToken": track_token, "musicType": "song"} else: diff --git a/pandora/models/search.py b/pandora/models/search.py index fe31561..55fd685 100644 --- a/pandora/models/search.py +++ b/pandora/models/search.py @@ -51,7 +51,7 @@ class ArtistSearchResultItem(SearchResultItem): likely_match = Field("likelyMatch", default=False) def create_station(self): - self._api_client.create_station(artist_token=self.token) + return self._api_client.create_station(artist_token=self.token) @classmethod def from_json(cls, api_client, data): @@ -66,7 +66,7 @@ class SongSearchResultItem(SearchResultItem): song_name = Field("songName") def create_station(self): - self._api_client.create_station(track_token=self.token) + return self._api_client.create_station(track_token=self.token) @classmethod def from_json(cls, api_client, data): @@ -80,7 +80,7 @@ class GenreStationSearchResultItem(SearchResultItem): station_name = Field("stationName") def create_station(self): - self._api_client.create_station(search_token=self.token) + return self._api_client.create_station(search_token=self.token) @classmethod def from_json(cls, api_client, data): diff --git a/tests/test_pandora/test_client.py b/tests/test_pandora/test_client.py index 1c5a229..4262d34 100644 --- a/tests/test_pandora/test_client.py +++ b/tests/test_pandora/test_client.py @@ -177,7 +177,14 @@ class TestCreatingStation(TestCase): client = APIClient(Mock(return_value={}), None, None, None, None) client.create_station(artist_token="foo") client.transport.assert_called_with( - "station.createStation", trackToken="foo", musicType="artist" + "station.createStation", musicToken="foo", musicType="artist" + ) + + def test_using_song_token(self): + client = APIClient(Mock(return_value={}), None, None, None, None) + client.create_station(song_token="foo") + client.transport.assert_called_with( + "station.createStation", musicToken="foo", musicType="song" ) def test_using_track_token(self): diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py index 8605d1b..a155588 100644 --- a/tests/test_pandora/test_models.py +++ b/tests/test_pandora/test_models.py @@ -577,7 +577,7 @@ class TestArtistSearchResultItem(TestCase): ) result._api_client.create_station = Mock() - result.create_station() + self.assertIsNotNone(result.create_station()) result._api_client.create_station.assert_called_with( artist_token=result.token ) @@ -614,7 +614,7 @@ class TestSongSearchResultItem(TestCase): ) result._api_client.create_station = Mock() - result.create_station() + self.assertIsNotNone(result.create_station()) result._api_client.create_station.assert_called_with( track_token=result.token ) @@ -650,7 +650,7 @@ class TestGenreStationSearchResultItem(TestCase): ) result._api_client.create_station = Mock() - result.create_station() + self.assertIsNotNone(result.create_station()) result._api_client.create_station.assert_called_with( search_token=result.token ) -- cgit v1.2.3