-
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.
* Pass correct source when creating a dummy artefact * Add get artefacts endpoint * Remove families endpoint as it's no longer needed * Return stage name with artefact * Add fetch artefact endpoint * Refactor to get links to artefacts * Some renaming * Pass query parameters as a dictionary * Fix navbar not highlighting correct family * Fix selecting deb artefact navigates to snap board * Pass query parameters as a map
- Loading branch information
Showing
24 changed files
with
322 additions
and
347 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,17 +17,40 @@ | |
# Written by: | ||
# Omar Selo <[email protected]> | ||
# Nadzeya Hutsko <[email protected]> | ||
from fastapi import APIRouter, Depends | ||
from fastapi import APIRouter, Depends, HTTPException | ||
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 | ||
from test_observer.data_access.models import Artefact, ArtefactBuild, Family, Stage | ||
from test_observer.data_access.models_enums import FamilyName | ||
from test_observer.data_access.setup import get_db | ||
|
||
from .models import ArtefactBuildDTO, ArtefactDTO | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/", response_model=list[ArtefactDTO]) | ||
def get_artefacts(family: FamilyName | None = None, db: Session = Depends(get_db)): | ||
"""Get latest artefacts by family""" | ||
query = db.query(Stage) | ||
if family: | ||
query = query.filter(Stage.family.has(Family.name == family)) | ||
stages = query.all() | ||
|
||
return [artefact for stage in stages for artefact in stage.latest_artefacts] | ||
|
||
|
||
@router.get("/{artefact_id}", response_model=ArtefactDTO) | ||
def get_artefact(artefact_id: int, db: Session = Depends(get_db)): | ||
"""Get an artefact by id""" | ||
artefact = db.query(Artefact).get(artefact_id) | ||
|
||
if artefact is None: | ||
raise HTTPException(status_code=404, detail="Artefact not found") | ||
|
||
return artefact | ||
|
||
|
||
@router.get("/{artefact_id}/builds", response_model=list[ArtefactBuildDTO]) | ||
def get_artefact_builds(artefact_id: int, db: Session = Depends(get_db)): | ||
"""Get latest artefact builds of an artefact together with their test executions""" | ||
|
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 |
---|---|---|
|
@@ -17,11 +17,21 @@ | |
# Written by: | ||
# Omar Selo <[email protected]> | ||
# Nadzeya Hutsko <[email protected]> | ||
from pydantic import BaseModel, ConfigDict | ||
from pydantic import AliasPath, BaseModel, ConfigDict, Field | ||
|
||
from test_observer.data_access.models_enums import TestExecutionStatus | ||
|
||
|
||
class ArtefactDTO(BaseModel): | ||
model_config = ConfigDict(from_attributes=True) | ||
|
||
id: int | ||
name: str | ||
version: str | ||
source: dict[str, int | str] | ||
stage: str = Field(validation_alias=AliasPath("stage", "name")) | ||
|
||
|
||
class EnvironmentDTO(BaseModel): | ||
model_config = ConfigDict(from_attributes=True) | ||
|
||
|
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -17,13 +17,53 @@ | |
# Written by: | ||
# Omar Selo <[email protected]> | ||
# Nadzeya Hutsko <[email protected]> | ||
from datetime import timedelta | ||
|
||
from fastapi.testclient import TestClient | ||
from sqlalchemy.orm import Session | ||
from test_observer.data_access.models import ArtefactBuild, Environment, TestExecution | ||
|
||
from test_observer.data_access.models import ArtefactBuild, Environment, TestExecution | ||
from tests.helpers import create_artefact | ||
|
||
|
||
def test_get_latest_artefacts_by_family(db_session: Session, test_client: TestClient): | ||
"""Should only get latest artefacts and only ones that belong to given family""" | ||
relevant_artefact = create_artefact(db_session, "edge", version="2") | ||
|
||
old_timestamp = relevant_artefact.created_at - timedelta(days=1) | ||
create_artefact(db_session, "edge", created_at=old_timestamp, version="1") | ||
create_artefact(db_session, "proposed") | ||
|
||
response = test_client.get("/v1/artefacts", params={"family": "snap"}) | ||
|
||
assert response.status_code == 200 | ||
assert response.json() == [ | ||
{ | ||
"id": relevant_artefact.id, | ||
"name": relevant_artefact.name, | ||
"version": relevant_artefact.version, | ||
"source": relevant_artefact.source, | ||
"stage": relevant_artefact.stage.name, | ||
} | ||
] | ||
|
||
|
||
def test_get_artefact(db_session: Session, test_client: TestClient): | ||
"""Should be able to fetch an existing artefact""" | ||
artefact = create_artefact(db_session, "edge") | ||
|
||
response = test_client.get(f"/v1/artefacts/{artefact.id}") | ||
|
||
assert response.status_code == 200 | ||
assert response.json() == { | ||
"id": artefact.id, | ||
"name": artefact.name, | ||
"version": artefact.version, | ||
"source": artefact.source, | ||
"stage": artefact.stage.name, | ||
} | ||
|
||
|
||
def test_get_artefact_builds(db_session: Session, test_client: TestClient): | ||
artefact = create_artefact(db_session, "beta") | ||
artefact_build = ArtefactBuild(architecture="amd64", artefact=artefact, revision=1) | ||
|
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
import 'family_name.dart'; | ||
|
||
enum StageName { edge, beta, candidate, stable, proposed, updates } | ||
|
||
List<StageName> familyStages(FamilyName family) { | ||
switch (family) { | ||
case FamilyName.snap: | ||
return [ | ||
StageName.edge, | ||
StageName.beta, | ||
StageName.candidate, | ||
StageName.stable, | ||
]; | ||
case FamilyName.deb: | ||
return [ | ||
StageName.proposed, | ||
StageName.updates, | ||
]; | ||
} | ||
} |
Oops, something went wrong.