summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-01-23 14:47:36 +0000
committerGerrit Code Review <review@openstack.org>2015-01-23 14:47:36 +0000
commitcb34b9b6ebf11b23c5dabf5631357c250008720e (patch)
treea2d0004d45d998ee505ce2e6d58b4744ca4ea1ce
parent88f6319b7b16e1b865588d735e41f4b8448879b6 (diff)
parent62df6c669f2625582cea9602ed2ec4a4aca2948a (diff)
downloadpython-glanceclient-cb34b9b6ebf11b23c5dabf5631357c250008720e.tar.gz
Merge "Handle HTTP byte returns in python 3"
-rw-r--r--glanceclient/common/http.py4
-rw-r--r--tests/test_http.py2
-rw-r--r--tests/utils.py9
3 files changed, 11 insertions, 4 deletions
diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py
index a2ade22..67fde15 100644
--- a/glanceclient/common/http.py
+++ b/glanceclient/common/http.py
@@ -226,7 +226,7 @@ class HTTPClient(object):
if not resp.ok:
LOG.debug("Request returned failure status %s." % resp.status_code)
- raise exc.from_response(resp, resp.content)
+ raise exc.from_response(resp, resp.text)
elif resp.status_code == requests.codes.MULTIPLE_CHOICES:
raise exc.from_response(resp)
@@ -239,7 +239,7 @@ class HTTPClient(object):
body_iter = resp.iter_content(chunk_size=CHUNKSIZE)
self.log_http_response(resp)
else:
- content = resp.content
+ content = resp.text
self.log_http_response(resp, content)
if content_type and content_type.startswith('application/json'):
# Let's use requests json method,
diff --git a/tests/test_http.py b/tests/test_http.py
index 54e56e2..985284e 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -221,7 +221,7 @@ class TestClient(testtools.TestCase):
def test_http_json(self):
data = {"test": "json_request"}
- fake = utils.FakeResponse({}, "OK")
+ fake = utils.FakeResponse({}, b"OK")
def test_json(passed_data):
"""
diff --git a/tests/utils.py b/tests/utils.py
index b2849e5..845b185 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -132,8 +132,15 @@ class FakeResponse(object):
return self.body.read()
return self.body
+ @property
+ def text(self):
+ if isinstance(self.content, six.binary_type):
+ return self.content.decode('utf-8')
+
+ return self.content
+
def json(self, **kwargs):
- return self.body and json.loads(self.content) or ""
+ return self.body and json.loads(self.text) or ""
def iter_content(self, chunk_size=1, decode_unicode=False):
while True: