Compare commits

..

1 Commits

Author SHA1 Message Date
Serghei Mihai b4a00ae80e wscalls: unflatten payload when calling webservice (#66916)
gitea/wcs/pipeline/head This commit looks good Details
2024-03-26 22:18:18 +01:00
2 changed files with 4 additions and 4 deletions

View File

@ -594,6 +594,7 @@ def test_webservice_with_unflattened_payload_keys(http_requests, pub):
item.post_data = {
'foo/0': 'first',
'foo/1': 'second',
'foo/2': '{{ form_name }}',
'bar': 'example',
'form//name': '{{ form_name }}',
}
@ -602,7 +603,7 @@ def test_webservice_with_unflattened_payload_keys(http_requests, pub):
assert http_requests.get_last('url') == 'http://remote.example.net/'
assert http_requests.get_last('method') == 'POST'
payload = json.loads(http_requests.get_last('body'))
assert payload == {'foo': ['first', 'second'], 'bar': 'example', 'form/name': 'baz'}
assert payload == {'foo': ['first', 'second', 'baz'], 'bar': 'example', 'form/name': 'baz'}
assert http_requests.count() == 1
http_requests.empty()

View File

@ -66,8 +66,6 @@ def unflatten_keys(d):
if not isinstance(d, dict) or not d: # unflattening an empty dict has no sense
return d
# ok d is a dict
def split_key(key):
def map_key(x):
if misc.is_ascii_digit(x):
@ -234,7 +232,7 @@ def call_webservice(
if method in ('PATCH', 'PUT', 'POST', 'DELETE') and post_data:
payload = {}
with get_publisher().complex_data():
for key, value in unflatten_keys(post_data).items():
for key, value in post_data.items():
try:
payload[key] = WorkflowStatusItem.compute(value, allow_complex=True, raises=True)
except Exception as e:
@ -242,6 +240,7 @@ def call_webservice(
else:
if payload[key]:
payload[key] = get_publisher().get_cached_complex_data(payload[key])
payload = unflatten_keys(payload)
# if formdata has to be sent, it's the payload. If post_data exists,
# it's added in formdata['extra']