From ee8c1bab9873c0bf87a12ebebc4a12c233586687 Mon Sep 17 00:00:00 2001 From: Charles Hsu Date: Mon, 17 Aug 2015 17:06:44 +0800 Subject: Convert http response(byte string) to string in python3. Avoid a TypeError exception in python3. Change-Id: I4039e3f2a88b5f681288b5ca8dd5c63c13b7764f Closes-bug: #1457012 --- swiftclient/shell.py | 3 ++- tests/unit/test_shell.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/swiftclient/shell.py b/swiftclient/shell.py index f2388fc..ed026b8 100755 --- a/swiftclient/shell.py +++ b/swiftclient/shell.py @@ -875,7 +875,8 @@ def st_upload(parser, args, output_manager): if error.http_response_content: if msg: msg += ': ' - msg += error.http_response_content[:60] + msg += (error.http_response_content + .decode('utf8')[:60]) msg = ': %s' % msg else: msg = ': %s' % error diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index 4ac2f5b..34e3206 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -467,6 +467,27 @@ class TestShell(unittest.TestCase): 'x-object-meta-mtime': mock.ANY}, response_dict={}) + @mock.patch('swiftclient.service.SwiftService.upload') + def test_upload_object_with_account_readonly(self, upload): + argv = ["", "upload", "container", self.tmpfile] + upload.return_value = [ + {"success": False, + "headers": {}, + "action": 'create_container', + "error": swiftclient.ClientException( + 'Container PUT failed', + http_status=403, + http_reason='Forbidden', + http_response_content=b'

Forbidden

') + }] + + with CaptureOutput() as output: + swiftclient.shell.main(argv) + self.assertTrue(output.err != '') + warning_msg = "Warning: failed to create container 'container': " \ + "403 Forbidden" + self.assertTrue(output.err.startswith(warning_msg)) + @mock.patch('swiftclient.service.Connection') def test_upload_delete_slo_segments(self, connection): # Upload delete existing segments -- cgit v1.2.1