Merge ~pappacena/launchpad:bugfix-remove-ocirecipe-pushrules into launchpad:master

Proposed by Thiago F. Pappacena
Status: Merged
Approved by: Thiago F. Pappacena
Approved revision: 67962f529769c006a584368cb69eb1cfc61e3fd1
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pappacena/launchpad:bugfix-remove-ocirecipe-pushrules
Merge into: launchpad:master
Diff against target: 60 lines (+18/-5)
2 files modified
lib/lp/oci/model/ocirecipe.py (+2/-0)
lib/lp/oci/tests/test_ocirecipe.py (+16/-5)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Tom Wardill (community) Approve
Review via email: mp+392055@code.launchpad.net

Commit message

Removing associated push rules when deleting an OCI recipe

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/oci/model/ocirecipe.py b/lib/lp/oci/model/ocirecipe.py
2index 15fa5be..fd21dde 100644
3--- a/lib/lp/oci/model/ocirecipe.py
4+++ b/lib/lp/oci/model/ocirecipe.py
5@@ -240,6 +240,8 @@ class OCIRecipe(Storm, WebhookTargetMixin):
6 store.find(Job, Job.id.is_in(affected_jobs)).remove()
7 builds = store.find(OCIRecipeBuild, OCIRecipeBuild.recipe == self)
8 builds.remove()
9+ for push_rule in self.push_rules:
10+ push_rule.destroySelf()
11 getUtility(IWebhookSet).delete(self.webhooks)
12 store.remove(self)
13 store.find(
14diff --git a/lib/lp/oci/tests/test_ocirecipe.py b/lib/lp/oci/tests/test_ocirecipe.py
15index 76997a7..a0b1c59 100644
16--- a/lib/lp/oci/tests/test_ocirecipe.py
17+++ b/lib/lp/oci/tests/test_ocirecipe.py
18@@ -32,7 +32,10 @@ from zope.security.proxy import removeSecurityProxy
19
20 from lp.buildmaster.enums import BuildStatus
21 from lp.buildmaster.interfaces.processor import IProcessorSet
22-from lp.oci.interfaces.ocipushrule import OCIPushRuleAlreadyExists
23+from lp.oci.interfaces.ocipushrule import (
24+ IOCIPushRuleSet,
25+ OCIPushRuleAlreadyExists,
26+ )
27 from lp.oci.interfaces.ocirecipe import (
28 CannotModifyOCIRecipeProcessor,
29 DuplicateOCIRecipeName,
30@@ -385,11 +388,16 @@ class TestOCIRecipe(OCIConfigHelperMixin, TestCaseWithFactory):
31 for payload_matcher in payload_matchers]))
32
33 def test_destroySelf(self):
34+ self.setConfig()
35 oci_recipe = self.factory.makeOCIRecipe()
36- build_ids = []
37- for x in range(3):
38- build_ids.append(
39- self.factory.makeOCIRecipeBuild(recipe=oci_recipe).id)
40+ # Create associated builds:
41+ build_ids = [
42+ self.factory.makeOCIRecipeBuild(recipe=oci_recipe).id
43+ for _ in range(3)]
44+ # Create associated push rules:
45+ push_rule_ids = [
46+ self.factory.makeOCIPushRule(recipe=oci_recipe).id
47+ for i in range(3)]
48
49 with person_logged_in(oci_recipe.owner):
50 oci_recipe.destroySelf()
51@@ -397,6 +405,9 @@ class TestOCIRecipe(OCIConfigHelperMixin, TestCaseWithFactory):
52
53 for build_id in build_ids:
54 self.assertIsNone(getUtility(IOCIRecipeBuildSet).getByID(build_id))
55+ for push_rule_id in push_rule_ids:
56+ self.assertIsNone(
57+ getUtility(IOCIPushRuleSet).getByID(push_rule_id))
58
59 def test_related_webhooks_deleted(self):
60 owner = self.factory.makePerson()