diff options
author | jcass <john.cass77@gmail.com> | 2016-05-29 13:42:07 +0200 |
---|---|---|
committer | jcass <john.cass77@gmail.com> | 2016-05-29 13:42:07 +0200 |
commit | aabde7966a7ffef083f73368ca6f2904a778a78f (patch) | |
tree | 317339243d7d14653e49904a6d05db0a709f2401 | |
parent | 526b28e6f546dabb945500ed2dcb82d7988416df (diff) | |
download | pydora-aabde7966a7ffef083f73368ca6f2904a778a78f.tar.bz2 pydora-aabde7966a7ffef083f73368ca6f2904a778a78f.tar.xz pydora-aabde7966a7ffef083f73368ca6f2904a778a78f.zip |
Fix SearchResult model.
-rw-r--r-- | pandora/models/pandora.py | 10 | ||||
-rw-r--r-- | tests/test_pandora/test_models.py | 74 |
2 files changed, 78 insertions, 6 deletions
diff --git a/pandora/models/pandora.py b/pandora/models/pandora.py index d0c6aab..a3a83b7 100644 --- a/pandora/models/pandora.py +++ b/pandora/models/pandora.py | |||
@@ -278,8 +278,8 @@ class Bookmark(PandoraModel): | |||
278 | 278 | ||
279 | class BookmarkList(PandoraModel): | 279 | class BookmarkList(PandoraModel): |
280 | 280 | ||
281 | songs = Field("songs", formatter=PandoraModel.from_json_list) | 281 | songs = Field("songs", formatter=Bookmark.from_json_list) |
282 | artists = Field("artists", formatter=PandoraModel.from_json_list) | 282 | artists = Field("artists", formatter=Bookmark.from_json_list) |
283 | 283 | ||
284 | 284 | ||
285 | class SearchResultItem(PandoraModel): | 285 | class SearchResultItem(PandoraModel): |
@@ -287,7 +287,7 @@ class SearchResultItem(PandoraModel): | |||
287 | artist = Field("artistName") | 287 | artist = Field("artistName") |
288 | song_name = Field("songName") | 288 | song_name = Field("songName") |
289 | score = Field("score") | 289 | score = Field("score") |
290 | likely_match = Field("likelyMatch") | 290 | likely_match = Field("likelyMatch", default=False) |
291 | token = Field("musicToken") | 291 | token = Field("musicToken") |
292 | 292 | ||
293 | @property | 293 | @property |
@@ -305,8 +305,8 @@ class SearchResult(PandoraModel): | |||
305 | 305 | ||
306 | nearest_matches_available = Field("nearMatchesAvailable") | 306 | nearest_matches_available = Field("nearMatchesAvailable") |
307 | explanation = Field("explanation") | 307 | explanation = Field("explanation") |
308 | songs = Field("songs", formatter=PandoraModel.from_json_list) | 308 | songs = Field("songs", formatter=SearchResultItem.from_json_list) |
309 | artists = Field("artists", formatter=PandoraModel.from_json_list) | 309 | artists = Field("artists", formatter=SearchResultItem.from_json_list) |
310 | 310 | ||
311 | 311 | ||
312 | class GenreStationList(PandoraDictListModel): | 312 | class GenreStationList(PandoraDictListModel): |
diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py index ec6e9d5..1ab7cd5 100644 --- a/tests/test_pandora/test_models.py +++ b/tests/test_pandora/test_models.py | |||
@@ -2,7 +2,7 @@ from unittest import TestCase | |||
2 | from datetime import datetime | 2 | from datetime import datetime |
3 | from pandora.py2compat import Mock, patch | 3 | from pandora.py2compat import Mock, patch |
4 | from pandora import APIClient | 4 | from pandora import APIClient |
5 | from pandora.models.pandora import AdItem, PlaylistModel | 5 | from pandora.models.pandora import AdItem, PlaylistModel, SearchResultItem, SearchResult |
6 | from pandora.errors import ParameterMissing | 6 | from pandora.errors import ParameterMissing |
7 | 7 | ||
8 | import pandora.models as m | 8 | import pandora.models as m |
@@ -273,3 +273,75 @@ class TestAdItem(TestCase): | |||
273 | self.result.prepare_playback() | 273 | self.result.prepare_playback() |
274 | assert self.result.register_ad.called | 274 | assert self.result.register_ad.called |
275 | assert super_mock.called | 275 | assert super_mock.called |
276 | |||
277 | |||
278 | class TestSearchResultItem(TestCase): | ||
279 | |||
280 | JSON_DATA = { | ||
281 | "artistName": "artist_name_mock", | ||
282 | "musicToken": "S0000000", | ||
283 | "songName": "song_name_mock", | ||
284 | "score": 100 | ||
285 | } | ||
286 | |||
287 | def setUp(self): | ||
288 | api_client_mock = Mock(spec=APIClient) | ||
289 | api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY | ||
290 | self.result = SearchResultItem.from_json(api_client_mock, self.JSON_DATA) | ||
291 | |||
292 | def test_repr(self): | ||
293 | expected = ("SearchResultItem(artist='artist_name_mock', likely_match=False, score=100, " | ||
294 | "song_name='song_name_mock', token='S0000000')") | ||
295 | self.assertEqual(expected, repr(self.result)) | ||
296 | |||
297 | def test_is_song_true(self): | ||
298 | assert self.result.is_song is True | ||
299 | |||
300 | def test_is_song_false(self): | ||
301 | self.result.song_name = None | ||
302 | assert self.result.is_song is False | ||
303 | |||
304 | def test_create_station_song(self): | ||
305 | self.result._api_client.create_station = Mock() | ||
306 | |||
307 | self.result.create_station() | ||
308 | self.result._api_client.create_station.assert_called_with(track_token=self.result.token) | ||
309 | |||
310 | def test_create_station_artist(self): | ||
311 | self.result.song_name = None | ||
312 | self.result._api_client.create_station = Mock() | ||
313 | |||
314 | self.result.create_station() | ||
315 | self.result._api_client.create_station.assert_called_with(artist_token=self.result.token) | ||
316 | |||
317 | |||
318 | class TestSearchResult(TestCase): | ||
319 | |||
320 | JSON_DATA = { | ||
321 | 'nearMatchesAvailable': True, | ||
322 | 'explanation': '', | ||
323 | 'songs': [{ | ||
324 | 'artistName': 'song_artist_mock', | ||
325 | 'musicToken': 'S0000000', | ||
326 | 'songName': 'song_name_mock', | ||
327 | 'score': 100 | ||
328 | }], | ||
329 | 'artists': [{ | ||
330 | 'artistName': 'artist_mock', | ||
331 | 'musicToken': 'R000000', | ||
332 | 'likelyMatch': False, | ||
333 | 'score': 80 | ||
334 | }] | ||
335 | } | ||
336 | |||
337 | def setUp(self): | ||
338 | api_client_mock = Mock(spec=APIClient) | ||
339 | api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY | ||
340 | self.result = SearchResult.from_json(api_client_mock, self.JSON_DATA) | ||
341 | |||
342 | def test_repr(self): | ||
343 | expected = ("SearchResult(artists=[SearchResultItem(artist='artist_mock', " | ||
344 | "likely_match=False, score=80, song_name=None, token='R000000')], explanation='', " | ||
345 | "nearest_matches_available=True, songs=[SearchResultItem(artist='song_artist_mock', " | ||
346 | "likely_match=False, score=100, song_name='song_name_mock', token='S0000000')])") | ||
347 | self.assertEqual(expected, repr(self.result)) | ||