From 24747433fd6c0ba29c77ff666b1d9d83409249c6 Mon Sep 17 00:00:00 2001 From: Ryan Britton Date: Tue, 14 Jan 2025 15:34:13 +0000 Subject: [PATCH] Use test execution and artefact dto in rerun response --- .../controllers/test_executions/models.py | 36 +++---------------- .../controllers/test_executions/reruns.py | 4 ++- .../test_executions/test_reruns.py | 25 ++++++------- 3 files changed, 19 insertions(+), 46 deletions(-) diff --git a/backend/test_observer/controllers/test_executions/models.py b/backend/test_observer/controllers/test_executions/models.py index 54e3975e..d50bccee 100644 --- a/backend/test_observer/controllers/test_executions/models.py +++ b/backend/test_observer/controllers/test_executions/models.py @@ -38,6 +38,7 @@ TestExecutionStatus, TestResultStatus, ) +from test_observer.controllers.artefacts.models import TestExecutionDTO, ArtefactDTO class _StartTestExecutionRequest(BaseModel): @@ -157,39 +158,12 @@ class PendingRerun(BaseModel): "test_execution", "artefact_build", "artefact", "family" ) ) - test_execution_status: TestExecutionStatus = Field( - validation_alias=AliasPath("test_execution", "status") + test_execution: TestExecutionDTO = Field( + validation_alias=AliasPath("test_execution") ) - artefact_name: str = Field( - validation_alias=AliasPath( - "test_execution", "artefact_build", "artefact", "name" - ) - ) - version: str = Field( - validation_alias=AliasPath( - "test_execution", "artefact_build", "artefact", "version" - ) - ) - revision: int | None = Field( - validation_alias=AliasPath("test_execution", "artefact_build", "revision") - ) - stage: StageName = Field( - validation_alias=AliasPath( - "test_execution", "artefact_build", "artefact", "stage" - ) - ) - track: str = Field( - validation_alias=AliasPath( - "test_execution", "artefact_build", "artefact", "track" - ) - ) - architecture: str = Field( - validation_alias=AliasPath("test_execution", "environment", "architecture") - ) - environment: str = Field( - validation_alias=AliasPath("test_execution", "environment", "name") + artefact: ArtefactDTO = Field( + validation_alias=AliasPath("test_execution", "artefact_build", "artefact") ) - test_plan: str = Field(validation_alias=AliasPath("test_execution", "test_plan")) class DeleteReruns(BaseModel): diff --git a/backend/test_observer/controllers/test_executions/reruns.py b/backend/test_observer/controllers/test_executions/reruns.py index dc7c0955..b6a6018a 100644 --- a/backend/test_observer/controllers/test_executions/reruns.py +++ b/backend/test_observer/controllers/test_executions/reruns.py @@ -8,6 +8,7 @@ ArtefactBuild, TestExecution, TestExecutionRerunRequest, + Artefact, ) from test_observer.data_access.repository import get_or_create from test_observer.data_access.setup import get_db @@ -54,7 +55,8 @@ def get_rerun_requests(db: Session = Depends(get_db)): select(TestExecutionRerunRequest).options( joinedload(TestExecutionRerunRequest.test_execution) .joinedload(TestExecution.artefact_build) - .joinedload(ArtefactBuild.artefact), + .joinedload(ArtefactBuild.artefact) + .joinedload(Artefact.assignee), joinedload(TestExecutionRerunRequest.test_execution).joinedload( TestExecution.environment ), diff --git a/backend/tests/controllers/test_executions/test_reruns.py b/backend/tests/controllers/test_executions/test_reruns.py index 4d4277bb..02bbceda 100644 --- a/backend/tests/controllers/test_executions/test_reruns.py +++ b/backend/tests/controllers/test_executions/test_reruns.py @@ -4,11 +4,13 @@ import pytest from fastapi.testclient import TestClient +from fastapi.encoders import jsonable_encoder from httpx import Response from test_observer.data_access.models import TestExecution from test_observer.data_access.models_enums import StageName from tests.data_generator import DataGenerator +from test_observer.controllers.artefacts.models import TestExecutionDTO, ArtefactDTO reruns_url = "/v1/test-executions/reruns" @@ -43,20 +45,15 @@ def delete_helper(data: Any) -> Response: # noqa: ANN401 def test_execution_to_pending_rerun(test_execution: TestExecution) -> dict: - return { - "test_execution_id": test_execution.id, - "ci_link": test_execution.ci_link, - "family": test_execution.artefact_build.artefact.family, - "test_execution_status": test_execution.status, - "artefact_name": test_execution.artefact_build.artefact.name, - "version": test_execution.artefact_build.artefact.version, - "revision": test_execution.artefact_build.revision, - "stage": test_execution.artefact_build.artefact.stage, - "track": test_execution.artefact_build.artefact.track, - "architecture": test_execution.environment.architecture, - "environment": test_execution.environment.name, - "test_plan": test_execution.test_plan, - } + return jsonable_encoder( + { + "test_execution_id": test_execution.id, + "ci_link": test_execution.ci_link, + "family": test_execution.artefact_build.artefact.family, + "test_execution": TestExecutionDTO.from_orm(test_execution), + "artefact": ArtefactDTO.from_orm(test_execution.artefact_build.artefact), + } + ) def test_post_no_data_returns_422(post: Post):