aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjcass <john.cass77@gmail.com>2016-05-29 13:42:07 +0200
committerjcass <john.cass77@gmail.com>2016-05-29 13:42:07 +0200
commitaabde7966a7ffef083f73368ca6f2904a778a78f (patch)
tree317339243d7d14653e49904a6d05db0a709f2401 /tests
parent526b28e6f546dabb945500ed2dcb82d7988416df (diff)
downloadpydora-aabde7966a7ffef083f73368ca6f2904a778a78f.tar.bz2
pydora-aabde7966a7ffef083f73368ca6f2904a778a78f.tar.xz
pydora-aabde7966a7ffef083f73368ca6f2904a778a78f.zip
Fix SearchResult model.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_pandora/test_models.py74
1 files changed, 73 insertions, 1 deletions
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
2from datetime import datetime 2from datetime import datetime
3from pandora.py2compat import Mock, patch 3from pandora.py2compat import Mock, patch
4from pandora import APIClient 4from pandora import APIClient
5from pandora.models.pandora import AdItem, PlaylistModel 5from pandora.models.pandora import AdItem, PlaylistModel, SearchResultItem, SearchResult
6from pandora.errors import ParameterMissing 6from pandora.errors import ParameterMissing
7 7
8import pandora.models as m 8import 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
278class 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
318class 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))