diff options
author | jcass <john.cass77@gmail.com> | 2016-01-12 18:24:18 +0200 |
---|---|---|
committer | jcass <john.cass77@gmail.com> | 2016-01-12 18:24:18 +0200 |
commit | 473872dc0e3ffbcad5dfe4fec69e41755c47c549 (patch) | |
tree | a85607c9b18f909a7431712477ded8c6b718f8e4 | |
parent | 296c91c836ad41a5130711bcd6f30117a4c48265 (diff) | |
download | pydora-473872dc0e3ffbcad5dfe4fec69e41755c47c549.tar.bz2 pydora-473872dc0e3ffbcad5dfe4fec69e41755c47c549.tar.xz pydora-473872dc0e3ffbcad5dfe4fec69e41755c47c549.zip |
Fix to ensure InvalidAuthToken exceptions result in re-authentication and retry.
-rw-r--r-- | pandora/transport.py | 2 | ||||
-rw-r--r-- | tests/test_pandora/test_transport.py | 36 |
2 files changed, 28 insertions, 10 deletions
diff --git a/pandora/transport.py b/pandora/transport.py index bba1608..cdd1699 100644 --- a/pandora/transport.py +++ b/pandora/transport.py | |||
@@ -50,7 +50,7 @@ def retries(max_tries, exceptions=(Exception,)): | |||
50 | # Don't retry for PandoraExceptions - unlikely that result | 50 | # Don't retry for PandoraExceptions - unlikely that result |
51 | # will change for same set of input parameters. | 51 | # will change for same set of input parameters. |
52 | if isinstance(e, PandoraException): | 52 | if isinstance(e, PandoraException): |
53 | break | 53 | raise |
54 | if retries_left > 0: | 54 | if retries_left > 0: |
55 | time.sleep(delay_exponential( | 55 | time.sleep(delay_exponential( |
56 | 0.5, 2, max_tries - retries_left)) | 56 | 0.5, 2, max_tries - retries_left)) |
diff --git a/tests/test_pandora/test_transport.py b/tests/test_pandora/test_transport.py index 394916b..1393b7d 100644 --- a/tests/test_pandora/test_transport.py +++ b/tests/test_pandora/test_transport.py | |||
@@ -1,6 +1,6 @@ | |||
1 | import time | 1 | import time |
2 | from unittest import TestCase | 2 | from unittest import TestCase |
3 | from pandora.errors import PandoraException | 3 | from pandora.errors import InvalidAuthToken, PandoraException |
4 | 4 | ||
5 | from pandora.py2compat import Mock, call | 5 | from pandora.py2compat import Mock, call |
6 | 6 | ||
@@ -28,14 +28,32 @@ class TestTransport(TestCase): | |||
28 | assert client.transport._start_request.call_count == 5 | 28 | assert client.transport._start_request.call_count == 5 |
29 | 29 | ||
30 | def test_call_should_not_retry_for_pandora_exceptions(self): | 30 | def test_call_should_not_retry_for_pandora_exceptions(self): |
31 | client = TestSettingsDictBuilder._build_minimal() | 31 | with self.assertRaises(PandoraException): |
32 | client = TestSettingsDictBuilder._build_minimal() | ||
33 | |||
34 | time.sleep = Mock() | ||
35 | client.transport._make_http_request = Mock( | ||
36 | side_effect=PandoraException("error_mock")) | ||
37 | client.transport._start_request = Mock() | ||
32 | 38 | ||
33 | time.sleep = Mock() | 39 | client("method") |
34 | client.transport._make_http_request = Mock( | ||
35 | side_effect=PandoraException("error_mock")) | ||
36 | client.transport._start_request = Mock() | ||
37 | 40 | ||
38 | client("method") | 41 | client.transport._start_request.assert_has_calls([call("method")]) |
42 | assert client.transport._start_request.call_count == 1 | ||
39 | 43 | ||
40 | client.transport._start_request.assert_has_calls([call("method")]) | 44 | def test_call_should_retry_if_auth_token_expired(self): |
41 | assert client.transport._start_request.call_count == 1 | 45 | with self.assertRaises(InvalidAuthToken): |
46 | client = TestSettingsDictBuilder._build_minimal() | ||
47 | |||
48 | time.sleep = Mock() | ||
49 | client.transport._make_http_request = Mock( | ||
50 | side_effect=InvalidAuthToken("error_mock")) | ||
51 | client.transport._start_request = Mock() | ||
52 | |||
53 | client._authenticate = Mock() | ||
54 | |||
55 | client("method") | ||
56 | |||
57 | client.transport._start_request.assert_has_calls([call("method")]) | ||
58 | assert client.transport._start_request.call_count == 2 | ||
59 | assert client._authenticate.call_count == 1 | ||