From d050cd3c942a4799c8f1da7a03b1f7186bfa345b Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Sat, 28 Sep 2024 03:08:34 -0400 Subject: [PATCH] =?UTF-8?q?[wip]=C2=A0multipart=20result=20tests=20-=20add?= =?UTF-8?q?=20content-disposition=20and=20content-location=20headers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EchoResultsTester/package.cwl | 3 ++ tests/functional/test_wps_package.py | 37 +++++++++++++------ tests/functional/utils.py | 3 +- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/tests/functional/application-packages/EchoResultsTester/package.cwl b/tests/functional/application-packages/EchoResultsTester/package.cwl index 08d6ace3c..37018f54f 100644 --- a/tests/functional/application-packages/EchoResultsTester/package.cwl +++ b/tests/functional/application-packages/EchoResultsTester/package.cwl @@ -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: diff --git a/tests/functional/test_wps_package.py b/tests/functional/test_wps_package.py index d047cec16..7b791cedb 100644 --- a/tests/functional/test_wps_package.py +++ b/tests/functional/test_wps_package.py @@ -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} @@ -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: Content-Length: 4 test --{boundary} + Content-Disposition: attachment; name="output_json"; filename="result.json" Content-Type: {ContentType.APP_JSON} Content-ID: Content-Length: 0 @@ -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: 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: @@ -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: 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: Content-Length: 16 @@ -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: 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: 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) @@ -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: 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: 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: Content-Length: 16 diff --git a/tests/functional/utils.py b/tests/functional/utils.py index dbdfe31bb..21712a836 100644 --- a/tests/functional/utils.py +++ b/tests/functional/utils.py @@ -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