Skip to content

Commit

Permalink
Solving recent conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio-amjr committed Nov 13, 2023
1 parent 9126eed commit 173ed54
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
12 changes: 6 additions & 6 deletions app/api/api_v1/endpoints/test_run_executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
11 changes: 1 addition & 10 deletions app/crud/crud_test_run_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
TestRunExecutionStats,
TestRunExecutionWithStats,
)
from app.schemas.test_selection import SelectedTests
from app.test_engine.test_script_manager import test_script_manager


Expand Down Expand Up @@ -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

Check failure on line 181 in app/crud/crud_test_run_execution.py

View workflow job for this annotation

GitHub Actions / Mypy

app/crud/crud_test_run_execution.py#L181

Argument 1 to "pending_test_suite_executions_for_selected_tests" of "TestScriptManager" has incompatible type "Optional[SelectedTests]"; expected "SelectedTests" [arg-type]
)
)

Expand Down
7 changes: 6 additions & 1 deletion app/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions app/schemas/test_run_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
33 changes: 25 additions & 8 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 173ed54

Please sign in to comment.