-
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.
Add GET /v1/artefacts/{artefact_id}/builds endpoint
- Loading branch information
Showing
6 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
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,16 @@ | ||
from fastapi import APIRouter, Depends | ||
from sqlalchemy.orm import Session | ||
from test_observer.data_access.models import ArtefactBuild | ||
from test_observer.data_access.setup import get_db | ||
|
||
from .models import ArtefactBuildDTO | ||
|
||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/{artefact_id}/builds", response_model=list[ArtefactBuildDTO]) | ||
def get_artefact_builds(artefact_id: int, db: Session = Depends(get_db)): | ||
return ( | ||
db.query(ArtefactBuild).filter(ArtefactBuild.artefact_id == artefact_id).all() | ||
) |
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,29 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class EnvironmentDTO(BaseModel): | ||
id: int | ||
name: str | ||
architecture: str | ||
|
||
class Config: | ||
orm_mode = True | ||
|
||
|
||
class TestExecutionDTO(BaseModel): | ||
id: int | ||
jenkins_link: str | None | ||
c3_link: str | None | ||
environment: EnvironmentDTO | ||
|
||
class Config: | ||
orm_mode = True | ||
|
||
|
||
class ArtefactBuildDTO(BaseModel): | ||
id: int | ||
revision: int | None | ||
test_executions: list[TestExecutionDTO] | ||
|
||
class Config: | ||
orm_mode = True |
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,40 @@ | ||
from fastapi.testclient import TestClient | ||
from sqlalchemy.orm import Session | ||
from test_observer.data_access.models import Environment, TestExecution | ||
|
||
from tests.helpers import create_artefact, create_artefact_builds | ||
|
||
|
||
def test_get_artefact(db_session: Session, test_client: TestClient): | ||
artefact = create_artefact(db_session, "beta") | ||
artefact_build = create_artefact_builds(db_session, artefact, 1)[0] | ||
environment = Environment( | ||
name="some-environment", architecture=artefact_build.architecture | ||
) | ||
test_execution = TestExecution( | ||
artefact_build=artefact_build, environment=environment | ||
) | ||
db_session.add_all([environment, test_execution]) | ||
db_session.commit() | ||
|
||
response = test_client.get(f"/v1/artefacts/{artefact.id}/builds") | ||
|
||
assert response.status_code == 200 | ||
assert response.json() == [ | ||
{ | ||
"id": artefact_build.id, | ||
"revision": artefact_build.revision, | ||
"test_executions": [ | ||
{ | ||
"id": test_execution.id, | ||
"jenkins_link": test_execution.jenkins_link, | ||
"c3_link": test_execution.c3_link, | ||
"environment": { | ||
"id": environment.id, | ||
"name": environment.name, | ||
"architecture": environment.architecture, | ||
}, | ||
} | ||
], | ||
} | ||
] |
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