-
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.
Merge branch 'main' into fix-artefact-build-uniqueness
- Loading branch information
Showing
8 changed files
with
166 additions
and
143 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
Empty file.
12 changes: 0 additions & 12 deletions
12
backend/test_observer/controllers/test_execution/models.py
This file was deleted.
Oops, something went wrong.
82 changes: 0 additions & 82 deletions
82
backend/test_observer/controllers/test_execution/test_execution.py
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
backend/test_observer/controllers/test_executions/models.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 |
---|---|---|
@@ -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 | ||
|
80 changes: 78 additions & 2 deletions
80
backend/test_observer/controllers/test_executions/test_executions.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 |
---|---|---|
@@ -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, | ||
|
37 changes: 0 additions & 37 deletions
37
backend/tests/controllers/test_executions/test_test_excutions.py
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 |
---|---|---|
@@ -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", | ||
|
@@ -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, | ||
|
@@ -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): | ||
|
@@ -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(), | ||
) | ||
|
||
|
@@ -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 |