aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2020-12-19 21:22:24 +0000
committerMike Crute <mike@crute.us>2020-12-19 21:22:24 +0000
commitd1b45499b3234a8a7417bdf290f28d3626ed9f76 (patch)
treebd804541737b0bbfd183fd8fea9367658352b1db
parent1af5836e5c1b727794916e2007aa96d757d0da80 (diff)
downloadpydora-d1b45499b3234a8a7417bdf290f28d3626ed9f76.tar.bz2
pydora-d1b45499b3234a8a7417bdf290f28d3626ed9f76.tar.xz
pydora-d1b45499b3234a8a7417bdf290f28d3626ed9f76.zip
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
-rw-r--r--pandora/client.py10
-rw-r--r--pandora/models/search.py6
-rw-r--r--tests/test_pandora/test_client.py9
-rw-r--r--tests/test_pandora/test_models.py6
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):
218 ) 218 )
219 219
220 def create_station( 220 def create_station(
221 self, search_token=None, artist_token=None, track_token=None 221 self,
222 search_token=None,
223 artist_token=None,
224 track_token=None,
225 song_token=None,
222 ): 226 ):
223 from .models.station import Station 227 from .models.station import Station
224 228
@@ -227,7 +231,9 @@ class APIClient(BaseAPIClient):
227 if search_token: 231 if search_token:
228 kwargs = {"musicToken": search_token} 232 kwargs = {"musicToken": search_token}
229 elif artist_token: 233 elif artist_token:
230 kwargs = {"trackToken": artist_token, "musicType": "artist"} 234 kwargs = {"musicToken": artist_token, "musicType": "artist"}
235 elif song_token:
236 kwargs = {"musicToken": song_token, "musicType": "song"}
231 elif track_token: 237 elif track_token:
232 kwargs = {"trackToken": track_token, "musicType": "song"} 238 kwargs = {"trackToken": track_token, "musicType": "song"}
233 else: 239 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):
51 likely_match = Field("likelyMatch", default=False) 51 likely_match = Field("likelyMatch", default=False)
52 52
53 def create_station(self): 53 def create_station(self):
54 self._api_client.create_station(artist_token=self.token) 54 return self._api_client.create_station(artist_token=self.token)
55 55
56 @classmethod 56 @classmethod
57 def from_json(cls, api_client, data): 57 def from_json(cls, api_client, data):
@@ -66,7 +66,7 @@ class SongSearchResultItem(SearchResultItem):
66 song_name = Field("songName") 66 song_name = Field("songName")
67 67
68 def create_station(self): 68 def create_station(self):
69 self._api_client.create_station(track_token=self.token) 69 return self._api_client.create_station(track_token=self.token)
70 70
71 @classmethod 71 @classmethod
72 def from_json(cls, api_client, data): 72 def from_json(cls, api_client, data):
@@ -80,7 +80,7 @@ class GenreStationSearchResultItem(SearchResultItem):
80 station_name = Field("stationName") 80 station_name = Field("stationName")
81 81
82 def create_station(self): 82 def create_station(self):
83 self._api_client.create_station(search_token=self.token) 83 return self._api_client.create_station(search_token=self.token)
84 84
85 @classmethod 85 @classmethod
86 def from_json(cls, api_client, data): 86 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):
177 client = APIClient(Mock(return_value={}), None, None, None, None) 177 client = APIClient(Mock(return_value={}), None, None, None, None)
178 client.create_station(artist_token="foo") 178 client.create_station(artist_token="foo")
179 client.transport.assert_called_with( 179 client.transport.assert_called_with(
180 "station.createStation", trackToken="foo", musicType="artist" 180 "station.createStation", musicToken="foo", musicType="artist"
181 )
182
183 def test_using_song_token(self):
184 client = APIClient(Mock(return_value={}), None, None, None, None)
185 client.create_station(song_token="foo")
186 client.transport.assert_called_with(
187 "station.createStation", musicToken="foo", musicType="song"
181 ) 188 )
182 189
183 def test_using_track_token(self): 190 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):
577 ) 577 )
578 result._api_client.create_station = Mock() 578 result._api_client.create_station = Mock()
579 579
580 result.create_station() 580 self.assertIsNotNone(result.create_station())
581 result._api_client.create_station.assert_called_with( 581 result._api_client.create_station.assert_called_with(
582 artist_token=result.token 582 artist_token=result.token
583 ) 583 )
@@ -614,7 +614,7 @@ class TestSongSearchResultItem(TestCase):
614 ) 614 )
615 result._api_client.create_station = Mock() 615 result._api_client.create_station = Mock()
616 616
617 result.create_station() 617 self.assertIsNotNone(result.create_station())
618 result._api_client.create_station.assert_called_with( 618 result._api_client.create_station.assert_called_with(
619 track_token=result.token 619 track_token=result.token
620 ) 620 )
@@ -650,7 +650,7 @@ class TestGenreStationSearchResultItem(TestCase):
650 ) 650 )
651 result._api_client.create_station = Mock() 651 result._api_client.create_station = Mock()
652 652
653 result.create_station() 653 self.assertIsNotNone(result.create_station())
654 result._api_client.create_station.assert_called_with( 654 result._api_client.create_station.assert_called_with(
655 search_token=result.token 655 search_token=result.token
656 ) 656 )