diff options
author | John Cass <john.cass77@gmail.com> | 2016-06-07 07:23:57 +0200 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2016-06-06 22:23:57 -0700 |
commit | 79af8c5a61de0feb54bd14c17fb81dd742c04e2c (patch) | |
tree | b95360a631e9565920081e061230d7c388c27375 /tests | |
parent | b414e2c38b8bc13bafed500b656aa68be0db820c (diff) | |
download | pydora-79af8c5a61de0feb54bd14c17fb81dd742c04e2c.tar.bz2 pydora-79af8c5a61de0feb54bd14c17fb81dd742c04e2c.tar.xz pydora-79af8c5a61de0feb54bd14c17fb81dd742c04e2c.zip |
Add support for searching genre stations. (#45)
Add support for searching genre stations.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_pandora/test_models.py | 173 |
1 files changed, 141 insertions, 32 deletions
diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py index 7383d85..3a771ab 100644 --- a/tests/test_pandora/test_models.py +++ b/tests/test_pandora/test_models.py | |||
@@ -277,54 +277,157 @@ class TestAdItem(TestCase): | |||
277 | 277 | ||
278 | class TestSearchResultItem(TestCase): | 278 | class TestSearchResultItem(TestCase): |
279 | 279 | ||
280 | JSON_DATA = { | 280 | SONG_JSON_DATA = { |
281 | "artistName": "artist_name_mock", | 281 | "artistName": "artist_name_mock", |
282 | "musicToken": "S0000000", | 282 | "musicToken": "S0000000", |
283 | "songName": "song_name_mock", | 283 | "songName": "song_name_mock", |
284 | "score": 100 | 284 | "score": 100 |
285 | } | 285 | } |
286 | 286 | ||
287 | ARTIST_JSON_DATA = { | ||
288 | "artistName": "artist_name_mock", | ||
289 | "musicToken": "R0000000", | ||
290 | "likelyMatch": False, | ||
291 | "score": 100 | ||
292 | } | ||
293 | |||
294 | COMPOSER_JSON_DATA = { | ||
295 | "artistName": "composer_name_mock", | ||
296 | "musicToken": "C0000000", | ||
297 | "likelyMatch": False, | ||
298 | "score": 100 | ||
299 | } | ||
300 | |||
301 | GENRE_JSON_DATA = { | ||
302 | "stationName": "station_name_mock", | ||
303 | "musicToken": "G0000000", | ||
304 | "score": 100 | ||
305 | } | ||
306 | |||
287 | def setUp(self): | 307 | def setUp(self): |
288 | api_client_mock = Mock(spec=APIClient) | 308 | self.api_client_mock = Mock(spec=APIClient) |
289 | api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY | 309 | self.api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY |
290 | self.result = SearchResultItem.from_json(api_client_mock, self.JSON_DATA) | 310 | |
311 | def test_is_song(self): | ||
312 | result = SearchResultItem.from_json(self.api_client_mock, self.SONG_JSON_DATA) | ||
313 | assert result.is_song | ||
314 | assert not result.is_artist | ||
315 | assert not result.is_composer | ||
316 | assert not result.is_genre_station | ||
317 | |||
318 | def test_is_artist(self): | ||
319 | result = SearchResultItem.from_json(self.api_client_mock, self.ARTIST_JSON_DATA) | ||
320 | assert not result.is_song | ||
321 | assert result.is_artist | ||
322 | assert not result.is_composer | ||
323 | assert not result.is_genre_station | ||
324 | |||
325 | def test_is_composer(self): | ||
326 | result = SearchResultItem.from_json(self.api_client_mock, self.COMPOSER_JSON_DATA) | ||
327 | assert not result.is_song | ||
328 | assert not result.is_artist | ||
329 | assert result.is_composer | ||
330 | assert not result.is_genre_station | ||
331 | |||
332 | def test_is_genre_station(self): | ||
333 | result = SearchResultItem.from_json(self.api_client_mock, self.GENRE_JSON_DATA) | ||
334 | assert not result.is_song | ||
335 | assert not result.is_artist | ||
336 | assert not result.is_composer | ||
337 | assert result.is_genre_station | ||
338 | |||
339 | def test_create_station(self): | ||
340 | result = SearchResultItem.from_json(self.api_client_mock, self.SONG_JSON_DATA) | ||
341 | |||
342 | self.assertRaises(NotImplementedError, result.create_station()) | ||
343 | |||
344 | |||
345 | class TestArtistSearchResultItem(TestCase): | ||
346 | |||
347 | ARTIST_JSON_DATA = { | ||
348 | "artistName": "artist_name_mock", | ||
349 | "musicToken": "R0000000", | ||
350 | "likelyMatch": False, | ||
351 | "score": 100 | ||
352 | } | ||
353 | |||
354 | COMPOSER_JSON_DATA = { | ||
355 | "artistName": "composer_name_mock", | ||
356 | "musicToken": "C0000000", | ||
357 | "likelyMatch": False, | ||
358 | "score": 100 | ||
359 | } | ||
360 | |||
361 | def setUp(self): | ||
362 | self.api_client_mock = Mock(spec=APIClient) | ||
363 | self.api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY | ||
291 | 364 | ||
292 | def test_repr(self): | 365 | def test_repr(self): |
293 | expected = ("SearchResultItem(artist='artist_name_mock', likely_match=False, score=100, " | 366 | result = SearchResultItem.from_json(self.api_client_mock, self.ARTIST_JSON_DATA) |
294 | "song_name='song_name_mock', token='S0000000')") | 367 | expected = ("ArtistSearchResultItem(artist='artist_name_mock', likely_match=False, score=100, token='R0000000')") |
295 | self.assertEqual(expected, repr(self.result)) | 368 | self.assertEqual(expected, repr(result)) |
296 | 369 | ||
297 | def test_is_song(self): | 370 | result = SearchResultItem.from_json(self.api_client_mock, self.COMPOSER_JSON_DATA) |
298 | assert self.result.is_song | 371 | expected = ("ArtistSearchResultItem(artist='composer_name_mock', likely_match=False, score=100, token='C0000000')") |
372 | self.assertEqual(expected, repr(result)) | ||
299 | 373 | ||
300 | self.result.token = 'R123456' | 374 | def test_create_station(self): |
301 | assert not self.result.is_song | 375 | result = SearchResultItem.from_json(self.api_client_mock, self.ARTIST_JSON_DATA) |
376 | result._api_client.create_station = Mock() | ||
302 | 377 | ||
303 | def test_is_artist(self): | 378 | result.create_station() |
304 | assert not self.result.is_artist | 379 | result._api_client.create_station.assert_called_with(artist_token=result.token) |
305 | 380 | ||
306 | self.result.token = 'R123456' | ||
307 | assert self.result.is_artist | ||
308 | 381 | ||
309 | def test_is_composer(self): | 382 | class TestSongSearchResultItem(TestCase): |
310 | assert not self.result.is_composer | ||
311 | 383 | ||
312 | self.result.token = 'C12345' | 384 | SONG_JSON_DATA = { |
313 | assert self.result.is_composer | 385 | "artistName": "artist_name_mock", |
386 | "musicToken": "S0000000", | ||
387 | "songName": "song_name_mock", | ||
388 | "score": 100 | ||
389 | } | ||
314 | 390 | ||
391 | def setUp(self): | ||
392 | self.api_client_mock = Mock(spec=APIClient) | ||
393 | self.api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY | ||
315 | 394 | ||
316 | def test_create_station_song(self): | 395 | def test_repr(self): |
317 | self.result._api_client.create_station = Mock() | 396 | result = SearchResultItem.from_json(self.api_client_mock, self.SONG_JSON_DATA) |
397 | expected = ("SongSearchResultItem(artist='artist_name_mock', score=100, song_name='song_name_mock', token='S0000000')") | ||
398 | self.assertEqual(expected, repr(result)) | ||
399 | |||
400 | def test_create_station(self): | ||
401 | result = SearchResultItem.from_json(self.api_client_mock, self.SONG_JSON_DATA) | ||
402 | result._api_client.create_station = Mock() | ||
403 | |||
404 | result.create_station() | ||
405 | result._api_client.create_station.assert_called_with(track_token=result.token) | ||
406 | |||
407 | |||
408 | class TestGenreStationSearchResultItem(TestCase): | ||
409 | |||
410 | GENRE_JSON_DATA = { | ||
411 | "stationName": "station_name_mock", | ||
412 | "musicToken": "G0000000", | ||
413 | "score": 100 | ||
414 | } | ||
318 | 415 | ||
319 | self.result.create_station() | 416 | def setUp(self): |
320 | self.result._api_client.create_station.assert_called_with(track_token=self.result.token) | 417 | self.api_client_mock = Mock(spec=APIClient) |
418 | self.api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY | ||
321 | 419 | ||
322 | def test_create_station_artist(self): | 420 | def test_repr(self): |
323 | self.result.token = 'R123456' | 421 | result = SearchResultItem.from_json(self.api_client_mock, self.GENRE_JSON_DATA) |
324 | self.result._api_client.create_station = Mock() | 422 | expected = ("GenreStationSearchResultItem(score=100, station_name='station_name_mock', token='G0000000')") |
423 | self.assertEqual(expected, repr(result)) | ||
424 | |||
425 | def test_create_station(self): | ||
426 | result = SearchResultItem.from_json(self.api_client_mock, self.GENRE_JSON_DATA) | ||
427 | result._api_client.create_station = Mock() | ||
325 | 428 | ||
326 | self.result.create_station() | 429 | result.create_station() |
327 | self.result._api_client.create_station.assert_called_with(artist_token=self.result.token) | 430 | result._api_client.create_station.assert_called_with(search_token=result.token) |
328 | 431 | ||
329 | 432 | ||
330 | class TestSearchResult(TestCase): | 433 | class TestSearchResult(TestCase): |
@@ -343,6 +446,11 @@ class TestSearchResult(TestCase): | |||
343 | 'musicToken': 'R000000', | 446 | 'musicToken': 'R000000', |
344 | 'likelyMatch': False, | 447 | 'likelyMatch': False, |
345 | 'score': 80 | 448 | 'score': 80 |
449 | }], | ||
450 | 'genreStations': [{ | ||
451 | 'musicToken': 'G0000', | ||
452 | 'stationName': 'station_mock', | ||
453 | 'score': 50 | ||
346 | }] | 454 | }] |
347 | } | 455 | } |
348 | 456 | ||
@@ -352,8 +460,9 @@ class TestSearchResult(TestCase): | |||
352 | self.result = SearchResult.from_json(api_client_mock, self.JSON_DATA) | 460 | self.result = SearchResult.from_json(api_client_mock, self.JSON_DATA) |
353 | 461 | ||
354 | def test_repr(self): | 462 | def test_repr(self): |
355 | expected = ("SearchResult(artists=[SearchResultItem(artist='artist_mock', " | 463 | expected = ("SearchResult(artists=[ArtistSearchResultItem(artist='artist_mock', likely_match=False, score=80, " |
356 | "likely_match=False, score=80, song_name=None, token='R000000')], explanation='', " | 464 | "token='R000000')], explanation='', genre_stations=[GenreStationSearchResultItem(score=50, " |
357 | "nearest_matches_available=True, songs=[SearchResultItem(artist='song_artist_mock', " | 465 | "station_name='station_mock', token='G0000')], nearest_matches_available=True, " |
358 | "likely_match=False, score=100, song_name='song_name_mock', token='S0000000')])") | 466 | "songs=[SongSearchResultItem(artist='song_artist_mock', score=100, song_name='song_name_mock', " |
467 | "token='S0000000')])") | ||
359 | self.assertEqual(expected, repr(self.result)) | 468 | self.assertEqual(expected, repr(self.result)) |