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
diff --git a/lib/lp/oci/model/ocirecipe.py b/lib/lp/oci/model/ocirecipe.py
index 15fa5be..fd21dde 100644
--- a/lib/lp/oci/model/ocirecipe.py
+++ b/lib/lp/oci/model/ocirecipe.py
@@ -240,6 +240,8 @@ class OCIRecipe(Storm, WebhookTargetMixin):
240 store.find(Job, Job.id.is_in(affected_jobs)).remove()240 store.find(Job, Job.id.is_in(affected_jobs)).remove()
241 builds = store.find(OCIRecipeBuild, OCIRecipeBuild.recipe == self)241 builds = store.find(OCIRecipeBuild, OCIRecipeBuild.recipe == self)
242 builds.remove()242 builds.remove()
243 for push_rule in self.push_rules:
244 push_rule.destroySelf()
243 getUtility(IWebhookSet).delete(self.webhooks)245 getUtility(IWebhookSet).delete(self.webhooks)
244 store.remove(self)246 store.remove(self)
245 store.find(247 store.find(
diff --git a/lib/lp/oci/tests/test_ocirecipe.py b/lib/lp/oci/tests/test_ocirecipe.py
index 76997a7..a0b1c59 100644
--- a/lib/lp/oci/tests/test_ocirecipe.py
+++ b/lib/lp/oci/tests/test_ocirecipe.py
@@ -32,7 +32,10 @@ from zope.security.proxy import removeSecurityProxy
3232
33from lp.buildmaster.enums import BuildStatus33from lp.buildmaster.enums import BuildStatus
34from lp.buildmaster.interfaces.processor import IProcessorSet34from lp.buildmaster.interfaces.processor import IProcessorSet
35from lp.oci.interfaces.ocipushrule import OCIPushRuleAlreadyExists35from lp.oci.interfaces.ocipushrule import (
36 IOCIPushRuleSet,
37 OCIPushRuleAlreadyExists,
38 )
36from lp.oci.interfaces.ocirecipe import (39from lp.oci.interfaces.ocirecipe import (
37 CannotModifyOCIRecipeProcessor,40 CannotModifyOCIRecipeProcessor,
38 DuplicateOCIRecipeName,41 DuplicateOCIRecipeName,
@@ -385,11 +388,16 @@ class TestOCIRecipe(OCIConfigHelperMixin, TestCaseWithFactory):
385 for payload_matcher in payload_matchers]))388 for payload_matcher in payload_matchers]))
386389
387 def test_destroySelf(self):390 def test_destroySelf(self):
391 self.setConfig()
388 oci_recipe = self.factory.makeOCIRecipe()392 oci_recipe = self.factory.makeOCIRecipe()
389 build_ids = []393 # Create associated builds:
390 for x in range(3):394 build_ids = [
391 build_ids.append(395 self.factory.makeOCIRecipeBuild(recipe=oci_recipe).id
392 self.factory.makeOCIRecipeBuild(recipe=oci_recipe).id)396 for _ in range(3)]
397 # Create associated push rules:
398 push_rule_ids = [
399 self.factory.makeOCIPushRule(recipe=oci_recipe).id
400 for i in range(3)]
393401
394 with person_logged_in(oci_recipe.owner):402 with person_logged_in(oci_recipe.owner):
395 oci_recipe.destroySelf()403 oci_recipe.destroySelf()
@@ -397,6 +405,9 @@ class TestOCIRecipe(OCIConfigHelperMixin, TestCaseWithFactory):
397405
398 for build_id in build_ids:406 for build_id in build_ids:
399 self.assertIsNone(getUtility(IOCIRecipeBuildSet).getByID(build_id))407 self.assertIsNone(getUtility(IOCIRecipeBuildSet).getByID(build_id))
408 for push_rule_id in push_rule_ids:
409 self.assertIsNone(
410 getUtility(IOCIPushRuleSet).getByID(push_rule_id))
400411
401 def test_related_webhooks_deleted(self):412 def test_related_webhooks_deleted(self):
402 owner = self.factory.makePerson()413 owner = self.factory.makePerson()