summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Vrbanac <john.vrbanac@rackspace.com>2013-12-18 17:19:44 -0600
committerJohn Vrbanac <john.vrbanac@rackspace.com>2013-12-18 17:57:47 -0600
commit9d67ba5899e55e25601e38c21692f082cb747346 (patch)
tree4d5552bfa9d70e10ced97d8e7d1636528ff939cb
parent5f555c7ced9afb8653b746c22241c48b5be15449 (diff)
downloadpython-barbicanclient-9d67ba5899e55e25601e38c21692f082cb747346.tar.gz
Removing conditional around client status code check
The response object should always have a status_code on it. Change-Id: I341c6297a199ced88df2a39c9c8d6a4bbb5c057f
-rw-r--r--barbicanclient/client.py2
-rw-r--r--barbicanclient/test/test_client.py16
2 files changed, 11 insertions, 7 deletions
diff --git a/barbicanclient/client.py b/barbicanclient/client.py
index a03ec48..73561bb 100644
--- a/barbicanclient/client.py
+++ b/barbicanclient/client.py
@@ -126,7 +126,7 @@ class Client(object):
return resp.json()
def _check_status_code(self, resp):
- status = resp.status_code if resp else None
+ status = resp.status_code
LOG.debug('Response status {0}'.format(status))
if status == 401:
LOG.error('Auth error: {0}'.format(self._get_error_message(resp)))
diff --git a/barbicanclient/test/test_client.py b/barbicanclient/test/test_client.py
index 623c2cd..dbc3324 100644
--- a/barbicanclient/test/test_client.py
+++ b/barbicanclient/test/test_client.py
@@ -14,6 +14,7 @@
# limitations under the License.
import mock
+import requests
import unittest2 as unittest
from barbicanclient import client
@@ -60,6 +61,12 @@ class WhenTestingClientInit(unittest.TestCase):
self.fake_auth = FakeAuth(self.auth_token, self.endpoint,
self.tenant_name, self.tenant_id)
+ def _mock_response(self, content=None, status_code=200):
+ resp = requests.Response()
+ resp._content = content or '{"title": {"generic mocked response"}}'
+ resp.status_code = status_code
+ return resp
+
def test_can_be_used_without_auth_plugin(self):
c = client.Client(auth_plugin=None, endpoint=self.endpoint,
tenant_id=self.tenant_id)
@@ -88,22 +95,19 @@ class WhenTestingClientInit(unittest.TestCase):
self.assertTrue(c.base_url.endswith(self.tenant_id))
def test_should_raise_for_unauthorized_response(self):
- resp = mock.MagicMock()
- resp.status_code = 401
+ resp = self._mock_response(status_code=401)
c = client.Client(auth_plugin=self.fake_auth)
with self.assertRaises(client.HTTPAuthError):
c._check_status_code(resp)
def test_should_raise_for_server_error(self):
- resp = mock.MagicMock()
- resp.status_code = 500
+ resp = self._mock_response(status_code=500)
c = client.Client(auth_plugin=self.fake_auth)
with self.assertRaises(client.HTTPServerError):
c._check_status_code(resp)
def test_should_raise_for_client_errors(self):
- resp = mock.MagicMock()
- resp.status_code = 400
+ resp = self._mock_response(status_code=400)
c = client.Client(auth_plugin=self.fake_auth)
with self.assertRaises(client.HTTPClientError):
c._check_status_code(resp)