aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjcass <john.cass77@gmail.com>2016-06-01 04:17:09 +0200
committerjcass <john.cass77@gmail.com>2016-06-01 04:17:09 +0200
commit20080cfc037c0aa281f613c045bccd719bf5668c (patch)
treea9c3bbf6a895f4c3ddaca17ba7227bed61606c05
parentaabde7966a7ffef083f73368ca6f2904a778a78f (diff)
downloadpydora-20080cfc037c0aa281f613c045bccd719bf5668c.tar.bz2
pydora-20080cfc037c0aa281f613c045bccd719bf5668c.tar.xz
pydora-20080cfc037c0aa281f613c045bccd719bf5668c.zip
Fix SearchResult model.
-rw-r--r--pandora/models/pandora.py15
-rw-r--r--tests/test_pandora/test_models.py24
2 files changed, 32 insertions, 7 deletions
diff --git a/pandora/models/pandora.py b/pandora/models/pandora.py
index a3a83b7..d42fe0d 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,18 @@ 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 # Song result tokens start with 'S', followed by seven digits.
298 return re.compile('^([S])(\d{7})$').match(self.token)
299
300 @property
301 def is_artist(self):
302 # Artist result tokens start with 'R', followed by six digits.
303 return re.compile('^([R])(\d{6})$').match(self.token)
304
305 @property
306 def is_composer(self):
307 # Composer result tokens start with 'C', followed by five digits.
308 return re.compile('^([C])(\d{5})$').match(self.token)
296 309
297 def create_station(self): 310 def create_station(self):
298 if self.is_song: 311 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()