Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpRequest Allow callable params #255

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pypeman/contrib/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class HttpRequest(nodes.BaseNode):
:param verify: verify ssl. Default True.
:param params: get params in dict. List for multiple elements, ex :
{'param1': 'omega', param2: ['alpha', 'beta']}
The key can be a function that takes a msg as input param
:param client_cert: tuple with .crt and .key path
:param binary: bool, Get response content as bytes
:param send_as_json: bool, If the method is a PATCH/POST/PUT, send data as json
Expand Down Expand Up @@ -220,8 +221,11 @@ async def handle_request(self, msg):

get_params = None
if params:
params = params.copy()
get_params = []
for key, param in params.items():
if callable(param):
param = param(msg)
if isinstance(param, list):
for value in param:
get_params.append((key, value))
Expand Down
6 changes: 3 additions & 3 deletions pypeman/tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,11 @@ def test_httprequest_node(self):
('zeta', 'un'),
('zeta', 'deux'),
('zeta', 'trois'),
# ('omega', 'meta_params')
]
req_kwargs2['data'] = content1

args_headers = {'args_headers': 'args_headers'}
args_params = {'theta': ['uno', 'dos']}
args_params = {'theta': ['uno', 'dos'], 'omega': tstfct2}
http_node2 = nodes.HttpRequest(
url=url,
method='post',
Expand Down Expand Up @@ -474,6 +473,7 @@ def test_httprequest_node(self):
req_kwargs3['params'] = [
('theta', 'uno'),
('theta', 'dos'),
('omega', 'fctname'),
]
req_kwargs3['headers'] = args_headers
req_kwargs3['data'] = content1
Expand Down Expand Up @@ -524,7 +524,7 @@ def test_httprequest_node(self):
Test 3:
- post in node args,
- object BasicAuth for auth,
- list in dict params from args,
- list in dict params from args + callable str param,
- headers from args
- client_cert
"""
Expand Down
Loading