From 173ed54fde30d9e33735cb2dfbca3d94c6252e30 Mon Sep 17 00:00:00 2001 From: Antonio Melo Jr Date: Mon, 13 Nov 2023 15:51:49 -0300 Subject: [PATCH] Solving recent conflicts --- .../api_v1/endpoints/test_run_executions.py | 12 +++---- app/crud/crud_test_run_execution.py | 11 +------ app/schemas/__init__.py | 7 +++- app/schemas/test_run_execution.py | 2 ++ app/utils.py | 33 ++++++++++++++----- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/app/api/api_v1/endpoints/test_run_executions.py b/app/api/api_v1/endpoints/test_run_executions.py index 68c76208..33184224 100644 --- a/app/api/api_v1/endpoints/test_run_executions.py +++ b/app/api/api_v1/endpoints/test_run_executions.py @@ -82,8 +82,9 @@ def create_test_run_execution( """ Create new test run execution. """ + test_run_execution_in.selected_tests = selected_tests test_run_execution = crud.test_run_execution.create( - db=db, obj_in=test_run_execution_in, selected_tests=selected_tests + db=db, obj_in=test_run_execution_in ) return test_run_execution @@ -258,14 +259,13 @@ def repeat_test_run_execution( test_run_execution_in.description = execution_to_repeat.description test_run_execution_in.project_id = execution_to_repeat.project_id test_run_execution_in.operator_id = execution_to_repeat.operator_id + test_run_execution_in.selected_tests = selected_tests_from_execution( + execution_to_repeat + ) # TODO: Remove test_run_config completely from the project test_run_execution_in.test_run_config_id = None - selected_tests = selected_tests_from_execution(execution_to_repeat) - - return crud.test_run_execution.create( - db=db, obj_in=test_run_execution_in, selected_tests=selected_tests - ) + return crud.test_run_execution.create(db=db, obj_in=test_run_execution_in) @router.delete("/{id}", response_model=schemas.TestRunExecutionInDBBase) diff --git a/app/crud/crud_test_run_execution.py b/app/crud/crud_test_run_execution.py index 1a673a15..52965809 100644 --- a/app/crud/crud_test_run_execution.py +++ b/app/crud/crud_test_run_execution.py @@ -36,7 +36,6 @@ TestRunExecutionStats, TestRunExecutionWithStats, ) -from app.schemas.test_selection import SelectedTests from app.test_engine.test_script_manager import test_script_manager @@ -177,17 +176,9 @@ def create( test_run_execution = super().create(db=db, obj_in=obj_in) - # https://github.com/project-chip/certification-tool/issues/14 - # TODO: while we change the API. selected tests can come from two places: - # 1. Pass in directly - # 2. from the optional test_run_config - selected_tests: Optional[SelectedTests] = kwargs.get("selected_tests") - - selected_tests = SelectedTests() if not selected_tests else selected_tests - test_suites = ( test_script_manager.pending_test_suite_executions_for_selected_tests( - selected_tests + obj_in.selected_tests ) ) diff --git a/app/schemas/__init__.py b/app/schemas/__init__.py index 906d1ee3..77ce94ca 100644 --- a/app/schemas/__init__.py +++ b/app/schemas/__init__.py @@ -48,7 +48,12 @@ ) from .test_run_log_entry import TestRunLogEntry from .test_runner_status import TestRunnerStatus -from .test_selection import SelectedTests +from .test_selection import ( + SelectedCollection, + SelectedTestCase, + SelectedTests, + SelectedTestSuite, +) from .test_step_execution import TestStepExecution, TestStepExecutionToExport from .test_suite_execution import TestSuiteExecution, TestSuiteExecutionToExport from .test_suite_metadata import TestSuiteMetadata, TestSuiteMetadataBase diff --git a/app/schemas/test_run_execution.py b/app/schemas/test_run_execution.py index 88c423ff..817a89b9 100644 --- a/app/schemas/test_run_execution.py +++ b/app/schemas/test_run_execution.py @@ -19,6 +19,7 @@ from pydantic import BaseModel from app.models.test_enums import TestStateEnum +from app.schemas.test_selection import SelectedTests from .operator import Operator, OperatorToExport from .test_run_config import TestRunConfigToExport @@ -51,6 +52,7 @@ class TestRunExecutionBaseWithRelationships(TestRunExecutionBase): class TestRunExecutionCreate(TestRunExecutionBaseWithRelationships): # TODO(#124): Require project ID when UI supports project management. operator_id: Optional[int] + selected_tests: Optional[SelectedTests] # Properties shared by models stored in DB diff --git a/app/utils.py b/app/utils.py index b484d6a7..a2cf6702 100644 --- a/app/utils.py +++ b/app/utils.py @@ -28,7 +28,12 @@ from alembic.migration import MigrationContext from app.core.config import settings from app.models import TestRunExecution -from app.schemas import TestSelection +from app.schemas import ( + SelectedCollection, + SelectedTestCase, + SelectedTests, + SelectedTestSuite, +) def send_email( @@ -167,18 +172,30 @@ def get_db_revision() -> str: return current_rev -def selected_tests_from_execution(run: TestRunExecution) -> TestSelection: - selected_tests: TestSelection = {} +def selected_tests_from_execution(run: TestRunExecution) -> SelectedTests: + collections: list[SelectedCollection] = [] for suite in run.test_suite_executions: - selected_tests.setdefault(suite.collection_id, {}) - selected_tests[suite.collection_id][suite.public_id] = {} + index = -1 + + for i, c in enumerate(collections): + if c.public_id == suite.collection_id: + index = i + break + if index == -1: + collections.append(SelectedCollection(public_id=suite.collection_id)) + + collections[index].test_suites.append( + SelectedTestSuite(public_id=suite.public_id) + ) for case in suite.test_case_executions: - selected_tests[suite.collection_id][suite.public_id].update( - {case.public_id: 1} + collections[index].test_suites[-1].test_cases.append( + SelectedTestCase( + public_id=case.public_id, iterations=case.execution_index + ) ) - return selected_tests + return SelectedTests(collections=collections) def formated_datetime_now_str() -> str: