Merge lp:~rockstar/launchpad/ihasrecipes into lp:launchpad

Proposed by Paul Hummer
Status: Merged
Approved by: Brad Crittenden
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~rockstar/launchpad/ihasrecipes
Merge into: lp:launchpad
Prerequisite: lp:~abentley/launchpad/recipe-index
Diff against target: 152 lines (+76/-5)
6 files modified
lib/lp/code/configure.zcml (+3/-2)
lib/lp/code/interfaces/branch.py (+3/-1)
lib/lp/code/interfaces/hasrecipes.py (+19/-0)
lib/lp/code/interfaces/sourcepackagerecipe.py (+1/-2)
lib/lp/code/model/branch.py (+12/-0)
lib/lp/code/model/tests/test_hasrecipes.py (+38/-0)
To merge this branch: bzr merge lp:~rockstar/launchpad/ihasrecipes
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+22890@code.launchpad.net

Description of the change

This branch creates an IHasRecipes interface and implements it for IBranch. This is needed for the recipe listing that exist in a followup branch. It's pretty straightforward, and small for a reason.

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Nice branch Paul. Looks like you have one c-n-p error:

s/test_branch_implements_hasbranches/test_branch_implements_hasrecipes/

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'lib/canonical/launchpad/apidoc'
2=== modified file 'lib/lp/code/configure.zcml'
3--- lib/lp/code/configure.zcml 2010-04-06 21:21:01 +0000
4+++ lib/lp/code/configure.zcml 2010-04-06 21:21:07 +0000
5@@ -496,11 +496,12 @@
6 getUpgradeFormat
7 isBranchMergeable
8 visibleByUser
9+ getRecipes
10 "/>
11 <require
12 permission="launchpad.Edit"
13- attributes="destroySelf destroySelfBreakReferences setPrivate
14- setOwner setTarget requestUpgrade"
15+ attributes="destroySelf destroySelfBreakReferences setPrivate
16+ setOwner setTarget requestUpgrade"
17 set_attributes="name url mirror_status_message
18 description lifecycle_status
19 last_mirrored last_mirrored_id last_mirror_attempt
20
21=== modified file 'lib/lp/code/interfaces/branch.py'
22--- lib/lp/code/interfaces/branch.py 2010-03-25 02:21:15 +0000
23+++ lib/lp/code/interfaces/branch.py 2010-04-06 21:21:07 +0000
24@@ -70,6 +70,7 @@
25 from lp.code.interfaces.branchlookup import IBranchLookup
26 from lp.code.interfaces.branchtarget import IHasBranchTarget
27 from lp.code.interfaces.hasbranches import IHasMergeProposals
28+from lp.code.interfaces.hasrecipes import IHasRecipes
29 from canonical.launchpad.interfaces.launchpad import (
30 ILaunchpadCelebrities, IPrivacy)
31 from lp.registry.interfaces.role import IHasOwner
32@@ -309,7 +310,8 @@
33 """A marker interface to indicate the need to show the branch menu."""
34
35
36-class IBranch(IHasOwner, IPrivacy, IHasBranchTarget, IHasMergeProposals):
37+class IBranch(IHasOwner, IPrivacy, IHasBranchTarget, IHasMergeProposals,
38+ IHasRecipes):
39 """A Bazaar branch."""
40
41 # Mark branches as exported entries for the Launchpad API.
42
43=== added file 'lib/lp/code/interfaces/hasrecipes.py'
44--- lib/lp/code/interfaces/hasrecipes.py 1970-01-01 00:00:00 +0000
45+++ lib/lp/code/interfaces/hasrecipes.py 2010-04-06 21:21:07 +0000
46@@ -0,0 +1,19 @@
47+# Copyright 2010 Canonical Ltd. This software is licensed under the
48+# GNU Affero General Public License version 3 (see the file LICENSE).
49+
50+"""Interface definitions for IHasRecipes."""
51+
52+__metaclass__ = type
53+__all__ = [
54+ 'IHasRecipes',
55+ ]
56+
57+
58+from zope.interface import Attribute, Interface
59+
60+
61+class IHasRecipes(Interface):
62+ """An object that has recipes."""
63+
64+ def getRecipes():
65+ """Returns all recipes associated with the object."""
66
67=== modified file 'lib/lp/code/interfaces/sourcepackagerecipe.py'
68--- lib/lp/code/interfaces/sourcepackagerecipe.py 2010-04-06 21:21:01 +0000
69+++ lib/lp/code/interfaces/sourcepackagerecipe.py 2010-04-06 21:21:07 +0000
70@@ -3,7 +3,6 @@
71
72 # pylint: disable-msg=E0211,E0213
73
74-
75 """Interface of the `SourcePackageRecipe` content type."""
76
77
78@@ -22,7 +21,7 @@
79 from lazr.restful.fields import CollectionField, Reference
80
81 from zope.interface import Attribute, Interface
82-from zope.schema import Bool, Datetime, Object, TextLine, Text
83+from zope.schema import Bool, Datetime, Object, Text, TextLine
84
85 from canonical.launchpad import _
86 from canonical.launchpad.validators.name import name_validator
87
88=== modified file 'lib/lp/code/model/branch.py'
89--- lib/lp/code/model/branch.py 2010-03-11 14:29:15 +0000
90+++ lib/lp/code/model/branch.py 2010-04-06 21:21:07 +0000
91@@ -1065,6 +1065,18 @@
92 user, checked_branches)
93 return can_access
94
95+ def getRecipes(self):
96+ """See `IHasRecipes`."""
97+ from lp.code.model.sourcepackagerecipe import SourcePackageRecipe
98+ from lp.code.model.sourcepackagerecipedata import (
99+ SourcePackageRecipeData)
100+ store = Store.of(self)
101+ return store.find(
102+ SourcePackageRecipe,
103+ SourcePackageRecipe.id ==
104+ SourcePackageRecipeData.sourcepackage_recipe_id,
105+ SourcePackageRecipeData.base_branch == self)
106+
107
108 class DeletionOperation:
109 """Represent an operation to perform as part of branch deletion."""
110
111=== added file 'lib/lp/code/model/tests/test_hasrecipes.py'
112--- lib/lp/code/model/tests/test_hasrecipes.py 1970-01-01 00:00:00 +0000
113+++ lib/lp/code/model/tests/test_hasrecipes.py 2010-04-06 21:21:07 +0000
114@@ -0,0 +1,38 @@
115+# Copyright 2010 Canonical Ltd. This software is licensed under the
116+# GNU Affero General Public License version 3 (see the file LICENSE).
117+
118+"""Tests for classes that implement IHasRecipes."""
119+
120+__metaclass__ = type
121+
122+import unittest
123+
124+from canonical.testing import DatabaseFunctionalLayer
125+from lp.code.interfaces.hasrecipes import IHasRecipes
126+from lp.testing import TestCaseWithFactory
127+
128+
129+class TestIHasRecipes(TestCaseWithFactory):
130+ """Test that the correct objects implement the interface."""
131+
132+ layer = DatabaseFunctionalLayer
133+
134+ def test_branch_implements_hasrecipes(self):
135+ # Branches should implement IHasRecipes.
136+ branch = self.factory.makeBranch()
137+ self.assertProvides(branch, IHasRecipes)
138+
139+ def test_branch_getRecipes(self):
140+ # IBranch.recipes should provide all the SourcePackageRecipes attached
141+ # to that branch.
142+ base_branch = self.factory.makeBranch()
143+ recipe1 = self.factory.makeSourcePackageRecipe(
144+ None, None, None, None, None, None, base_branch)
145+ recipe2 = self.factory.makeSourcePackageRecipe(
146+ None, None, None, None, None, None, base_branch)
147+ recipe_ignored = self.factory.makeSourcePackageRecipe()
148+ self.assertEqual(2, base_branch.getRecipes().count())
149+
150+
151+def test_suite():
152+ return unittest.TestLoader().loadTestsFromName(__name__)