Merge "Add json param to HTTPAction"
This commit is contained in:
commit
da93da4ac1
@ -16,7 +16,7 @@
|
||||
from email import header
|
||||
from email.mime import multipart
|
||||
from email.mime import text
|
||||
import json
|
||||
import json as json_lib
|
||||
import smtplib
|
||||
import time
|
||||
|
||||
@ -131,6 +131,8 @@ class HTTPAction(actions.Action):
|
||||
query string for the HTTP request.
|
||||
:param body: (optional) Dictionary, bytes, or file-like object to send
|
||||
in the body of the HTTP request.
|
||||
:param json: (optional) A JSON serializable Python object to send
|
||||
in the body of the HTTP request.
|
||||
:param headers: (optional) Dictionary of HTTP Headers to send with
|
||||
the HTTP request.
|
||||
:param cookies: (optional) Dict or CookieJar object to send with
|
||||
@ -152,6 +154,7 @@ class HTTPAction(actions.Action):
|
||||
method="GET",
|
||||
params=None,
|
||||
body=None,
|
||||
json=None,
|
||||
headers=None,
|
||||
cookies=None,
|
||||
auth=None,
|
||||
@ -171,10 +174,16 @@ class HTTPAction(actions.Action):
|
||||
if isinstance(val, (six.integer_types, float)):
|
||||
headers[key] = str(val)
|
||||
|
||||
if body and json:
|
||||
raise exc.ActionException(
|
||||
"Only one of the parameters 'json' and 'body' can be passed"
|
||||
)
|
||||
|
||||
self.url = url
|
||||
self.method = method
|
||||
self.params = params
|
||||
self.body = json.dumps(body) if isinstance(body, dict) else body
|
||||
self.body = json_lib.dumps(body) if isinstance(body, dict) else body
|
||||
self.json = json
|
||||
self.headers = headers
|
||||
self.cookies = cookies
|
||||
self.timeout = timeout
|
||||
@ -185,13 +194,14 @@ class HTTPAction(actions.Action):
|
||||
def run(self, context):
|
||||
LOG.info(
|
||||
"Running HTTP action "
|
||||
"[url=%s, method=%s, params=%s, body=%s, headers=%s,"
|
||||
" cookies=%s, auth=%s, timeout=%s, allow_redirects=%s,"
|
||||
" proxies=%s, verify=%s]",
|
||||
"[url=%s, method=%s, params=%s, body=%s, json=%s,"
|
||||
" headers=%s, cookies=%s, auth=%s, timeout=%s,"
|
||||
" allow_redirects=%s, proxies=%s, verify=%s]",
|
||||
self.url,
|
||||
self.method,
|
||||
self.params,
|
||||
self.body,
|
||||
self.json,
|
||||
self.headers,
|
||||
self.cookies,
|
||||
self.auth,
|
||||
@ -213,6 +223,7 @@ class HTTPAction(actions.Action):
|
||||
self.url,
|
||||
params=self.params,
|
||||
data=self.body,
|
||||
json=self.json,
|
||||
headers=self.headers,
|
||||
cookies=self.cookies,
|
||||
auth=self.auth,
|
||||
@ -445,7 +456,7 @@ class SSHAction(actions.Action):
|
||||
return raise_exc(parent_exc=e)
|
||||
|
||||
def test(self, context):
|
||||
return json.dumps(self.params)
|
||||
return json_lib.dumps(self.params)
|
||||
|
||||
|
||||
class SSHProxiedAction(SSHAction):
|
||||
|
@ -87,6 +87,7 @@ class HTTPActionTest(base.BaseTest):
|
||||
'POST',
|
||||
URL,
|
||||
data=DATA_STR,
|
||||
json=None,
|
||||
headers=None,
|
||||
cookies=None,
|
||||
params=None,
|
||||
|
@ -95,6 +95,7 @@ class MistralHTTPActionTest(base.BaseTest):
|
||||
'POST',
|
||||
URL,
|
||||
data=DATA_STR,
|
||||
json=None,
|
||||
headers=headers,
|
||||
cookies=None,
|
||||
params=None,
|
||||
|
@ -121,6 +121,7 @@ class ActionDefaultTest(base.EngineTestCase):
|
||||
'https://api.library.org/books',
|
||||
params=None,
|
||||
data=None,
|
||||
json=None,
|
||||
headers=None,
|
||||
cookies=None,
|
||||
allow_redirects=None,
|
||||
@ -151,7 +152,7 @@ class ActionDefaultTest(base.EngineTestCase):
|
||||
|
||||
requests.request.assert_called_with(
|
||||
'GET', 'https://api.library.org/books',
|
||||
params=None, data=None, headers=None, cookies=None,
|
||||
params=None, data=None, json=None, headers=None, cookies=None,
|
||||
allow_redirects=None, proxies=None, verify=None,
|
||||
auth=EXPECTED_ENV_AUTH,
|
||||
timeout=60
|
||||
@ -188,7 +189,7 @@ class ActionDefaultTest(base.EngineTestCase):
|
||||
self._assert_single_item(wf_ex.task_executions, name='task1')
|
||||
|
||||
calls = [mock.call('GET', url, params=None, data=None,
|
||||
headers=None, cookies=None,
|
||||
json=None, headers=None, cookies=None,
|
||||
allow_redirects=None, proxies=None,
|
||||
auth=EXPECTED_ENV_AUTH, verify=None,
|
||||
timeout=ENV['__actions']['std.http']['timeout'])
|
||||
@ -227,7 +228,7 @@ class ActionDefaultTest(base.EngineTestCase):
|
||||
self._assert_single_item(wf_ex.task_executions, name='task1')
|
||||
|
||||
calls = [mock.call('GET', url, params=None, data=None,
|
||||
headers=None, cookies=None,
|
||||
json=None, headers=None, cookies=None,
|
||||
allow_redirects=None, proxies=None,
|
||||
auth=EXPECTED_ENV_AUTH, verify=None,
|
||||
timeout=60)
|
||||
|
@ -23,7 +23,7 @@ class ActionManagerTest(base.DbTestCase):
|
||||
|
||||
http_action_input = (
|
||||
'url, method="GET", params=null, body=null, '
|
||||
'headers=null, cookies=null, auth=null, '
|
||||
'json=null, headers=null, cookies=null, auth=null, '
|
||||
'timeout=null, allow_redirects=null, '
|
||||
'proxies=null, verify=null'
|
||||
)
|
||||
|
@ -36,7 +36,7 @@ class InspectUtilsTest(base.BaseTest):
|
||||
|
||||
http_action_params = (
|
||||
'url, method="GET", params=null, body=null, '
|
||||
'headers=null, cookies=null, auth=null, '
|
||||
'json=null, headers=null, cookies=null, auth=null, '
|
||||
'timeout=null, allow_redirects=null, '
|
||||
'proxies=null, verify=null'
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user