Skip to content

Commit e20d7d1

Browse files
authored
OAProc: do not pretty print JSON results when document=raw (#2212) (#2230)
1 parent e2c5b86 commit e20d7d1

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

pygeoapi/api/processes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,12 @@ def execute_process(api: API, request: APIRequest,
519519
else:
520520
http_status = HTTPStatus.OK
521521

522-
if mime_type == 'application/json' or requested_response == 'document':
523-
response2 = to_json(response, api.pretty_print)
522+
if mime_type == 'application/json':
523+
if requested_response == 'document':
524+
pretty_print_ = api.pretty_print
525+
else: # raw
526+
pretty_print_ = False
527+
response2 = to_json(response, pretty_print_)
524528
else:
525529
response2 = response
526530

tests/api/test_processes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ def test_execute_process(config, api_):
204204
},
205205
'response': 'document'
206206
}
207+
req_body_9 = {
208+
'inputs': {
209+
'name': 'Test document'
210+
}
211+
}
207212

208213
cleanup_jobs = set()
209214

@@ -364,6 +369,12 @@ def test_execute_process(config, api_):
364369
assert 'outputs' in response
365370
assert isinstance(response['outputs'], list)
366371

372+
req = mock_api_request(data=req_body_9)
373+
rsp_headers, code, response = execute_process(api_, req, 'hello-world')
374+
375+
response2 = '{"id":"echo","value":"Hello Test document!"}'
376+
assert response == response2
377+
367378
# Cleanup
368379
time.sleep(2) # Allow time for any outstanding async jobs
369380
for _, job_id in cleanup_jobs:

0 commit comments

Comments
 (0)