-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move artefact builds controllers out of artefacts module
- Loading branch information
Showing
4 changed files
with
176 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from fastapi import APIRouter, Depends | ||
from sqlalchemy.orm import selectinload | ||
|
||
from test_observer.controllers.artefacts.artefact_retriever import ArtefactRetriever | ||
from test_observer.data_access.models import ( | ||
Artefact, | ||
ArtefactBuild, | ||
TestExecution, | ||
) | ||
|
||
from .models import ( | ||
ArtefactBuildDTO, | ||
) | ||
|
||
router = APIRouter(tags=["artefact-builds"]) | ||
|
||
|
||
@router.get("/{artefact_id}/builds", response_model=list[ArtefactBuildDTO]) | ||
def get_artefact_builds( | ||
artefact: Artefact = Depends( | ||
ArtefactRetriever( | ||
selectinload(Artefact.builds) | ||
.selectinload(ArtefactBuild.test_executions) | ||
.options( | ||
selectinload(TestExecution.environment), | ||
selectinload(TestExecution.rerun_request), | ||
) | ||
) | ||
), | ||
): | ||
"""Get latest artefact builds of an artefact together with their test executions""" | ||
for artefact_build in artefact.latest_builds: | ||
artefact_build.test_executions.sort( | ||
key=lambda test_execution: test_execution.environment.name | ||
) | ||
|
||
return artefact.latest_builds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
from tests.data_generator import DataGenerator | ||
|
||
|
||
def test_get_artefact_builds(test_client: TestClient, generator: DataGenerator): | ||
a = generator.gen_artefact("beta") | ||
ab = generator.gen_artefact_build(a) | ||
e = generator.gen_environment() | ||
te = generator.gen_test_execution(ab, e) | ||
|
||
response = test_client.get(f"/v1/artefacts/{a.id}/builds") | ||
|
||
assert response.status_code == 200 | ||
assert response.json() == [ | ||
{ | ||
"id": ab.id, | ||
"revision": ab.revision, | ||
"architecture": ab.architecture, | ||
"test_executions": [ | ||
{ | ||
"id": te.id, | ||
"ci_link": te.ci_link, | ||
"c3_link": te.c3_link, | ||
"status": te.status.value, | ||
"environment": { | ||
"id": e.id, | ||
"name": e.name, | ||
"architecture": e.architecture, | ||
}, | ||
"is_rerun_requested": False, | ||
} | ||
], | ||
} | ||
] | ||
|
||
|
||
def test_get_artefact_builds_sorts_test_executions_by_environment_name( | ||
test_client: TestClient, generator: DataGenerator | ||
): | ||
a = generator.gen_artefact("beta") | ||
ab = generator.gen_artefact_build(a) | ||
e2 = generator.gen_environment("e2") | ||
e1 = generator.gen_environment("e1") | ||
te2 = generator.gen_test_execution(ab, e2) | ||
te1 = generator.gen_test_execution(ab, e1) | ||
|
||
assert test_client.get(f"/v1/artefacts/{a.id}/builds").json() == [ | ||
{ | ||
"id": ab.id, | ||
"revision": ab.revision, | ||
"architecture": ab.architecture, | ||
"test_executions": [ | ||
{ | ||
"id": te1.id, | ||
"ci_link": te1.ci_link, | ||
"c3_link": te1.c3_link, | ||
"status": te1.status.value, | ||
"environment": { | ||
"id": e1.id, | ||
"name": e1.name, | ||
"architecture": e1.architecture, | ||
}, | ||
"is_rerun_requested": False, | ||
}, | ||
{ | ||
"id": te2.id, | ||
"ci_link": te2.ci_link, | ||
"c3_link": te2.c3_link, | ||
"status": te2.status.value, | ||
"environment": { | ||
"id": e2.id, | ||
"name": e2.name, | ||
"architecture": e2.architecture, | ||
}, | ||
"is_rerun_requested": False, | ||
}, | ||
], | ||
} | ||
] | ||
|
||
|
||
def test_get_artefact_builds_only_latest( | ||
test_client: TestClient, generator: DataGenerator | ||
): | ||
artefact = generator.gen_artefact("beta") | ||
generator.gen_artefact_build(artefact=artefact, revision=1) | ||
artefact_build2 = generator.gen_artefact_build(artefact=artefact, revision=2) | ||
|
||
response = test_client.get(f"/v1/artefacts/{artefact.id}/builds") | ||
|
||
assert response.status_code == 200 | ||
assert response.json() == [ | ||
{ | ||
"id": artefact_build2.id, | ||
"revision": artefact_build2.revision, | ||
"architecture": artefact_build2.architecture, | ||
"test_executions": [], | ||
} | ||
] | ||
|
||
|
||
def test_get_artefact_builds_with_rerun_requested( | ||
test_client: TestClient, generator: DataGenerator | ||
): | ||
a = generator.gen_artefact("beta") | ||
ab = generator.gen_artefact_build(a) | ||
e = generator.gen_environment() | ||
te = generator.gen_test_execution(ab, e) | ||
generator.gen_rerun_request(te) | ||
|
||
response = test_client.get(f"/v1/artefacts/{a.id}/builds") | ||
|
||
assert response.status_code == 200 | ||
assert response.json() == [ | ||
{ | ||
"id": ab.id, | ||
"revision": ab.revision, | ||
"architecture": ab.architecture, | ||
"test_executions": [ | ||
{ | ||
"id": te.id, | ||
"ci_link": te.ci_link, | ||
"c3_link": te.c3_link, | ||
"status": te.status.value, | ||
"environment": { | ||
"id": e.id, | ||
"name": e.name, | ||
"architecture": e.architecture, | ||
}, | ||
"is_rerun_requested": True, | ||
} | ||
], | ||
} | ||
] |