From 433db865fcc97b25c52fc43322e869a1119dfe26 Mon Sep 17 00:00:00 2001 From: Lakshya Garg Date: Fri, 17 Feb 2023 22:07:01 +0530 Subject: [PATCH] feat: add semantic versioning (#28) --- compliance_suite/cli.py | 8 +++----- compliance_suite/constants/constants.py | 7 ------- compliance_suite/functions/client.py | 3 +++ compliance_suite/test_runner.py | 7 ++----- docs/utility.md | 20 +++++++++---------- tests/cancel_task.yml | 2 ++ tests/cancel_task_functional.yml | 2 ++ tests/create_task.yml | 2 ++ tests/create_task_functional.yml | 2 ++ tests/get_task_basic.yml | 2 ++ tests/get_task_full.yml | 2 ++ tests/get_task_minimal.yml | 2 ++ tests/list_tasks_basic.yml | 2 ++ tests/list_tasks_full.yml | 2 ++ tests/list_tasks_minimal.yml | 2 ++ tests/service_info.yml | 2 ++ tests/template/test_template.yml | 2 ++ tests/template/test_template_schema.json | 8 ++++++++ .../data/run_job_tests/fail_service_info.yml | 3 ++- unittests/data/run_job_tests/invalid_yaml.yml | 2 ++ unittests/data/run_job_tests/skip_01.yml | 2 ++ unittests/data/run_job_tests/success_01.yml | 2 ++ unittests/data/tests/wrong_schema_yaml.yml | 2 ++ unittests/test_cli.py | 14 ++++++++++--- 24 files changed, 71 insertions(+), 31 deletions(-) diff --git a/compliance_suite/cli.py b/compliance_suite/cli.py index 4cd7eab..da451d0 100644 --- a/compliance_suite/cli.py +++ b/compliance_suite/cli.py @@ -20,7 +20,7 @@ def main() -> None: @main.command(help='Run TES compliance tests against the servers') @click.option('--server', '-s', help='server URL on which the compliance tests are run. Format - https:///') -@click.option('--version', '-v', help='TES version. Example - "v1.0"') +@click.option('--version', '-v', help='TES version. Example - "1.0.0"') @click.option('--tag', '-t', multiple=True, help='Tag', default=['All']) @click.option('--output_path', '-o', help='path to output the JSON report') @click.option('--serve', default=False, is_flag=True, help='spin up a server') @@ -38,8 +38,7 @@ def report(server: str, Args: server (str): The server URL on which the compliance suite will be run. Format - https:/// - version (str): The compliance suite will be run against this TES version. - Default - Latest version. Example - "v1.0" + version (str): The compliance suite will be run against this TES version. Example - "1.0.0" tag (List[str]): The list of the tags for which the compliance suite will be run. Default - All output_path (str): The output path to store the JSON compliance report serve (bool): If true, runs a local server and displays the JSON report in webview @@ -51,8 +50,7 @@ def report(server: str, raise Exception("No server provided. Please provide a server URL.") if version is None: - logger.info("No version provided. Latest version is used as default value.") - version = "v1.0" # Hardcode the latest version here. TODO - Future versions + raise Exception("No version provided. Please provide a version.") tag = [val.lower() for val in tag] # Convert the tags into lowercase to allow case-insensitive tags logger.info(f"Input tag is - {tag}") diff --git a/compliance_suite/constants/constants.py b/compliance_suite/constants/constants.py index d463f01..af11a21 100644 --- a/compliance_suite/constants/constants.py +++ b/compliance_suite/constants/constants.py @@ -13,13 +13,6 @@ TesTaskMinimal, ) -# YAML Constants - -VERSION_INFO = { - 'v1.0': 'v1', - 'v1.1': 'v1' -} - # Utility Constants LOGGING_LEVEL = { diff --git a/compliance_suite/functions/client.py b/compliance_suite/functions/client.py index b9be373..f2cee69 100644 --- a/compliance_suite/functions/client.py +++ b/compliance_suite/functions/client.py @@ -59,6 +59,7 @@ def send_request( for key in uri_params.keys(): endpoint = endpoint.replace(f"{{{key}}}", uri_params[key]) + version = "v" + version.split(".")[0] # Convert SemVer into Major API version base_url: str = str(server) + version + endpoint request_headers: dict = REQUEST_HEADERS[service] response = None @@ -137,7 +138,9 @@ def poll_request( for key in uri_params.keys(): endpoint = endpoint.replace(f"{{{key}}}", uri_params[key]) + self.check_cancel = check_cancel_val + version = "v" + version.split(".")[0] # Convert SemVer into Major API version base_url: str = str(server) + version + endpoint request_headers: dict = REQUEST_HEADERS[service] diff --git a/compliance_suite/test_runner.py b/compliance_suite/test_runner.py index 1540c27..eb1b523 100644 --- a/compliance_suite/test_runner.py +++ b/compliance_suite/test_runner.py @@ -15,10 +15,7 @@ from pydantic import ValidationError from requests.models import Response -from compliance_suite.constants.constants import ( - ENDPOINT_TO_MODEL, - VERSION_INFO, -) +from compliance_suite.constants.constants import ENDPOINT_TO_MODEL from compliance_suite.exceptions.compliance_exception import ( JobValidationException, TestFailureException @@ -43,7 +40,7 @@ def __init__(self, service: str, server: str, version: str): self.service: str = service self.server: str = server - self.version: str = VERSION_INFO[version] + self.version: str = version self.job_data: Any = None self.auxiliary_space: Dict = {} # Dictionary to store the sub-job results self.report_test: Any = None # Test object to store the result diff --git a/docs/utility.md b/docs/utility.md index 2705035..f81859f 100644 --- a/docs/utility.md +++ b/docs/utility.md @@ -67,15 +67,15 @@ env_vars: The following command line parameters can be run: -| Parameter | Short Name | Required |Description | -|---------------|------------|----------|---| -| --server | -s | Yes |The server URL on which the compliance suite will be run. Format - `https:///`| -| --version | -v | No |The compliance suite will be run against this TES version. Default - Latest version. Example - `"v1.0"`| -| --tag | -t | No |Tag for which the compliance suite will be run. It is case insensitive. Default - `"all"` | -| --output_path | -o | No |The output path to store the JSON compliance report | -| --serve | NA | No |If set, runs a local server and displays the JSON report in HTML web page | -| --port | NA | No |The port at which the local server is run. Default - 15800 | -| --uptime | -u | No |The local server duration in seconds. Default - 3600 seconds | +| Parameter | Short Name | Required | Description | +|---------------|------------|----------|-------------------------------------------------------------------------------------------------| +| --server | -s | Yes | The server URL on which the compliance suite will be run. Format - `https:///` | +| --version | -v | Yes | The compliance suite will be run against this TES version. Format - SemVer. Example - `"1.0.0"` | +| --tag | -t | No | Tag for which the compliance suite will be run. It is case insensitive. Default - `"all"` | +| --output_path | -o | No | The output path to store the JSON compliance report | +| --serve | NA | No | If set, runs a local server and displays the JSON report in HTML web page | +| --port | NA | No | The port at which the local server is run. Default - 15800 | +| --uptime | -u | No | The local server duration in seconds. Default - 3600 seconds | Multiple tags can be set by providing multiple `--tag` or `-t` parameter. ```base @@ -87,7 +87,7 @@ tes-compliance-suite report --server "https://test.com/" --tag "cancel task" --t 1. Some examples for command line are: ```base tes-compliance-suite report --server "https://test.com/" --tag "all" -tes-compliance-suite report --server "https://test.com/" --version "v1.0" --tag "all" --output_path "path/to/store" --serve --port 9090 --uptime 1000 +tes-compliance-suite report --server "https://test.com/" --version "1.0.0" --tag "all" --output_path "path/to/store" --serve --port 9090 --uptime 1000 ``` 2. If the HOME python version is different than 3.8, then absolute path with reference to 3.8 should be used. diff --git a/tests/cancel_task.yml b/tests/cancel_task.yml index ebffa26..c6e483d 100644 --- a/tests/cancel_task.yml +++ b/tests/cancel_task.yml @@ -1,6 +1,8 @@ name: Cancel Tes Task Job description: Job to cancel a TES Task service: TES +versions: + - 1.0.0 tags: - logical - cancel task diff --git a/tests/cancel_task_functional.yml b/tests/cancel_task_functional.yml index 0bdff13..e2fc14b 100644 --- a/tests/cancel_task_functional.yml +++ b/tests/cancel_task_functional.yml @@ -1,6 +1,8 @@ name: Cancel Tes Task Job description: Job to cancel a TES Task service: TES +versions: + - 1.0.0 tags: - functional - cancel task diff --git a/tests/create_task.yml b/tests/create_task.yml index b49e412..55f1b0b 100644 --- a/tests/create_task.yml +++ b/tests/create_task.yml @@ -1,6 +1,8 @@ name: Create Tes Task Job description: Job to create a new TES Task service: TES +versions: + - 1.0.0 tags: - logical - create task diff --git a/tests/create_task_functional.yml b/tests/create_task_functional.yml index 5c62289..0eb240b 100644 --- a/tests/create_task_functional.yml +++ b/tests/create_task_functional.yml @@ -1,6 +1,8 @@ name: Create Tes Task Functional Job description: Job to create a new TES Task and test functionality service: TES +versions: + - 1.0.0 tags: - functional - create task diff --git a/tests/get_task_basic.yml b/tests/get_task_basic.yml index d92cdad..1e0702a 100644 --- a/tests/get_task_basic.yml +++ b/tests/get_task_basic.yml @@ -1,6 +1,8 @@ name: Get Basic Task Job description: Job to retrieve the Basic view of TES Task service: TES +versions: + - 1.0.0 tags: - logical - get task diff --git a/tests/get_task_full.yml b/tests/get_task_full.yml index 608d899..11595e7 100644 --- a/tests/get_task_full.yml +++ b/tests/get_task_full.yml @@ -1,6 +1,8 @@ name: Get Full Task Job description: Job to retrieve the Full view of TES Task service: TES +versions: + - 1.0.0 tags: - logical - get task diff --git a/tests/get_task_minimal.yml b/tests/get_task_minimal.yml index 2cde3d3..f4baa41 100644 --- a/tests/get_task_minimal.yml +++ b/tests/get_task_minimal.yml @@ -1,6 +1,8 @@ name: Get Minimal Task Job description: Job to retrieve the Minimal view of TES Task service: TES +versions: + - 1.0.0 tags: - logical - get task diff --git a/tests/list_tasks_basic.yml b/tests/list_tasks_basic.yml index edcb801..356cd68 100644 --- a/tests/list_tasks_basic.yml +++ b/tests/list_tasks_basic.yml @@ -1,6 +1,8 @@ name: List Basic Tasks Job description: Job to retrieve the list of Basic view of TES tasks service: TES +versions: + - 1.0.0 tags: - logical - list tasks diff --git a/tests/list_tasks_full.yml b/tests/list_tasks_full.yml index 7aae8fe..75838a8 100644 --- a/tests/list_tasks_full.yml +++ b/tests/list_tasks_full.yml @@ -1,6 +1,8 @@ name: List Full Tasks Job description: Job to retrieve the list of Full view of TES tasks service: TES +versions: + - 1.0.0 tags: - logical - list tasks diff --git a/tests/list_tasks_minimal.yml b/tests/list_tasks_minimal.yml index 68a233d..50bb143 100644 --- a/tests/list_tasks_minimal.yml +++ b/tests/list_tasks_minimal.yml @@ -1,6 +1,8 @@ name: List Minimal Tasks Job description: Job to retrieve the list of Minimal view of TES tasks service: TES +versions: + - 1.0.0 tags: - logical - list tasks diff --git a/tests/service_info.yml b/tests/service_info.yml index 69ab378..e9ecdee 100644 --- a/tests/service_info.yml +++ b/tests/service_info.yml @@ -1,6 +1,8 @@ name: Service Info Job description: Job to retrieve the service info service: TES +versions: + - 1.0.0 tags: - logical - service info diff --git a/tests/template/test_template.yml b/tests/template/test_template.yml index bdc93a7..9465493 100644 --- a/tests/template/test_template.yml +++ b/tests/template/test_template.yml @@ -1,6 +1,8 @@ name: description: # Optional service: # enum - [TES] +versions: + - tags: - # Logical - No Polling needed, Functional - Polling needed. Always add 3 tags - Individual tag based on test name, TES endpoint tag and "All" tag jobs: diff --git a/tests/template/test_template_schema.json b/tests/template/test_template_schema.json index a66242f..17cacf3 100644 --- a/tests/template/test_template_schema.json +++ b/tests/template/test_template_schema.json @@ -18,6 +18,13 @@ "TES" ] }, + "versions": { + "type": "array", + "description": "The list of API versions against which the test file can be run", + "items": { + "type": "string" + } + }, "tags": { "type": "array", "description": "The list of tags which define the test file. Example. Logical - No Polling needed, Functional - Polling needed. Always add 3 tags - Individual tag based on test name, TES endpoint tag and All tag", @@ -123,6 +130,7 @@ "required": [ "name", "service", + "versions", "tags", "jobs" ] diff --git a/unittests/data/run_job_tests/fail_service_info.yml b/unittests/data/run_job_tests/fail_service_info.yml index 3a38c13..145528e 100644 --- a/unittests/data/run_job_tests/fail_service_info.yml +++ b/unittests/data/run_job_tests/fail_service_info.yml @@ -1,7 +1,8 @@ name: Service Info Job description: Job to retrieve the service info service: TES -#server: https://invalid-url +versions: + - 1.0.0 tags: - logical - service info diff --git a/unittests/data/run_job_tests/invalid_yaml.yml b/unittests/data/run_job_tests/invalid_yaml.yml index e45ece1..7601fa4 100644 --- a/unittests/data/run_job_tests/invalid_yaml.yml +++ b/unittests/data/run_job_tests/invalid_yaml.yml @@ -2,6 +2,8 @@ Invalid YAML name: Service Info Job description: Job to retrieve the service info service: TES +versions: + - 1.0.0 tags: - logical - service info diff --git a/unittests/data/run_job_tests/skip_01.yml b/unittests/data/run_job_tests/skip_01.yml index cc8acb5..e792cfc 100644 --- a/unittests/data/run_job_tests/skip_01.yml +++ b/unittests/data/run_job_tests/skip_01.yml @@ -1,6 +1,8 @@ name: Service Info Job description: Job to retrieve the service info service: TES +versions: + - 1.0.0 tags: - logical jobs: diff --git a/unittests/data/run_job_tests/success_01.yml b/unittests/data/run_job_tests/success_01.yml index 69ab378..e9ecdee 100644 --- a/unittests/data/run_job_tests/success_01.yml +++ b/unittests/data/run_job_tests/success_01.yml @@ -1,6 +1,8 @@ name: Service Info Job description: Job to retrieve the service info service: TES +versions: + - 1.0.0 tags: - logical - service info diff --git a/unittests/data/tests/wrong_schema_yaml.yml b/unittests/data/tests/wrong_schema_yaml.yml index 589a717..fe1b99d 100644 --- a/unittests/data/tests/wrong_schema_yaml.yml +++ b/unittests/data/tests/wrong_schema_yaml.yml @@ -1,5 +1,7 @@ description: Job to retrieve the service info service: TES +versions: + - 1.0.0 tags: - logical - service info diff --git a/unittests/test_cli.py b/unittests/test_cli.py index ec722a9..511002a 100644 --- a/unittests/test_cli.py +++ b/unittests/test_cli.py @@ -33,6 +33,13 @@ def test_report_no_server(self): result = runner.invoke(report, []) assert result.exit_code == 1 + def test_report_no_version(self): + """ asserts if the application raises Exception if no server is provided""" + + runner = CliRunner() + result = runner.invoke(report, ['--server', 'https://test.com/']) + assert result.exit_code == 1 + @patch.object(JobRunner, "generate_report") @patch.object(JobRunner, "run_jobs") def test_report_no_tag(self, mock_run_jobs, mock_generate_reports): @@ -42,7 +49,7 @@ def test_report_no_tag(self, mock_run_jobs, mock_generate_reports): mock_run_jobs.return_value = {} mock_generate_reports.return_value = '{"test": "test"}' runner = CliRunner() - result = runner.invoke(report, ['--server', 'https://test.com/']) + result = runner.invoke(report, ['--server', 'https://test.com/', '--version', '1.0.0']) assert result.exit_code == 0 @patch.object(ReportServer, 'serve_thread') @@ -56,6 +63,7 @@ def test_report(self, mock_run_jobs, mock_generate_reports, mock_report_server): mock_generate_reports.return_value = '{"test": "test"}' mock_report_server.return_value = MagicMock() runner = CliRunner() - result = runner.invoke(report, ['--server', 'https://test.com/', '--tag', 'All', '--output_path', - "path/to/output", '--serve', '--port', 9090, '--uptime', 1000]) + result = runner.invoke(report, ['--server', 'https://test.com/', '--version', '1.0.0', '--tag', 'All', + '--output_path', "path/to/output", '--serve', '--port', 9090, + '--uptime', 1000]) assert result.exit_code == 0