Skip to content

Commit

Permalink
Return artefact status from api (#65)
Browse files Browse the repository at this point in the history
* Return artefact status from api

* Replace null artefact status with 'UNDECIDED'

* Bug fixes
  • Loading branch information
omar-selo authored Dec 4, 2023
1 parent eef21c0 commit e112f70
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Make artefact status not nullable
Revision ID: 8317277d4333
Revises: 8d8643821588
Create Date: 2023-12-04 08:20:23.131927+00:00
"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "8317277d4333"
down_revision = "8d8643821588"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.execute("ALTER TYPE artefact_status_enum RENAME TO artefact_status_enum_old")
op.execute(
"CREATE TYPE artefact_status_enum AS "
"ENUM('APPROVED', 'MARKED_AS_FAILED', 'UNDECIDED')"
)
op.execute(
"ALTER TABLE artefact ALTER COLUMN status TYPE "
"artefact_status_enum USING status::text::artefact_status_enum"
)
op.execute("DROP TYPE artefact_status_enum_old")
op.execute("UPDATE artefact SET status = 'UNDECIDED' WHERE status IS NULL")
op.execute("ALTER TABLE artefact ALTER COLUMN status SET NOT NULL")


def downgrade() -> None:
op.execute("ALTER TYPE artefact_status_enum RENAME TO artefact_status_enum_old")
op.execute(
"CREATE TYPE artefact_status_enum AS ENUM('APPROVED', 'MARKED_AS_FAILED')"
)
op.execute("ALTER TABLE artefact ALTER COLUMN status DROP NOT NULL")
op.execute("UPDATE artefact SET status = NULL WHERE status = 'UNDECIDED'")
op.execute(
"ALTER TABLE artefact ALTER COLUMN status TYPE "
"artefact_status_enum USING status::text::artefact_status_enum"
)
op.execute("DROP TYPE artefact_status_enum_old")
1 change: 1 addition & 0 deletions backend/test_observer/controllers/artefacts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ArtefactDTO(BaseModel):
series: str | None
repo: str | None
stage: str = Field(validation_alias=AliasPath("stage", "name"))
status: ArtefactStatus


class EnvironmentDTO(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion backend/test_observer/data_access/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Artefact(Base):
)
# Default fields
due_date: Mapped[date | None]
status: Mapped[ArtefactStatus | None]
status: Mapped[ArtefactStatus] = mapped_column(default=ArtefactStatus.UNDECIDED)

__table_args__ = (
UniqueConstraint("name", "version", "track", name="unique_snap"),
Expand Down
1 change: 1 addition & 0 deletions backend/test_observer/data_access/models_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ class TestExecutionStatus(Enum):
class ArtefactStatus(str, Enum):
APPROVED = "APPROVED"
MARKED_AS_FAILED = "MARKED_AS_FAILED"
UNDECIDED = "UNDECIDED"
11 changes: 9 additions & 2 deletions backend/tests/controllers/artefacts/test_artefacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@

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")
relevant_artefact = create_artefact(
db_session,
"edge",
version="2",
status=ArtefactStatus.MARKED_AS_FAILED,
)

old_timestamp = relevant_artefact.created_at - timedelta(days=1)
create_artefact(db_session, "edge", created_at=old_timestamp, version="1")
Expand All @@ -48,13 +53,14 @@ def test_get_latest_artefacts_by_family(db_session: Session, test_client: TestCl
"series": relevant_artefact.series,
"repo": relevant_artefact.repo,
"stage": relevant_artefact.stage.name,
"status": relevant_artefact.status,
}
]


def test_get_artefact(db_session: Session, test_client: TestClient):
"""Should be able to fetch an existing artefact"""
artefact = create_artefact(db_session, "edge")
artefact = create_artefact(db_session, "edge", status=ArtefactStatus.APPROVED)

response = test_client.get(f"/v1/artefacts/{artefact.id}")

Expand All @@ -68,6 +74,7 @@ def test_get_artefact(db_session: Session, test_client: TestClient):
"series": artefact.series,
"repo": artefact.repo,
"stage": artefact.stage.name,
"status": artefact.status,
}


Expand Down
1 change: 1 addition & 0 deletions backend/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def create_artefact(db_session: Session, stage_name: str, **kwargs) -> Artefact:
series=kwargs.get("series", "jammy" if family == FamilyName.DEB else None),
repo=kwargs.get("repo", "main" if family == FamilyName.DEB else None),
created_at=kwargs.get("created_at", datetime.utcnow()),
status=kwargs.get("status"),
)
db_session.add(artefact)
db_session.commit()
Expand Down

0 comments on commit e112f70

Please sign in to comment.