diff --git a/src/test_workflow/test_recorder/test_recorder.py b/src/test_workflow/test_recorder/test_recorder.py index 4edad516df..eca0f2c386 100644 --- a/src/test_workflow/test_recorder/test_recorder.py +++ b/src/test_workflow/test_recorder/test_recorder.py @@ -8,6 +8,7 @@ import logging import os import shutil +import urllib.parse from typing import Any import yaml @@ -49,9 +50,9 @@ def _create_base_folder_structure(self, component_name: str, component_test_conf return os.path.realpath(dest_directory) def _generate_std_files(self, stdout: str, stderr: str, output_path: str) -> None: - with open(os.path.join(output_path, "stdout.txt"), "w", encoding='utf-8') as stdout_file: + with open(os.path.join(output_path, "stdout.txt"), "w", encoding="utf-8") as stdout_file: stdout_file.write(stdout) - with open(os.path.join(output_path, "stderr.txt"), "w", encoding='utf-8') as stderr_file: + with open(os.path.join(output_path, "stderr.txt"), "w", encoding="utf-8") as stderr_file: stderr_file.write(stderr) def _generate_yml(self, test_result_data: TestResultData, output_path: str) -> str: @@ -66,14 +67,17 @@ def _generate_yml(self, test_result_data: TestResultData, output_path: str) -> s "component_name": test_result_data.component_name, "test_config": test_result_data.component_test_config, "test_result": "PASS" if (test_result_data.exit_code == 0) else "FAIL", - "test_result_files": test_result_file + "test_result_files": test_result_file, } - with open(os.path.join(output_path, "%s.yml" % test_result_data.component_name), "w", encoding='utf-8') as file: + with open(os.path.join(output_path, "%s.yml" % test_result_data.component_name), "w", encoding="utf-8") as file: yaml.dump(outcome, file) return os.path.realpath("%s.yml" % test_result_data.component_name) def _update_absolute_file_paths(self, files: list, base_path: str, relative_path: str) -> list: - return [os.path.join(base_path, relative_path, file) for file in files] + if base_path.startswith("https://"): + return [f"{base_path}/{relative_path}/{urllib.parse.quote_plus(file)}" for file in files] + else: + return [os.path.join(base_path, relative_path, file) for file in files] # get a list of files within directory with relative paths. def _get_list_files(self, dir: str) -> list: @@ -133,7 +137,7 @@ def save_test_result_data(self, test_result_data: TestResultData) -> None: class TestResultsLogs(LogRecorder): - __test__ = False # type:ignore + __test__ = False # type:ignore parent_class: TestRecorder def __init__(self, parent_class: TestRecorder) -> None: diff --git a/tests/tests_test_workflow/test_recorder/test_test_recorder.py b/tests/tests_test_workflow/test_recorder/test_test_recorder.py index 5b17f78b42..a4a1751585 100644 --- a/tests/tests_test_workflow/test_recorder/test_test_recorder.py +++ b/tests/tests_test_workflow/test_recorder/test_test_recorder.py @@ -96,8 +96,28 @@ def test_update_absolute_file_paths(self, mock_local_cluster_logs: Mock, mock_re "working-directory", "https://ci.opensearch.org/ci/dbc/integ-test/" ) - file_path = test_recorder._update_absolute_file_paths(["file1", "file2"], "working-directory", "sub-directory") - self.assertEqual(file_path, [os.path.join("working-directory", "sub-directory", "file1"), os.path.join("working-directory", "sub-directory", "file2")]) + file_path = test_recorder._update_absolute_file_paths( + ["file1", "file2 with spaces"], + "working-directory", + "sub-directory" + ) + self.assertEqual(file_path, [ + os.path.join("working-directory", "sub-directory", "file1"), + os.path.join("working-directory", "sub-directory", "file2 with spaces") + ]) + + @patch("test_workflow.test_recorder.test_recorder.TestResultsLogs") + @patch("test_workflow.test_recorder.test_recorder.RemoteClusterLogs") + @patch("test_workflow.test_recorder.test_recorder.LocalClusterLogs") + def test_update_absolute_file_paths_escaping(self, mock_local_cluster_logs: Mock, mock_remote_cluster_logs: Mock, mock_test_results_logs: Mock, *mock: Any) -> None: + test_recorder = TestRecorder( + "1234", + "integ-test", + "working-directory", + "https://ci.opensearch.org/ci/dbc/integ-test/" + ) + file_path = test_recorder._update_absolute_file_paths(["A long test case name"], "https://working-directory", "sub-directory") + self.assertEqual(file_path, ["https://working-directory/sub-directory/A+long+test+case+name"]) @patch("os.walk") @patch("test_workflow.test_recorder.test_recorder.TestResultsLogs")