From 537c2017444b231ded83041730a5148be7de283a Mon Sep 17 00:00:00 2001 From: Omar Selo Date: Tue, 20 Jun 2023 13:50:52 +0300 Subject: [PATCH] Fix bug as artefact builds shouldn't be generated randomly --- .../controllers/artefacts/test_artefacts.py | 6 ++-- .../controllers/promoter/test_promoter.py | 9 ++++-- backend/tests/helpers.py | 28 ------------------- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/backend/tests/controllers/artefacts/test_artefacts.py b/backend/tests/controllers/artefacts/test_artefacts.py index d67b5018..a0a8de1f 100644 --- a/backend/tests/controllers/artefacts/test_artefacts.py +++ b/backend/tests/controllers/artefacts/test_artefacts.py @@ -21,19 +21,19 @@ from sqlalchemy.orm import Session from test_observer.data_access.models import ArtefactBuild, Environment, TestExecution -from tests.helpers import create_artefact, create_artefact_builds +from tests.helpers import create_artefact def test_get_artefact_builds(db_session: Session, test_client: TestClient): artefact = create_artefact(db_session, "beta") - artefact_build = create_artefact_builds(db_session, artefact, 1)[0] + artefact_build = ArtefactBuild(architecture="amd64", artefact=artefact, revision=1) environment = Environment( name="some-environment", architecture=artefact_build.architecture ) test_execution = TestExecution( artefact_build=artefact_build, environment=environment ) - db_session.add_all([environment, test_execution]) + db_session.add_all([environment, test_execution, artefact_build]) db_session.commit() response = test_client.get(f"/v1/artefacts/{artefact.id}/builds") diff --git a/backend/tests/controllers/promoter/test_promoter.py b/backend/tests/controllers/promoter/test_promoter.py index bb90c175..8ce643fc 100644 --- a/backend/tests/controllers/promoter/test_promoter.py +++ b/backend/tests/controllers/promoter/test_promoter.py @@ -25,8 +25,9 @@ from fastapi.testclient import TestClient from requests_mock import Mocker from sqlalchemy.orm import Session +from test_observer.data_access.models import ArtefactBuild -from tests.helpers import create_artefact, create_artefact_builds +from tests.helpers import create_artefact def test_run_to_move_artefact_snap( @@ -45,7 +46,6 @@ def test_run_to_move_artefact_snap( source={"store": "ubuntu"}, created_at=datetime.utcnow(), ) - create_artefact_builds(db_session, artefact) create_artefact( db_session, "edge", @@ -54,6 +54,8 @@ def test_run_to_move_artefact_snap( source={"store": "ubuntu"}, created_at=datetime.utcnow() - timedelta(days=1), ) + ArtefactBuild(architecture="amd64", artefact=artefact, revision=1) + requests_mock.get( "https://api.snapcraft.io/v2/snaps/info/core20", json={ @@ -106,7 +108,6 @@ def test_run_to_move_artefact_deb( source={"series": "kinetic", "repo": "main"}, created_at=datetime.utcnow(), ) - create_artefact_builds(db_session, artefact) create_artefact( db_session, "proposed", @@ -115,6 +116,8 @@ def test_run_to_move_artefact_deb( source={"series": "kinetic", "repo": "main"}, created_at=datetime.utcnow() - timedelta(days=1), ) + db_session.add(ArtefactBuild(architecture="x64", artefact=artefact)) + db_session.commit() with open("tests/test_data/Packages-proposed.gz", "rb") as f: proposed_content = f.read() diff --git a/backend/tests/helpers.py b/backend/tests/helpers.py index 6dbbae76..dc22ce2f 100644 --- a/backend/tests/helpers.py +++ b/backend/tests/helpers.py @@ -19,31 +19,3 @@ def create_artefact(db_session: Session, stage_name: str, **kwargs) -> Artefact: db_session.add(artefact) db_session.commit() return artefact - - -def create_artefact_builds( - db_session: Session, artefact: Artefact, num_builds: int = 5 -) -> list[ArtefactBuild]: - """ - Create a number of ArtefactBuild instances for an Artefact and add them - to the database - """ - architectures = ["arm64", "x86", "amd64"] - - for i in range(num_builds): - architecture = choice(architectures) - - build = ArtefactBuild( - architecture=architecture, - revision=i + 1 - if artefact.stage.family.name == FamilyName.SNAP.value - else None, - artefact_id=artefact.id, - ) - - # Add the build to the artefact's builds - artefact.builds.append(build) - - # Commit the changes to the database - db_session.commit() - return artefact.builds