Skip to content

Commit

Permalink
frontend: explicitly add new objects to the transaction
Browse files Browse the repository at this point in the history
See #3130
  • Loading branch information
FrostyX authored and praiskup committed Mar 7, 2024
1 parent 7a236d1 commit 7ccd596
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
5 changes: 3 additions & 2 deletions frontend/coprs_frontend/coprs/logic/builds_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ def create(cls, build_chroot, name, epoch, version, release, arch):
"""
Create a new record about a built package in some `BuildChroot`
"""
return models.BuildChrootResult(
build_chroot = models.BuildChrootResult(
build_chroot_id=build_chroot,
build_chroot=build_chroot,
name=name,
Expand All @@ -1544,7 +1544,8 @@ def create(cls, build_chroot, name, epoch, version, release, arch):
release=release,
arch=arch,
)

db.session.add(build_chroot)
return build_chroot

@classmethod
def create_from_dict(cls, build_chroot, results):
Expand Down
11 changes: 7 additions & 4 deletions frontend/coprs_frontend/tests/coprs_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ def f_builds(self):
copr=self.c2, name="whatsupthere-world", source_type=0)
self.p3 = models.Package(
copr=self.c3, name="goodbye-world", source_type=0)
self.db.session.add_all([self.p1, self.p2, self.p3])

self.b1 = models.Build(
copr=self.c1, copr_dir=self.c1_dir, package=self.p1,
Expand Down Expand Up @@ -461,6 +462,7 @@ def f_fork_prepare(self, f_coprs, f_mock_chroots, f_builds):
self.b6_bc = []
self.b7_bc = []
self.b8_bc = []
self.db.session.add_all([self.b5, self.b6, self.b7, self.b8])
self.db.session.flush()

for build, build_chroots in zip(
Expand All @@ -478,7 +480,6 @@ def f_fork_prepare(self, f_coprs, f_mock_chroots, f_builds):
)
build_chroots.append(buildchroot)
self.db.session.add(buildchroot)
self.db.session.add_all([self.b5, self.b6, self.b7, self.b8])

self.p5 = models.Package(
copr=self.c2, name="new-package", source_type=0)
Expand All @@ -498,6 +499,7 @@ def f_fork_prepare(self, f_coprs, f_mock_chroots, f_builds):
self.b9_bc = []
self.b10_bc = []
self.b11_bc = []
self.db.session.add_all([self.b9, self.b10, self.b11])
self.db.session.flush()

bc_status = {self.b9: {self.mc2: StatusEnum("succeeded"),
Expand All @@ -521,7 +523,6 @@ def f_fork_prepare(self, f_coprs, f_mock_chroots, f_builds):
)
build_chroots.append(buildchroot)
self.db.session.add(buildchroot)
self.db.session.add_all([self.b9, self.b10, self.b11])

@pytest.fixture
def f_fedora_branching(self, f_u1_ts_client, f_mock_chroots, f_db):
Expand Down Expand Up @@ -549,13 +550,13 @@ def f_fedora_branching(self, f_u1_ts_client, f_mock_chroots, f_db):
@pytest.fixture
def f_hook_package(self, f_users, f_coprs, f_mock_chroots, f_builds):
self.c1.webhook_secret = str(uuid.uuid4())
self.db.session.add(self.c1)
self.pHook = models.Package(
copr=self.c1,
name="hook-package",
source_type=helpers.BuildSourceEnum('scm'),
source_json='{"clone_url": "example.com"}',
)
self.db.session.add_all([self.c1, self.pHook])

@pytest.fixture
def f_build_few_chroots(self, f_mock_chroots_many):
Expand Down Expand Up @@ -662,6 +663,8 @@ def f_copr_permissions(self):
copr_builder=helpers.PermissionEnum("request"),
copr_admin=helpers.PermissionEnum("approved"))

self.db.session.add_all([self.cp1, self.cp2, self.cp3])


@pytest.fixture
def f_copr_more_permissions(self, f_copr_permissions):
Expand All @@ -680,7 +683,7 @@ def f_copr_more_permissions(self, f_copr_permissions):
copr_builder=helpers.PermissionEnum("approved"),
copr_admin=helpers.PermissionEnum("nothing"))

self.db.session.add_all([self.cp1, self.cp2, self.cp3])
self.db.session.add_all([self.u4, self.cp4])

@pytest.fixture
def f_actions(self, f_db):
Expand Down
1 change: 1 addition & 0 deletions frontend/coprs_frontend/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def test_orm_object_clone(self):

# remove the duplicity, and commit (no traceback)
copy.copr = target_copr
self.db.session.add(copy)
self.db.session.commit()

target_copr = self.models.Copr.query.get(1)
Expand Down
3 changes: 3 additions & 0 deletions frontend/coprs_frontend/tests/test_pagure_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_positive_is_dir_in_commit(self, f_users, f_coprs):
copr=self.c1, name="hello-world", source_type=8, webhook_rebuild=True,
source_json='{"clone_url": "https://pagure.io/test"}'
)
self.db.session.add(self.p2)
candidates = ScmPackage.get_candidates_for_rebuild("https://pagure.io/test")
for pkg in candidates:
dir_in_commit = pkg.is_dir_in_commit(changed_files)
Expand All @@ -71,6 +72,7 @@ def test_positive_build_from_pr_update(self, f_raw_commit_changes):
copr=self.c1, name="hello-world", source_type=8, webhook_rebuild=True,
source_json='{"clone_url": "https://pagure.io/test/copr/copr"}'
)
self.db.session.add(self.p1)
build = build_on_fedmsg_loop()
message = Message(
'io.pagure.prod.pagure.pull-request.updated',
Expand Down Expand Up @@ -153,6 +155,7 @@ def test_positive_build_from_push(self, f_raw_commit_changes):
copr=self.c1, name="hello-world", source_type=8, webhook_rebuild=True,
source_json='{"clone_url": "https://pagure.io/test"}'
)
self.db.session.add(self.p1)
build = build_on_fedmsg_loop()
message = Message(
'io.pagure.prod.pagure.git.receive',
Expand Down

0 comments on commit 7ccd596

Please sign in to comment.