diff --git a/frontend/coprs_frontend/coprs/logic/builds_logic.py b/frontend/coprs_frontend/coprs/logic/builds_logic.py index d23fa48fb..287327f3d 100644 --- a/frontend/coprs_frontend/coprs/logic/builds_logic.py +++ b/frontend/coprs_frontend/coprs/logic/builds_logic.py @@ -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, @@ -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): diff --git a/frontend/coprs_frontend/tests/coprs_test_case.py b/frontend/coprs_frontend/tests/coprs_test_case.py index fbcd1678f..b4142c269 100644 --- a/frontend/coprs_frontend/tests/coprs_test_case.py +++ b/frontend/coprs_frontend/tests/coprs_test_case.py @@ -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, @@ -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( @@ -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) @@ -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"), @@ -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): @@ -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): @@ -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): @@ -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): diff --git a/frontend/coprs_frontend/tests/test_helpers.py b/frontend/coprs_frontend/tests/test_helpers.py index 80df3c5ac..121bfccea 100644 --- a/frontend/coprs_frontend/tests/test_helpers.py +++ b/frontend/coprs_frontend/tests/test_helpers.py @@ -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) diff --git a/frontend/coprs_frontend/tests/test_pagure_events.py b/frontend/coprs_frontend/tests/test_pagure_events.py index 7c134bfa3..eeb8ff8ce 100644 --- a/frontend/coprs_frontend/tests/test_pagure_events.py +++ b/frontend/coprs_frontend/tests/test_pagure_events.py @@ -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) @@ -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', @@ -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',