From 671a646f619697c7a09931969e6d09820cfbba0b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 10 Sep 2015 13:02:32 +0200 Subject: [PATCH] Port test_utils to Python 3 * Encode explicitly JSON to UTF-8 to get HTTP body as bytes on Python 3. * Use a literal byte string, instead of a native string, for the HTTP body. Change-Id: I1ee88e1abcded9dfaf3f1d9f720782b0d7ad662d --- fuelclient/tests/unit/common/test_utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fuelclient/tests/unit/common/test_utils.py b/fuelclient/tests/unit/common/test_utils.py index ac86e98a..34b77bac 100644 --- a/fuelclient/tests/unit/common/test_utils.py +++ b/fuelclient/tests/unit/common/test_utils.py @@ -165,10 +165,14 @@ class TestUtils(base.UnitTestCase): def test_get_error_body_get_from_json(self): error_body = 'This is error body' - resp = requests.Response() - resp._content = json.dumps({ + body_json = json.dumps({ 'message': error_body }) + if isinstance(body_json, six.text_type): + body_json = body_json.encode('utf-8') + + resp = requests.Response() + resp._content = body_json exception = requests.HTTPError() exception.response = resp @@ -176,7 +180,7 @@ class TestUtils(base.UnitTestCase): self.assertEqual(error.get_error_body(exception), error_body) def test_get_error_body_get_from_plaintext(self): - error_body = 'This is error body' + error_body = b'This is error body' resp = requests.Response() resp._content = error_body @@ -184,7 +188,8 @@ class TestUtils(base.UnitTestCase): exception = requests.HTTPError() exception.response = resp - self.assertEqual(error.get_error_body(exception), error_body) + self.assertEqual(error.get_error_body(exception), + error_body.decode('utf-8')) def test_get_display_data_single(self): test_data = {'a': 1, 'b': 2, 'c': 3}