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

This commit is contained in:
Jenkins 2016-01-22 13:16:44 +00:00 committed by Gerrit Code Review
commit e65e01014e
2 changed files with 23 additions and 1 deletions
swiftclient
tests/unit

@ -931,7 +931,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

@ -531,6 +531,27 @@ class TestShell(testtools.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