From d5fabc8b5888f14a6e10dc06ed09806a157e5827 Mon Sep 17 00:00:00 2001 From: Alastair Lyall Date: Tue, 6 Aug 2024 16:10:45 +0200 Subject: [PATCH] feat(cli): upload test files from spec automatically (#724) --- reana_client/cli/files.py | 3 +++ tests/test_cli_files.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/reana_client/cli/files.py b/reana_client/cli/files.py index 50ff6e57..fcb5cbd3 100644 --- a/reana_client/cli/files.py +++ b/reana_client/cli/files.py @@ -340,6 +340,9 @@ def upload_files( # noqa: C901 ) sys.exit(1) filenames.append(os.path.join(os.getcwd(), f)) + if reana_spec.get("tests"): + for f in reana_spec["tests"].get("files") or []: + filenames.append(os.path.join(os.getcwd(), f)) # collect all files in input.directories files_from_directories = [] diff --git a/tests/test_cli_files.py b/tests/test_cli_files.py index 8e22e8ab..fbb182a7 100644 --- a/tests/test_cli_files.py +++ b/tests/test_cli_files.py @@ -240,6 +240,35 @@ def test_upload_file(create_yaml_workflow_schema): assert message in result.output +def test_upload_file_with_test_files_from_spec( + get_workflow_specification_with_directory, +): + """Test upload file with test files from the specification, not from the command line.""" + reana_token = "000000" + file = "upload-this-test.feature" + env = {"REANA_SERVER_URL": "http://localhost"} + runner = CliRunner(env=env) + + with patch( + "reana_client.api.client.get_workflow_specification" + ) as mock_specification, patch("reana_client.api.client.requests.post"): + with runner.isolated_filesystem(): + with open(file, "w") as f: + f.write("Scenario: Test scenario") + + get_workflow_specification_with_directory["specification"]["tests"] = { + "files": [file] + } + mock_specification.return_value = get_workflow_specification_with_directory + result = runner.invoke( + cli, ["upload", "-t", reana_token, "--workflow", "test-workflow.1"] + ) + assert result.exit_code == 0 + assert ( + "upload-this-test.feature was successfully uploaded." in result.output + ) + + def test_upload_file_respect_gitignore( get_workflow_specification_with_directory, ):