Skip to content

Commit

Permalink
Merge branch 'main' into fix-artefact-build-uniqueness
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-selo committed Jun 21, 2023
2 parents 3c094cf + bac60dc commit 7085095
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 143 deletions.
2 changes: 0 additions & 2 deletions backend/test_observer/controllers/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@
from .artefacts import artefacts
from .families import families
from .promoter import promoter
from .test_execution import test_execution
from .test_executions import test_executions

router = APIRouter()
router.include_router(promoter.router)
router.include_router(test_execution.router, prefix="/v1/test-execution")
router.include_router(families.router, prefix="/v1/families")
router.include_router(version.router, prefix="/v1/version")
router.include_router(test_executions.router, prefix="/v1/test-executions")
Expand Down
Empty file.
12 changes: 0 additions & 12 deletions backend/test_observer/controllers/test_execution/models.py

This file was deleted.

82 changes: 0 additions & 82 deletions backend/test_observer/controllers/test_execution/test_execution.py

This file was deleted.

31 changes: 31 additions & 0 deletions backend/test_observer/controllers/test_executions/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
# Copyright 2023 Canonical Ltd.
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Written by:
# Omar Selo <[email protected]>


from pydantic import BaseModel

from test_observer.data_access.models_enums import TestExecutionStatus


class StartTestExecutionRequest(BaseModel):
family: str
name: str
version: str
revision: int | None = None
source: dict
arch: str
execution_stage: str
environment: str


class TestExecutionsPatchRequest(BaseModel):
c3_link: str
jenkins_link: str
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,90 @@
# Copyright 2023 Canonical Ltd.
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Written by:
# Omar Selo <[email protected]>
# Nadzeya Hutsko <[email protected]>


from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from test_observer.data_access.models import TestExecution
from test_observer.data_access.models import (
TestExecution,
Stage,
Artefact,
ArtefactBuild,
Environment,
)
from test_observer.data_access.models_enums import TestExecutionStatus
from test_observer.data_access.repository import get_or_create
from test_observer.data_access.setup import get_db

from .models import TestExecutionsPatchRequest
from .models import TestExecutionsPatchRequest, StartTestExecutionRequest

router = APIRouter()


@router.put("/start-test")
def start_test_execution(
request: StartTestExecutionRequest, db: Session = Depends(get_db)
):
stage = (
db.query(Stage)
.filter(
Stage.name == request.execution_stage,
Stage.family.has(name=request.family),
)
.one()
)

artefact = get_or_create(
db,
Artefact,
name=request.name,
version=request.version,
source=request.source,
stage_id=stage.id,
)

environment = get_or_create(
db,
Environment,
name=request.environment,
architecture=request.arch,
)

artefact_build = get_or_create(
db,
ArtefactBuild,
architecture=request.arch,
revision=request.revision,
artefact_id=artefact.id,
)

test_execution = get_or_create(
db,
TestExecution,
environment_id=environment.id,
artefact_build_id=artefact_build.id,
status=TestExecutionStatus.IN_PROGRESS,
)
return {"id": test_execution.id}


@router.patch("/{id}")
def patch_test_execution(
id: int,
Expand Down
37 changes: 0 additions & 37 deletions backend/tests/controllers/test_executions/test_test_excutions.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
# Copyright 2023 Canonical Ltd.
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Written by:
# Omar Selo <[email protected]>
# Nadzeya Hutsko <[email protected]>


from fastapi.testclient import TestClient
from sqlalchemy.orm import Session

from test_observer.controllers.test_execution.models import StartTestExecutionRequest
from test_observer.data_access.models import (
Artefact,
ArtefactBuild,
Environment,
Stage,
TestExecution,
ArtefactBuild,
Environment,
)
from test_observer.data_access.models_enums import TestExecutionStatus
from test_observer.controllers.test_executions.models import StartTestExecutionRequest


def test_creates_all_data_models(db_session: Session, test_client: TestClient):
test_client.put(
"/v1/test-execution/start",
response = test_client.put(
"/v1/test-executions/start-test",
json={
"family": "snap",
"name": "core22",
Expand Down Expand Up @@ -60,7 +80,7 @@ def test_creates_all_data_models(db_session: Session, test_client: TestClient):
)
assert artefact_build

assert (
test_execution = (
db_session.query(TestExecution)
.filter(
TestExecution.artefact_build == artefact_build,
Expand All @@ -69,6 +89,8 @@ def test_creates_all_data_models(db_session: Session, test_client: TestClient):
)
.one_or_none()
)
assert test_execution
assert response.json() == {"id": test_execution.id}


def test_uses_existing_models(db_session: Session, test_client: TestClient):
Expand Down Expand Up @@ -105,7 +127,7 @@ def test_uses_existing_models(db_session: Session, test_client: TestClient):
db_session.commit()

test_client.put(
"/v1/test-execution/start",
"/v1/test-executions/start-test",
json=request.dict(),
)

Expand All @@ -118,3 +140,30 @@ def test_uses_existing_models(db_session: Session, test_client: TestClient):
)
.one_or_none()
)


def test_updates_test_execution(db_session: Session, test_client: TestClient):
stage = db_session.query(Stage).filter(Stage.name == "beta").one()
artefact = Artefact(name="some artefact", version="1.0.0", source={}, stage=stage)
artefact_build = ArtefactBuild(architecture="some arch", artefact=artefact)
environment = Environment(name="some environment", architecture="some arch")
test_execution = TestExecution(
environment=environment, artefact_build=artefact_build
)
db_session.add_all([artefact, artefact_build, environment, test_execution])
db_session.commit()
db_session.refresh(test_execution)

test_client.patch(
f"/v1/test-executions/{test_execution.id}",
json={
"jenkins_link": "some jenkins link",
"c3_link": "some c3 link",
"status": TestExecutionStatus.PASSED.name,
},
)

db_session.refresh(test_execution)
assert test_execution.jenkins_link == "some jenkins link"
assert test_execution.c3_link == "some c3 link"
assert test_execution.status == TestExecutionStatus.PASSED

0 comments on commit 7085095

Please sign in to comment.