Skip to content

Commit

Permalink
Use test execution and artefact dto in rerun response
Browse files Browse the repository at this point in the history
  • Loading branch information
rpbritton committed Jan 14, 2025
1 parent b09fe2f commit 2474743
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 46 deletions.
36 changes: 5 additions & 31 deletions backend/test_observer/controllers/test_executions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
TestExecutionStatus,
TestResultStatus,
)
from test_observer.controllers.artefacts.models import TestExecutionDTO, ArtefactDTO


class _StartTestExecutionRequest(BaseModel):
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion backend/test_observer/controllers/test_executions/reruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
),
Expand Down
25 changes: 11 additions & 14 deletions backend/tests/controllers/test_executions/test_reruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

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

0 comments on commit 2474743

Please sign in to comment.