-
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.
* Make artefact track, store, series and repo not nullable * Add testresults report endpoint * Convert helper test function to fixtures * Refactor test data generation * Move create_artefact helper into DataGenerator * Return only latest artefact builds in testresults report * Fix migration * Reflect not nullability through artefact dto * Fix frontend after some artefact fields became not nullable
- Loading branch information
Showing
19 changed files
with
555 additions
and
131 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
...migrations/versions/2024_02_20_0819-654e57018d35_make_artefact_track_store_series_and_.py
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,70 @@ | ||
"""Make artefact track, store, series and repo not nullable | ||
Revision ID: 654e57018d35 | ||
Revises: bb2a51214402 | ||
Create Date: 2024-02-20 08:19:37.117290+00:00 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "654e57018d35" | ||
down_revision = "bb2a51214402" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.drop_constraint("unique_deb", "artefact", type_="unique") | ||
op.create_index( | ||
"unique_deb", | ||
"artefact", | ||
["name", "version", "series", "repo"], | ||
unique=True, | ||
postgresql_where=sa.text("series != '' AND repo != ''"), | ||
) | ||
op.drop_constraint("unique_snap", "artefact", type_="unique") | ||
op.create_index( | ||
"unique_snap", | ||
"artefact", | ||
["name", "version", "track"], | ||
unique=True, | ||
postgresql_where=sa.text("track != ''"), | ||
) | ||
|
||
op.execute("UPDATE artefact SET track = '' WHERE track is NULL") | ||
op.execute("UPDATE artefact SET store = '' WHERE store is NULL") | ||
op.execute("UPDATE artefact SET series = '' WHERE series is NULL") | ||
op.execute("UPDATE artefact SET repo = '' WHERE repo is NULL") | ||
|
||
op.alter_column("artefact", "track", existing_type=sa.VARCHAR(), nullable=False) | ||
op.alter_column("artefact", "store", existing_type=sa.VARCHAR(), nullable=False) | ||
op.alter_column("artefact", "series", existing_type=sa.VARCHAR(), nullable=False) | ||
op.alter_column("artefact", "repo", existing_type=sa.VARCHAR(), nullable=False) | ||
|
||
|
||
def downgrade() -> None: | ||
op.alter_column("artefact", "repo", existing_type=sa.VARCHAR(), nullable=True) | ||
op.alter_column("artefact", "series", existing_type=sa.VARCHAR(), nullable=True) | ||
op.alter_column("artefact", "store", existing_type=sa.VARCHAR(), nullable=True) | ||
op.alter_column("artefact", "track", existing_type=sa.VARCHAR(), nullable=True) | ||
|
||
op.execute("UPDATE artefact SET repo = NULL WHERE repo = ''") | ||
op.execute("UPDATE artefact SET series = NULL WHERE series = ''") | ||
op.execute("UPDATE artefact SET store = NULL WHERE store = ''") | ||
op.execute("UPDATE artefact SET track = NULL WHERE track = ''") | ||
|
||
op.drop_index( | ||
"unique_snap", table_name="artefact", postgresql_where=sa.text("track != ''") | ||
) | ||
op.create_unique_constraint("unique_snap", "artefact", ["name", "version", "track"]) | ||
op.drop_index( | ||
"unique_deb", | ||
table_name="artefact", | ||
postgresql_where=sa.text("series != '' AND repo != ''"), | ||
) | ||
op.create_unique_constraint( | ||
"unique_deb", "artefact", ["name", "version", "series", "repo"] | ||
) |
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,81 @@ | ||
import csv | ||
from datetime import datetime | ||
|
||
from fastapi import APIRouter, Depends | ||
from fastapi.responses import FileResponse | ||
from sqlalchemy import select | ||
from sqlalchemy.orm import Session | ||
from sqlalchemy.orm.attributes import InstrumentedAttribute | ||
|
||
from test_observer.data_access.models import ( | ||
Artefact, | ||
ArtefactBuild, | ||
Environment, | ||
Family, | ||
Stage, | ||
TestCase, | ||
TestExecution, | ||
TestResult, | ||
) | ||
from test_observer.data_access.setup import get_db | ||
|
||
router = APIRouter() | ||
|
||
TESTRESULTS_REPORT_COLUMNS: list[InstrumentedAttribute] = [ | ||
Family.name, | ||
Artefact.name, | ||
Artefact.version, | ||
Artefact.status, | ||
Artefact.track, | ||
Artefact.series, | ||
Artefact.repo, | ||
TestExecution.status, | ||
TestExecution.review_decision, | ||
TestExecution.review_comment, | ||
Environment.name, | ||
Environment.architecture, | ||
TestCase.name, | ||
TestCase.category, | ||
TestResult.status, | ||
] | ||
|
||
|
||
@router.get("/testresults", response_class=FileResponse) | ||
def get_testresults_report( | ||
start_date: datetime = datetime.min, | ||
end_date: datetime | None = None, | ||
db: Session = Depends(get_db), | ||
): | ||
""" | ||
Returns a csv report detailing all artefacts within a given date range. Together | ||
with their test executions and test results in csv format. | ||
""" | ||
if end_date is None: | ||
end_date = datetime.now() | ||
|
||
latest_builds = ( | ||
select(ArtefactBuild) | ||
.distinct(ArtefactBuild.artefact_id, ArtefactBuild.architecture) | ||
.order_by(ArtefactBuild.artefact_id, ArtefactBuild.architecture) | ||
.subquery() | ||
) | ||
|
||
cursor = db.execute( | ||
select(*TESTRESULTS_REPORT_COLUMNS) | ||
.join_from(Family, Stage) | ||
.join_from(Stage, Artefact) | ||
.join_from(Artefact, latest_builds) | ||
.join_from(latest_builds, TestExecution) | ||
.join_from(TestExecution, Environment) | ||
.join_from(TestExecution, TestResult) | ||
.join_from(TestResult, TestCase) | ||
.where(Artefact.created_at >= start_date, Artefact.created_at <= end_date) | ||
) | ||
|
||
filename = "testresults_report.csv" | ||
with open(filename, "w") as csvfile: | ||
writer = csv.writer(csvfile) | ||
writer.writerow(TESTRESULTS_REPORT_COLUMNS) | ||
writer.writerows(cursor) | ||
|
||
return filename |
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 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 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 |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
"""Fixtures for testing""" | ||
|
||
|
||
from collections.abc import Callable | ||
from os import environ | ||
|
||
import pytest | ||
|
@@ -34,9 +33,9 @@ | |
drop_database, | ||
) | ||
|
||
from test_observer.data_access.models import User | ||
from test_observer.data_access.setup import get_db | ||
from test_observer.main import app | ||
from tests.data_generator import DataGenerator | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
|
@@ -93,18 +92,5 @@ def test_client(db_session: Session) -> TestClient: | |
|
||
|
||
@pytest.fixture | ||
def create_user(db_session: Session) -> Callable[..., User]: | ||
def _create_user(**kwargs) -> User: | ||
user = User( | ||
**{ | ||
"name": "John Doe", | ||
"launchpad_handle": "jd", | ||
"launchpad_email": "[email protected]", | ||
**kwargs, | ||
} | ||
) | ||
db_session.add(user) | ||
db_session.commit() | ||
return user | ||
|
||
return _create_user | ||
def generator(db_session: Session) -> DataGenerator: | ||
return DataGenerator(db_session) |
Oops, something went wrong.