Handle case with None encoding during std.http action execution
During some cases resp.content may have a context not in json format and with 'None' in the resp.encoding. Need to properly handle this situation and don't try to pass 'None' as an argument to decode. Change-Id: Id87d650996f16b5ffab79d72413134a4c7fe9ca9 Closes-Bug: #1700608
This commit is contained in:
parent
5aad444d56
commit
178369459f
@ -210,7 +210,7 @@ class HTTPAction(actions.Action):
|
||||
except Exception as e:
|
||||
LOG.debug("HTTP action response is not json.")
|
||||
content = resp.content
|
||||
if content and resp.encoding != 'utf-8':
|
||||
if content and resp.encoding not in (None, 'utf-8'):
|
||||
content = content.decode(resp.encoding).encode('utf-8')
|
||||
|
||||
_result = {
|
||||
|
@ -272,3 +272,38 @@ class HTTPActionTest(base.BaseTest):
|
||||
proxies=None,
|
||||
verify=None
|
||||
)
|
||||
|
||||
@mock.patch.object(requests, 'request')
|
||||
def test_http_action_none_encoding_not_empty_resp(self, mocked_method):
|
||||
action = std.HTTPAction(
|
||||
url=URL,
|
||||
method='GET',
|
||||
timeout=20,
|
||||
allow_redirects=True
|
||||
)
|
||||
|
||||
self.assertEqual(URL, action.url)
|
||||
|
||||
mocked_method.return_value = get_fake_response(
|
||||
content='content', code=200, encoding=None
|
||||
)
|
||||
mock_ctx = mock.Mock()
|
||||
result = action.run(mock_ctx)
|
||||
|
||||
self.assertEqual('content', result['content'])
|
||||
self.assertEqual(200, result['status'])
|
||||
self.assertIsNone(result['encoding'])
|
||||
|
||||
mocked_method.assert_called_with(
|
||||
'GET',
|
||||
URL,
|
||||
headers=None,
|
||||
cookies=None,
|
||||
params=None,
|
||||
data=None,
|
||||
timeout=20,
|
||||
auth=None,
|
||||
allow_redirects=True,
|
||||
proxies=None,
|
||||
verify=None
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user