Convert http response(byte string) to string in python3.

Avoid a TypeError exception in python3.

Change-Id: I4039e3f2a88b5f681288b5ca8dd5c63c13b7764f
Closes-bug: #1457012
This commit is contained in:
Charles Hsu 2015-08-17 17:06:44 +08:00
parent 3c65652354
commit ee8c1bab98
2 changed files with 23 additions and 1 deletions
swiftclient
tests/unit

@ -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

@ -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'<html><h1>Forbidden</h1>')
}]
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