Merge "cast to str for allowable types"
This commit is contained in:
commit
dccb3e8b06
@ -20,6 +20,7 @@ from email.mime import text
|
||||
|
||||
import json
|
||||
import requests
|
||||
import six
|
||||
import smtplib
|
||||
import time
|
||||
|
||||
@ -143,6 +144,11 @@ class HTTPAction(base.Action):
|
||||
else:
|
||||
self.auth = auth
|
||||
|
||||
if isinstance(headers, dict):
|
||||
for key, val in headers.items():
|
||||
if isinstance(val, (six.integer_types, float)):
|
||||
headers[key] = str(val)
|
||||
|
||||
self.url = url
|
||||
self.method = method
|
||||
self.params = params
|
||||
|
@ -162,3 +162,46 @@ class HTTPActionTest(base.BaseTest):
|
||||
proxies=None,
|
||||
verify=None
|
||||
)
|
||||
|
||||
@mock.patch.object(requests, 'request')
|
||||
def test_http_action_with_headers(self, mocked_method):
|
||||
mocked_method.return_value = get_success_fake_response()
|
||||
|
||||
headers = {'int_header': 33, 'bool_header': True,
|
||||
'float_header': 3.0, 'regular_header': 'teststring'}
|
||||
|
||||
safe_headers = {'int_header': '33', 'bool_header': 'True',
|
||||
'float_header': '3.0', 'regular_header': 'teststring'}
|
||||
|
||||
action = std.HTTPAction(
|
||||
url=URL,
|
||||
method='POST',
|
||||
body=DATA,
|
||||
headers=headers.copy(),
|
||||
)
|
||||
|
||||
data_str = json.dumps(DATA)
|
||||
|
||||
self.assertEqual(data_str, action.body)
|
||||
self.assertEqual(URL, action.url)
|
||||
|
||||
result = action.run()
|
||||
|
||||
self.assertIsInstance(result, dict)
|
||||
self.assertEqual(DATA, result['content'])
|
||||
self.assertIn('headers', result)
|
||||
self.assertEqual(200, result['status'])
|
||||
|
||||
mocked_method.assert_called_with(
|
||||
'POST',
|
||||
URL,
|
||||
data=data_str,
|
||||
headers=safe_headers,
|
||||
cookies=None,
|
||||
params=None,
|
||||
timeout=None,
|
||||
auth=None,
|
||||
allow_redirects=None,
|
||||
proxies=None,
|
||||
verify=None
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user