diff options
author | jcass <john.cass77@gmail.com> | 2015-12-28 18:36:16 +0200 |
---|---|---|
committer | jcass <john.cass77@gmail.com> | 2015-12-28 18:36:16 +0200 |
commit | e6335911d8763cf4bfaa709364e0dc6fc9d60f12 (patch) | |
tree | 438eda651605e3f222e4f5913d8d24846c3cfd2b | |
parent | d2a520dbf6257986128d14a6c7d23aa37725d5e3 (diff) | |
download | pydora-e6335911d8763cf4bfaa709364e0dc6fc9d60f12.tar.bz2 pydora-e6335911d8763cf4bfaa709364e0dc6fc9d60f12.tar.xz pydora-e6335911d8763cf4bfaa709364e0dc6fc9d60f12.zip |
Align with using Pandora's ParameterMissing exception for ValueErrors.
-rw-r--r-- | pandora/client.py | 4 | ||||
-rw-r--r-- | pandora/models/pandora.py | 7 | ||||
-rw-r--r-- | tests/test_pandora/test_client.py | 4 | ||||
-rw-r--r-- | tests/test_pandora/test_models.py | 3 |
4 files changed, 10 insertions, 8 deletions
diff --git a/pandora/client.py b/pandora/client.py index fafd872..4a8a26d 100644 --- a/pandora/client.py +++ b/pandora/client.py | |||
@@ -262,8 +262,8 @@ class APIClient(BaseAPIClient): | |||
262 | from .models.pandora import AdItem | 262 | from .models.pandora import AdItem |
263 | 263 | ||
264 | if not station_id: | 264 | if not station_id: |
265 | raise ValueError("The 'station_id' param must be defined, " | 265 | raise errors.ParameterMissing("The 'station_id' param must be " |
266 | "got: '{}'".format(station_id)) | 266 | "defined, got: '{}'".format(station_id)) |
267 | 267 | ||
268 | ad_metadata = self.get_ad_metadata(ad_token) | 268 | ad_metadata = self.get_ad_metadata(ad_token) |
269 | ad_metadata["stationId"] = station_id | 269 | ad_metadata["stationId"] = station_id |
diff --git a/pandora/models/pandora.py b/pandora/models/pandora.py index 6abd3a7..3a901e5 100644 --- a/pandora/models/pandora.py +++ b/pandora/models/pandora.py | |||
@@ -1,6 +1,7 @@ | |||
1 | from .. import BaseAPIClient | 1 | from .. import BaseAPIClient |
2 | from . import with_metaclass, ModelMetaClass | 2 | from . import with_metaclass, ModelMetaClass |
3 | from . import Field, PandoraModel, PandoraListModel, PandoraDictListModel | 3 | from . import Field, PandoraModel, PandoraListModel, PandoraDictListModel |
4 | from ..errors import ParameterMissing | ||
4 | 5 | ||
5 | 6 | ||
6 | class Station(PandoraModel): | 7 | class Station(PandoraModel): |
@@ -231,13 +232,13 @@ class AdItem(PlaylistModel): | |||
231 | if self.tracking_tokens: | 232 | if self.tracking_tokens: |
232 | self._api_client.register_ad(station_id, self.tracking_tokens) | 233 | self._api_client.register_ad(station_id, self.tracking_tokens) |
233 | else: | 234 | else: |
234 | raise ValueError('No ad tracking tokens available for ' | 235 | raise ParameterMissing('No ad tracking tokens available ' |
235 | 'registration.') | 236 | 'for registration.') |
236 | 237 | ||
237 | def prepare_playback(self): | 238 | def prepare_playback(self): |
238 | try: | 239 | try: |
239 | self.register_ad(self.station_id) | 240 | self.register_ad(self.station_id) |
240 | except ValueError as e: | 241 | except ParameterMissing as e: |
241 | if not self.tracking_tokens: | 242 | if not self.tracking_tokens: |
242 | # Ignore registration attempts if no ad tracking tokens are | 243 | # Ignore registration attempts if no ad tracking tokens are |
243 | # available | 244 | # available |
diff --git a/tests/test_pandora/test_client.py b/tests/test_pandora/test_client.py index 24d9734..69fb632 100644 --- a/tests/test_pandora/test_client.py +++ b/tests/test_pandora/test_client.py | |||
@@ -1,7 +1,7 @@ | |||
1 | from unittest import TestCase | 1 | from unittest import TestCase |
2 | 2 | ||
3 | from pandora.client import APIClient, BaseAPIClient | 3 | from pandora.client import APIClient, BaseAPIClient |
4 | from pandora.errors import InvalidAuthToken | 4 | from pandora.errors import InvalidAuthToken, ParameterMissing |
5 | from pandora.py2compat import Mock, call, patch | 5 | from pandora.py2compat import Mock, call, patch |
6 | from tests.test_pandora.test_models import TestAdItem | 6 | from tests.test_pandora.test_models import TestAdItem |
7 | 7 | ||
@@ -117,4 +117,4 @@ class TestGettingAds(TestCase): | |||
117 | client = APIClient(transport, None, None, None, None) | 117 | client = APIClient(transport, None, None, None, None) |
118 | client.get_ad_metadata = Mock() | 118 | client.get_ad_metadata = Mock() |
119 | 119 | ||
120 | self.assertRaises(ValueError, client.get_ad_item, '', 'mock_token') | 120 | self.assertRaises(ParameterMissing, client.get_ad_item, '', 'mock_token') |
diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py index 06c988c..538cee5 100644 --- a/tests/test_pandora/test_models.py +++ b/tests/test_pandora/test_models.py | |||
@@ -3,6 +3,7 @@ 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 |
6 | from pandora.errors import ParameterMissing | ||
6 | 7 | ||
7 | import pandora.models as m | 8 | import pandora.models as m |
8 | 9 | ||
@@ -235,7 +236,7 @@ class TestAdItem(TestCase): | |||
235 | assert self.result._api_client.register_ad.called | 236 | assert self.result._api_client.register_ad.called |
236 | 237 | ||
237 | def test_register_ad_raises_exception_if_no_tracking_tokens_available(self): | 238 | def test_register_ad_raises_exception_if_no_tracking_tokens_available(self): |
238 | with self.assertRaises(ValueError): | 239 | with self.assertRaises(ParameterMissing): |
239 | self.result.tracking_tokens = [] | 240 | self.result.tracking_tokens = [] |
240 | self.result._api_client.register_ad = Mock(spec=AdItem) | 241 | self.result._api_client.register_ad = Mock(spec=AdItem) |
241 | 242 | ||