aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2016-01-09 14:04:47 -0800
committerMike Crute <mcrute@gmail.com>2016-01-09 14:04:47 -0800
commit3261aecab486d25909ffdd8ae70630c6838c2768 (patch)
treea2b7da7c9dca41d7d5e5fefe8091214300f9adbe
parent4603c5ab3818abd2ea8550bf4cade7dd33ad5f98 (diff)
downloadpydora-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.py23
-rw-r--r--pandora/errors.py11
-rw-r--r--tests/test_pandora/test_client.py6
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
97PandoraException._export_exceptions(locals()) 97PandoraException._export_exceptions(locals())
98
99
100class 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
46class TestCallingAPIClient(TestCase): 52class TestCallingAPIClient(TestCase):
47 53