aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2015-12-06 19:33:10 -0800
committerMike Crute <mcrute@gmail.com>2015-12-06 19:33:10 -0800
commitc4ddc5ce038950a169d56307c098c928c9d3cace (patch)
tree8df3e4a1231064a50289da5fd63d992b8021d723 /tests
parent8ee4f2470f81c1b08cce2c37ba940a547731d190 (diff)
downloadpydora-c4ddc5ce038950a169d56307c098c928c9d3cace.tar.bz2
pydora-c4ddc5ce038950a169d56307c098c928c9d3cace.tar.xz
pydora-c4ddc5ce038950a169d56307c098c928c9d3cace.zip
Add some tests
Diffstat (limited to 'tests')
-rw-r--r--tests/test_pandora/test_client.py37
-rw-r--r--tests/test_pandora/test_errors.py17
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/test_pandora/test_client.py b/tests/test_pandora/test_client.py
index 835dc0d..62b8440 100644
--- a/tests/test_pandora/test_client.py
+++ b/tests/test_pandora/test_client.py
@@ -5,6 +5,43 @@ from pandora.errors import InvalidAuthToken
5from pandora.py2compat import Mock, MagicMock, call, patch 5from pandora.py2compat import Mock, MagicMock, call, patch
6 6
7 7
8class TestAPIClientLogin(TestCase):
9
10 class StubTransport(object):
11
12 API_VERSION = None
13
14 partner = None
15 user = None
16
17 FAKE_PARTNER = object()
18 FAKE_USER = object()
19
20 def __call__(self, method, **params):
21 if method == "auth.partnerLogin":
22 return self.FAKE_PARTNER
23 elif method == "auth.userLogin":
24 return self.FAKE_USER
25 else:
26 raise AssertionError("Invalid call")
27
28 def set_partner(self, partner):
29 self.partner = partner
30
31 def set_user(self, user):
32 self.user = user
33
34 def test_login(self):
35 transport = self.StubTransport()
36 client = BaseAPIClient(transport, None, None, None)
37 client.login("foobear", "secret")
38
39 self.assertEqual("foobear", client.username)
40 self.assertEqual("secret", client.password)
41 self.assertIs(self.StubTransport.FAKE_USER, transport.user)
42 self.assertIs(self.StubTransport.FAKE_PARTNER, transport.partner)
43
44
8class TestCallingAPIClient(TestCase): 45class TestCallingAPIClient(TestCase):
9 46
10 def test_call_should_retry_on_token_error(self): 47 def test_call_should_retry_on_token_error(self):
diff --git a/tests/test_pandora/test_errors.py b/tests/test_pandora/test_errors.py
new file mode 100644
index 0000000..778771a
--- /dev/null
+++ b/tests/test_pandora/test_errors.py
@@ -0,0 +1,17 @@
1from unittest import TestCase
2
3from pandora.errors import InternalServerError, PandoraException
4
5
6class TestPandoraExceptionConstructionFromErrorCode(TestCase):
7
8 def test_it_returns_specific_error_class_if_possible(self):
9 error = PandoraException.from_code(0, "Test Message")
10 self.assertIsInstance(error, InternalServerError)
11 self.assertEqual("Test Message", error.extended_message)
12 self.assertEqual(0, error.code)
13
14 def test_it_returns_generic_error_if_unknown(self):
15 error = PandoraException.from_code(-99, "Test Message")
16 self.assertIsInstance(error, PandoraException)
17 self.assertEqual("Test Message", error.extended_message)