Skip to content

Commit

Permalink
Fix bug as artefact builds shouldn't be generated randomly
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-selo committed Jun 20, 2023
1 parent b53494a commit 537c201
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 34 deletions.
6 changes: 3 additions & 3 deletions backend/tests/controllers/artefacts/test_artefacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 6 additions & 3 deletions backend/tests/controllers/promoter/test_promoter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand All @@ -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={
Expand Down Expand Up @@ -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",
Expand All @@ -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()
Expand Down
28 changes: 0 additions & 28 deletions backend/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 537c201

Please sign in to comment.