Skip to content

Commit

Permalink
[wip] multipart result tests - add content-disposition and content-lo…
Browse files Browse the repository at this point in the history
…cation headers
  • Loading branch information
fmigneault committed Sep 28, 2024
1 parent fc75d93 commit d050cd3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ outputs:
output_data:
type: string
outputBinding:
# note: since no file is associated for literal type, a link representation from it should use 'output_data.txt'
outputEval: $(inputs.message)
output_text:
type: File
outputBinding:
# note: purposely use a different name than 'output_text' to validate the resulting path uses this one
glob: result.txt
format: "iana:text/plain"
output_json:
type: File
outputBinding:
# note: purposely use a different name than 'output_json' to validate the resulting path uses this one
glob: result.json
format: "iana:application/json"
$namespaces:
Expand Down
37 changes: 26 additions & 11 deletions tests/functional/test_wps_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -3983,6 +3983,7 @@ def test_execute_single_output_multipart_accept_data(self):
results_body = inspect.cleandoc(f"""
--{boundary}
Content-Type: {ContentType.APP_JSON}
Content-Location: {out_url}/{job_id}/output_json/result.json
Content-ID: <output_json@{job_id}>
{output_json}
Expand Down Expand Up @@ -4199,23 +4200,28 @@ def test_execute_multi_output_multipart_accept(self, multipart_header):
data=exec_content, headers=exec_headers, only_local=True)
assert resp.status_code == 200, f"Failed with: [{resp.status_code}]\nReason:\n{resp.json}"

# request status instead of results since not expecting 'document' JSON in this case
status_url = resp.json["location"]
status = self.monitor_job(status_url, return_status=True)
assert status["status"] == Status.SUCCEEDED

job_id = status["jobID"]
# rely on location that should be provided to find the job ID
results_url = get_header("Content-Location", resp.headers)
assert results_url, (
"Content-Location should have been provided in"
"results response pointing at where they can be found."
)
job_id = results_url.rsplit("/results")[0].rsplit("/jobs/")[-1]
assert is_uuid(job_id), f"Failed to retrieve the job ID: [{job_id}] is not a UUID"
out_url = get_wps_output_url(self.settings)

results = self.app.get(f"/jobs/{job_id}/results")
boundary = parse_kvp(results.headers["Content-Type"])["boundary"][0]
results_body = inspect.cleandoc(f"""
--{boundary}
Content-Disposition: attachment; name="output_data"
Content-Type: {ContentType.TEXT_PLAIN}
Content-ID: <output_data@{job_id}>
Content-Length: 4
test
--{boundary}
Content-Disposition: attachment; name="output_json"; filename="result.json"
Content-Type: {ContentType.APP_JSON}
Content-ID: <output_json@{job_id}>
Content-Length: 0
Expand Down Expand Up @@ -4356,14 +4362,14 @@ def test_execute_multi_output_prefer_header_return_representation(self):
output_json = json.dumps({"data": "test"}, separators=(",", ":"))
results_body = inspect.cleandoc(f"""
--{boundary}
Content-Disposition: attachment; filename="output_data.txt" name="output_data"
Content-Disposition: attachment; filename="output_data.txt"; name="output_data"
Content-Type: {ContentType.TEXT_PLAIN}
Content-ID: <output_data@{job_id}>
Content-Length: 4
test
--{boundary}
Content-Disposition: attachment; filename="result.json" name="output_json"
Content-Disposition: attachment; name="output_json"; filename="result.json"
Content-Type: {ContentType.APP_JSON}
Content-Location: {out_url}/{job_id}/output_json/result.json
Content-ID: <output_json@{job_id}>
Expand Down Expand Up @@ -4425,13 +4431,16 @@ def test_execute_multi_output_response_raw_value(self):
output_json = json.dumps({"data": "test"}, separators=(",", ":"))
results_body = inspect.cleandoc(f"""
--{boundary}
Content-Disposition: attachment; name="output_data"
Content-Type: {ContentType.TEXT_PLAIN}
Content-ID: <output_data@{job_id}>
Content-Length: 4
test
--{boundary}
Content-Disposition: attachment; name="output_json"; filename="result.json"
Content-Type: {ContentType.APP_JSON}
Content-Location: {out_url}/{job_id}/output_json/result.json
Content-ID: <output_json@{job_id}>
Content-Length: 16
Expand Down Expand Up @@ -4489,15 +4498,17 @@ def test_execute_multi_output_response_raw_reference(self):
boundary = parse_kvp(results.headers["Content-Type"])["boundary"][0]
results_body = inspect.cleandoc(f"""
--{boundary}
Content-Disposition: attachment; name="output_data" filename="output_data.txt"
Content-Type: {ContentType.TEXT_PLAIN}
Content-Location: {out_url}/{job_id}/output_data/output_data.txt
Content-ID: <output_data@{job_id}>
Content-Length: 0
Content-Location: {out_url}/{job_id}/output_data/result.txt
--{boundary}
Content-Disposition: attachment; name="output_json"; filename="result.json"
Content-Type: {ContentType.APP_JSON}
Content-Location: {out_url}/{job_id}/output_json/result.json
Content-ID: <output_json@{job_id}>
Content-Length: 0
Content-Location: {out_url}/{job_id}/output_json/result.json
--{boundary}--
""").replace("\n", "\r\n")
results_text = self.remove_result_multipart_variable(results.text)
Expand Down Expand Up @@ -4554,18 +4565,22 @@ def test_execute_multi_output_response_raw_mixed(self):
output_json = json.dumps({"data": "test"}, separators=(",", ":"))
results_body = inspect.cleandoc(f"""
--{boundary}
Content-Disposition: attachment; name="output_data"
Content-Type: {ContentType.TEXT_PLAIN}
Content-ID: <output_data@{job_id}>
Content-Length: 4
test
--{boundary}
Content-Disposition: attachment; name="output_text"; filename="result.txt"
Content-Type: {ContentType.TEXT_PLAIN}
Content-Location: {out_url}/{job_id}/output_text/result.txt
Content-ID: <output_text@{job_id}>
Content-Length: 0
Content-Location: {out_url}/{job_id}/output_text/result.txt
--{boundary}
Content-Disposition: attachment; name="output_json"; filename="result.json"
Content-Type: {ContentType.APP_JSON}
Content-Location: {out_url}/{job_id}/output_json/result.json
Content-ID: <output_json@{job_id}>
Content-Length: 16
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ def _try_get_logs(self, status_url):
def fully_qualified_test_process_name(self, name=""):
extra_name = f"-{name}" if name else ""
class_name = fully_qualified_name(self)
test_name = f"{class_name}.{self._testMethodName}{extra_name}".replace(".", "-")
test_name = f"{class_name}.{self._testMethodName}{extra_name}"
test_name = test_name.replace(".", "-").replace("-_", "_").replace("_-", "-")
return test_name

@overload
Expand Down

0 comments on commit d050cd3

Please sign in to comment.