Skip to content

Commit

Permalink
Add endpoint to patch artefact status (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-selo authored Nov 28, 2023
1 parent d7485c0 commit 8a08727
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
15 changes: 14 additions & 1 deletion backend/test_observer/controllers/artefacts/artefacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from test_observer.data_access.repository import get_artefacts_by_family
from test_observer.data_access.setup import get_db

from .models import ArtefactBuildDTO, ArtefactDTO
from .models import ArtefactBuildDTO, ArtefactDTO, ArtefactPatch

router = APIRouter()

Expand Down Expand Up @@ -55,6 +55,19 @@ def get_artefact(artefact_id: int, db: Session = Depends(get_db)):
return artefact


@router.patch("/{artefact_id}")
def patch_artefact(
artefact_id: int, request: ArtefactPatch, db: Session = Depends(get_db)
):
artefact = db.get(Artefact, artefact_id)

if artefact is None:
raise HTTPException(status_code=404, detail="Artefact not found")

artefact.status = request.status
db.commit()


@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"""
Expand Down
6 changes: 5 additions & 1 deletion backend/test_observer/controllers/artefacts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Nadzeya Hutsko <[email protected]>
from pydantic import AliasPath, BaseModel, ConfigDict, Field

from test_observer.data_access.models_enums import TestExecutionStatus
from test_observer.data_access.models_enums import ArtefactStatus, TestExecutionStatus


class ArtefactDTO(BaseModel):
Expand Down Expand Up @@ -60,3 +60,7 @@ class ArtefactBuildDTO(BaseModel):
architecture: str
revision: int | None
test_executions: list[TestExecutionDTO]


class ArtefactPatch(BaseModel):
status: ArtefactStatus
2 changes: 1 addition & 1 deletion backend/test_observer/data_access/models_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ class TestExecutionStatus(Enum):
NOT_TESTED = "NOT_TESTED"


class ArtefactStatus(Enum):
class ArtefactStatus(str, Enum):
APPROVED = "APPROVED"
MARKED_AS_FAILED = "MARKED_AS_FAILED"
15 changes: 15 additions & 0 deletions backend/tests/controllers/artefacts/test_artefacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from sqlalchemy.orm import Session

from test_observer.data_access.models import ArtefactBuild, Environment, TestExecution
from test_observer.data_access.models_enums import ArtefactStatus
from tests.helpers import create_artefact


Expand Down Expand Up @@ -129,3 +130,17 @@ def test_get_artefact_builds_only_latest(db_session: Session, test_client: TestC
"test_executions": [],
}
]


def test_artefact_signoff(db_session: Session, test_client: TestClient):
artefact = create_artefact(db_session, "candidate")

response = test_client.patch(
f"/v1/artefacts/{artefact.id}",
json={"status": ArtefactStatus.APPROVED},
)

db_session.refresh(artefact)

assert response.status_code == 200
assert artefact.status == ArtefactStatus.APPROVED

0 comments on commit 8a08727

Please sign in to comment.