diff --git a/backend/test_observer/controllers/test_executions/models.py b/backend/test_observer/controllers/test_executions/models.py index 2000e2e9..0642378f 100644 --- a/backend/test_observer/controllers/test_executions/models.py +++ b/backend/test_observer/controllers/test_executions/models.py @@ -151,12 +151,19 @@ class RerunRequest(BaseModel): class PendingRerun(BaseModel): test_execution_id: int - ci_link: str = Field(validation_alias=AliasPath("test_execution", "ci_link")) + ci_link: str | None = Field(validation_alias=AliasPath("test_execution", "ci_link")) family: FamilyName = Field( validation_alias=AliasPath( "test_execution", "artefact_build", "artefact", "family" ) ) + test_execution_status: TestExecutionStatus = Field(validation_alias=AliasPath("test_execution", "status")) + 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")) + architecture: str = Field(validation_alias=AliasPath("test_execution", "environment", "architecture")) + environment: str = Field(validation_alias=AliasPath("test_execution", "environment", "name")) + 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 9c60e4e8..9d1f79c9 100644 --- a/backend/test_observer/controllers/test_executions/reruns.py +++ b/backend/test_observer/controllers/test_executions/reruns.py @@ -54,7 +54,9 @@ 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(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 400e4eee..367c3511 100644 --- a/backend/tests/controllers/test_executions/test_reruns.py +++ b/backend/tests/controllers/test_executions/test_reruns.py @@ -41,6 +41,20 @@ def delete_helper(data: Any) -> Response: # noqa: ANN401 Get: TypeAlias = Callable[[], Response] Delete: TypeAlias = Callable[[Any], Response] +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, + "architecture": test_execution.environment.architecture, + "environment": test_execution.environment.name, + "test_plan": test_execution.test_plan, + } + def test_post_no_data_returns_422(post: Post): assert post(None).status_code == 422 @@ -57,13 +71,7 @@ def test_valid_post(post: Post, test_execution: TestExecution): response = post({"test_execution_ids": [test_execution.id]}) assert response.status_code == 200 - assert response.json() == [ - { - "test_execution_id": test_execution.id, - "ci_link": test_execution.ci_link, - "family": test_execution.artefact_build.artefact.family, - } - ] + assert response.json() == [test_execution_to_pending_rerun(test_execution)] def test_post_with_valid_and_invalid_ids(post: Post, test_execution: TestExecution): @@ -83,13 +91,7 @@ def test_get_after_one_post(get: Get, post: Post, test_execution: TestExecution) post({"test_execution_ids": [test_execution.id]}) - assert get().json() == [ - { - "test_execution_id": test_execution.id, - "ci_link": test_execution.ci_link, - "family": test_execution.artefact_build.artefact.family, - } - ] + assert get().json() == [test_execution_to_pending_rerun(test_execution)] def test_get_after_two_identical_posts( @@ -100,13 +102,7 @@ def test_get_after_two_identical_posts( post({"test_execution_ids": [test_execution.id]}) post({"test_execution_ids": [test_execution.id]}) - assert get().json() == [ - { - "test_execution_id": test_execution.id, - "ci_link": test_execution.ci_link, - "family": test_execution.artefact_build.artefact.family, - } - ] + assert get().json() == [test_execution_to_pending_rerun(test_execution)] def test_get_after_two_different_posts( @@ -121,18 +117,7 @@ def test_get_after_two_different_posts( post({"test_execution_ids": [te1.id]}) post({"test_execution_ids": [te2.id]}) - assert get().json() == [ - { - "test_execution_id": te1.id, - "ci_link": te1.ci_link, - "family": te1.artefact_build.artefact.family, - }, - { - "test_execution_id": te2.id, - "ci_link": te2.ci_link, - "family": te2.artefact_build.artefact.family, - }, - ] + assert get().json() == [test_execution_to_pending_rerun(te1), test_execution_to_pending_rerun(te2)] def test_get_after_post_with_two_test_execution_ids( @@ -147,18 +132,7 @@ def test_get_after_post_with_two_test_execution_ids( post({"test_execution_ids": [te1.id, te2.id]}) - assert sorted(get().json(), key=itemgetter("test_execution_id")) == [ - { - "test_execution_id": te1.id, - "ci_link": te1.ci_link, - "family": te1.artefact_build.artefact.family, - }, - { - "test_execution_id": te2.id, - "ci_link": te2.ci_link, - "family": te2.artefact_build.artefact.family, - }, - ] + assert sorted(get().json(), key=itemgetter("test_execution_id")) == [test_execution_to_pending_rerun(te1), test_execution_to_pending_rerun(te2)] def test_post_delete_get(