aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2016-05-31 20:10:03 -0700
committerMike Crute <mcrute@gmail.com>2016-05-31 20:10:03 -0700
commitc5fc706463b51ef0b2c8d54450846fea2f06fa56 (patch)
tree7b1102d97703fec6f62c4817e32a50ab529c23af
parent987e110009224d896d4759dc92566c5c638862f8 (diff)
parent27556ee4085d877e0bf689b742145a3ff46272c6 (diff)
downloadpydora-c5fc706463b51ef0b2c8d54450846fea2f06fa56.tar.bz2
pydora-c5fc706463b51ef0b2c8d54450846fea2f06fa56.tar.xz
pydora-c5fc706463b51ef0b2c8d54450846fea2f06fa56.zip
Merge pull request #44 from jcass77/enhance/search_tokens
Differentiate between types of search results.
-rw-r--r--pandora/models/pandora.py12
-rw-r--r--tests/test_pandora/test_models.py24
2 files changed, 29 insertions, 7 deletions
diff --git a/pandora/models/pandora.py b/pandora/models/pandora.py
index a3a83b7..3e168d8 100644
--- a/pandora/models/pandora.py
+++ b/pandora/models/pandora.py
@@ -1,3 +1,5 @@
1import re
2
1from .. import BaseAPIClient 3from .. import BaseAPIClient
2from . import with_metaclass, ModelMetaClass 4from . import with_metaclass, ModelMetaClass
3from . import Field, PandoraModel, PandoraListModel, PandoraDictListModel 5from . import Field, PandoraModel, PandoraListModel, PandoraDictListModel
@@ -292,7 +294,15 @@ class SearchResultItem(PandoraModel):
292 294
293 @property 295 @property
294 def is_song(self): 296 def is_song(self):
295 return self.song_name is not None 297 return self.token.startswith('S')
298
299 @property
300 def is_artist(self):
301 return self.token.startswith('R')
302
303 @property
304 def is_composer(self):
305 return self.token.startswith('C')
296 306
297 def create_station(self): 307 def create_station(self):
298 if self.is_song: 308 if self.is_song:
diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py
index 1ab7cd5..7383d85 100644
--- a/tests/test_pandora/test_models.py
+++ b/tests/test_pandora/test_models.py
@@ -294,12 +294,24 @@ class TestSearchResultItem(TestCase):
294 "song_name='song_name_mock', token='S0000000')") 294 "song_name='song_name_mock', token='S0000000')")
295 self.assertEqual(expected, repr(self.result)) 295 self.assertEqual(expected, repr(self.result))
296 296
297 def test_is_song_true(self): 297 def test_is_song(self):
298 assert self.result.is_song is True 298 assert self.result.is_song
299
300 self.result.token = 'R123456'
301 assert not self.result.is_song
302
303 def test_is_artist(self):
304 assert not self.result.is_artist
305
306 self.result.token = 'R123456'
307 assert self.result.is_artist
308
309 def test_is_composer(self):
310 assert not self.result.is_composer
311
312 self.result.token = 'C12345'
313 assert self.result.is_composer
299 314
300 def test_is_song_false(self):
301 self.result.song_name = None
302 assert self.result.is_song is False
303 315
304 def test_create_station_song(self): 316 def test_create_station_song(self):
305 self.result._api_client.create_station = Mock() 317 self.result._api_client.create_station = Mock()
@@ -308,7 +320,7 @@ class TestSearchResultItem(TestCase):
308 self.result._api_client.create_station.assert_called_with(track_token=self.result.token) 320 self.result._api_client.create_station.assert_called_with(track_token=self.result.token)
309 321
310 def test_create_station_artist(self): 322 def test_create_station_artist(self):
311 self.result.song_name = None 323 self.result.token = 'R123456'
312 self.result._api_client.create_station = Mock() 324 self.result._api_client.create_station = Mock()
313 325
314 self.result.create_station() 326 self.result.create_station()