diff options
author | Mike Crute <mcrute@gmail.com> | 2016-01-09 14:04:47 -0800 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2016-01-09 14:04:47 -0800 |
commit | 3261aecab486d25909ffdd8ae70630c6838c2768 (patch) | |
tree | a2b7da7c9dca41d7d5e5fefe8091214300f9adbe | |
parent | 4603c5ab3818abd2ea8550bf4cade7dd33ad5f98 (diff) | |
download | pydora-3261aecab486d25909ffdd8ae70630c6838c2768.tar.bz2 pydora-3261aecab486d25909ffdd8ae70630c6838c2768.tar.xz pydora-3261aecab486d25909ffdd8ae70630c6838c2768.zip |
Throw InvalidUserLogin error when login fails
fixes https://github.com/mcrute/pydora/issues/41
-rw-r--r-- | pandora/client.py | 23 | ||||
-rw-r--r-- | pandora/errors.py | 11 | ||||
-rw-r--r-- | tests/test_pandora/test_client.py | 6 |
3 files changed, 30 insertions, 10 deletions
diff --git a/pandora/client.py b/pandora/client.py index 403216e..7c9791e 100644 --- a/pandora/client.py +++ b/pandora/client.py | |||
@@ -73,16 +73,19 @@ class BaseAPIClient(object): | |||
73 | def _authenticate(self): | 73 | def _authenticate(self): |
74 | self._partner_login() | 74 | self._partner_login() |
75 | 75 | ||
76 | user = self.transport("auth.userLogin", | 76 | try: |
77 | loginType="user", | 77 | user = self.transport("auth.userLogin", |
78 | username=self.username, | 78 | loginType="user", |
79 | password=self.password, | 79 | username=self.username, |
80 | includePandoraOneInfo=True, | 80 | password=self.password, |
81 | includeSubscriptionExpiration=True, | 81 | includePandoraOneInfo=True, |
82 | returnCapped=True, | 82 | includeSubscriptionExpiration=True, |
83 | includeAdAttributes=True, | 83 | returnCapped=True, |
84 | includeAdvertiserAttributes=True, | 84 | includeAdAttributes=True, |
85 | xplatformAdCapable=True) | 85 | includeAdvertiserAttributes=True, |
86 | xplatformAdCapable=True) | ||
87 | except errors.InvalidPartnerLogin: | ||
88 | raise errors.InvalidUserLogin() | ||
86 | 89 | ||
87 | self.transport.set_user(user) | 90 | self.transport.set_user(user) |
88 | 91 | ||
diff --git a/pandora/errors.py b/pandora/errors.py index 3944490..9fbd00e 100644 --- a/pandora/errors.py +++ b/pandora/errors.py | |||
@@ -95,3 +95,14 @@ class PandoraException(Exception): | |||
95 | 95 | ||
96 | 96 | ||
97 | PandoraException._export_exceptions(locals()) | 97 | PandoraException._export_exceptions(locals()) |
98 | |||
99 | |||
100 | class InvalidUserLogin(InvalidPartnerLogin): | ||
101 | """Pydora Internal Login Error | ||
102 | |||
103 | This is thrown around a user login to disambiguate a login that is invalid | ||
104 | due to user error vs a login that is invalid due to a partner credential | ||
105 | error. The Pandora API returns 1002 in both cases. | ||
106 | """ | ||
107 | |||
108 | message = "Invalid User Login" | ||
diff --git a/tests/test_pandora/test_client.py b/tests/test_pandora/test_client.py index f7f0574..ce91e21 100644 --- a/tests/test_pandora/test_client.py +++ b/tests/test_pandora/test_client.py | |||
@@ -42,6 +42,12 @@ class TestAPIClientLogin(TestCase): | |||
42 | self.assertIs(self.StubTransport.FAKE_USER, transport.user) | 42 | self.assertIs(self.StubTransport.FAKE_USER, transport.user) |
43 | self.assertIs(self.StubTransport.FAKE_PARTNER, transport.partner) | 43 | self.assertIs(self.StubTransport.FAKE_PARTNER, transport.partner) |
44 | 44 | ||
45 | def test_login_user_error(self): | ||
46 | with self.assertRaises(errors.InvalidUserLogin): | ||
47 | transport = Mock(side_effect=[None, errors.InvalidPartnerLogin]) | ||
48 | client = BaseAPIClient(transport, None, None, None) | ||
49 | client.login("foobear", "secret") | ||
50 | |||
45 | 51 | ||
46 | class TestCallingAPIClient(TestCase): | 52 | class TestCallingAPIClient(TestCase): |
47 | 53 | ||