Merge lp:~thumper/launchpad/needs-review-event into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: no longer in the source branch.
Merged at revision: 11759
Proposed branch: lp:~thumper/launchpad/needs-review-event
Merge into: lp:launchpad
Prerequisite: lp:~thumper/launchpad/rename-created-job
Diff against target: 221 lines (+49/-19)
8 files modified
lib/lp/code/configure.zcml (+4/-0)
lib/lp/code/event/branchmergeproposal.py (+7/-0)
lib/lp/code/interfaces/event.py (+5/-0)
lib/lp/code/model/branch.py (+6/-1)
lib/lp/code/model/tests/test_branchmergeproposal.py (+9/-7)
lib/lp/code/model/tests/test_codereviewcomment.py (+1/-1)
lib/lp/code/subscribers/branchmergeproposal.py (+8/-0)
lib/lp/testing/__init__.py (+9/-10)
To merge this branch: bzr merge lp:~thumper/launchpad/needs-review-event
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+38686@code.launchpad.net

Commit message

Adds a new event for the needs review email.

Description of the change

This branch adds a new event for the needs review email. No functionality change at all, and the behaviour is exactly the same for now.

test_branchmergeproposal

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Nicely straightforward.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/configure.zcml'
2--- lib/lp/code/configure.zcml 2010-10-18 03:43:08 +0000
3+++ lib/lp/code/configure.zcml 2010-10-18 03:43:09 +0000
4@@ -353,6 +353,10 @@
5 handler="lp.code.subscribers.branchmergeproposal.merge_proposal_created"/>
6 <subscriber
7 for="lp.code.interfaces.branchmergeproposal.IBranchMergeProposal
8+ lp.code.interfaces.event.IBranchMergeProposalNeedsReviewEvent"
9+ handler="lp.code.subscribers.branchmergeproposal.merge_proposal_needs_review"/>
10+ <subscriber
11+ for="lp.code.interfaces.branchmergeproposal.IBranchMergeProposal
12 lazr.lifecycle.interfaces.IObjectModifiedEvent"
13 handler="lp.code.subscribers.branchmergeproposal.merge_proposal_modified"/>
14 <subscriber
15
16=== modified file 'lib/lp/code/event/branchmergeproposal.py'
17--- lib/lp/code/event/branchmergeproposal.py 2010-03-17 07:54:15 +0000
18+++ lib/lp/code/event/branchmergeproposal.py 2010-10-18 03:43:09 +0000
19@@ -7,6 +7,7 @@
20
21 __metaclass__ = type
22 __all__ = [
23+ 'BranchMergeProposalNeedsReviewEvent',
24 'BranchMergeProposalStatusChangeEvent',
25 'NewBranchMergeProposalEvent',
26 'NewCodeReviewCommentEvent',
27@@ -17,6 +18,7 @@
28 from zope.interface import implements
29
30 from lp.code.interfaces.event import (
31+ IBranchMergeProposalNeedsReviewEvent,
32 IBranchMergeProposalStatusChangeEvent,
33 INewBranchMergeProposalEvent,
34 INewCodeReviewCommentEvent,
35@@ -41,6 +43,11 @@
36 implements(INewBranchMergeProposalEvent)
37
38
39+class BranchMergeProposalNeedsReviewEvent(ObjectEvent):
40+ """The merge proposal has moved from work in progress to needs reivew."""
41+ implements(IBranchMergeProposalNeedsReviewEvent)
42+
43+
44 class ReviewerNominatedEvent(ObjectEvent):
45 """A reviewer has been nominated."""
46 implements(IReviewerNominatedEvent)
47
48=== modified file 'lib/lp/code/interfaces/event.py'
49--- lib/lp/code/interfaces/event.py 2010-03-17 07:54:15 +0000
50+++ lib/lp/code/interfaces/event.py 2010-10-18 03:43:09 +0000
51@@ -6,6 +6,7 @@
52 __metaclass__ = type
53 __all__ = [
54 'IBranchMergeProposalStatusChangeEvent',
55+ 'IBranchMergeProposalNeedsReviewEvent',
56 'INewBranchMergeProposalEvent',
57 'INewCodeReviewCommentEvent',
58 'IReviewerNominatedEvent',
59@@ -34,3 +35,7 @@
60
61 class INewCodeReviewCommentEvent(IObjectEvent):
62 """A new comment has been added to the merge proposal."""
63+
64+
65+class IBranchMergeProposalNeedsReviewEvent(IObjectEvent):
66+ """The merge proposal has moved from work in progress to needs reivew."""
67
68=== modified file 'lib/lp/code/model/branch.py'
69--- lib/lp/code/model/branch.py 2010-10-07 22:46:08 +0000
70+++ lib/lp/code/model/branch.py 2010-10-18 03:43:09 +0000
71@@ -83,7 +83,10 @@
72 CannotDeleteBranch,
73 InvalidBranchMergeProposal,
74 )
75-from lp.code.event.branchmergeproposal import NewBranchMergeProposalEvent
76+from lp.code.event.branchmergeproposal import (
77+ BranchMergeProposalNeedsReviewEvent,
78+ NewBranchMergeProposalEvent,
79+ )
80 from lp.code.interfaces.branch import (
81 BzrIdentityMixin,
82 DEFAULT_BRANCH_STATUS_IN_LISTING,
83@@ -434,6 +437,8 @@
84 reviewer, registrant, review_type, _notify_listeners=False)
85
86 notify(NewBranchMergeProposalEvent(bmp))
87+ notify(BranchMergeProposalNeedsReviewEvent(bmp))
88+
89 return bmp
90
91 def _createMergeProposal(
92
93=== modified file 'lib/lp/code/model/tests/test_branchmergeproposal.py'
94--- lib/lp/code/model/tests/test_branchmergeproposal.py 2010-10-18 03:43:08 +0000
95+++ lib/lp/code/model/tests/test_branchmergeproposal.py 2010-10-18 03:43:09 +0000
96@@ -50,6 +50,7 @@
97 WrongBranchMergeProposal,
98 )
99 from lp.code.event.branchmergeproposal import (
100+ BranchMergeProposalNeedsReviewEvent,
101 NewBranchMergeProposalEvent,
102 NewCodeReviewCommentEvent,
103 ReviewerNominatedEvent,
104@@ -645,12 +646,12 @@
105 merge_proposal = self.factory.makeBranchMergeProposal()
106 commenter = self.factory.makePerson()
107 login_person(commenter)
108- result, event = self.assertNotifies(
109+ result, events = self.assertNotifies(
110 NewCodeReviewCommentEvent,
111 merge_proposal.createComment,
112 owner=commenter,
113 subject='A review.')
114- self.assertEqual(result, event.object)
115+ self.assertEqual(result, events[0].object)
116
117 def test_notify_on_nominate_suppressed_if_requested(self):
118 # Ensure that the notification is supressed if the notify listeners
119@@ -758,10 +759,11 @@
120 target_branch = self.factory.makeProductBranch(
121 product=source_branch.product)
122 registrant = self.factory.makePerson()
123- result, event = self.assertNotifies(
124- NewBranchMergeProposalEvent,
125+ result, events = self.assertNotifies(
126+ [NewBranchMergeProposalEvent,
127+ BranchMergeProposalNeedsReviewEvent],
128 source_branch.addLandingTarget, registrant, target_branch)
129- self.assertEqual(result, event.object)
130+ self.assertEqual(result, events[0].object)
131
132 def test_getNotificationRecipients(self):
133 """Ensure that recipients can be added/removed with subscribe"""
134@@ -1333,12 +1335,12 @@
135 merge_proposal = self.factory.makeBranchMergeProposal()
136 login_person(merge_proposal.source_branch.owner)
137 reviewer = self.factory.makePerson()
138- result, event = self.assertNotifies(
139+ result, events = self.assertNotifies(
140 ReviewerNominatedEvent,
141 merge_proposal.nominateReviewer,
142 reviewer=reviewer,
143 registrant=merge_proposal.source_branch.owner)
144- self.assertEqual(result, event.object)
145+ self.assertEqual(result, events[0].object)
146
147 def test_notify_on_nominate_suppressed_if_requested(self):
148 # Ensure that a notification is suppressed if notify listeners is set
149
150=== modified file 'lib/lp/code/model/tests/test_codereviewcomment.py'
151--- lib/lp/code/model/tests/test_codereviewcomment.py 2010-10-04 19:50:45 +0000
152+++ lib/lp/code/model/tests/test_codereviewcomment.py 2010-10-18 03:43:09 +0000
153@@ -83,7 +83,7 @@
154 self.assertEqual('Re: Message subject', reply.message.subject)
155
156 def test_createNoParentComment(self):
157- comment = self.bmp.createComment(
158+ self.bmp.createComment(
159 self.submitter, 'Message subject', 'Message content')
160 new_comment = self.bmp.createComment(
161 self.reviewer, 'New subject', 'New content',
162
163=== modified file 'lib/lp/code/subscribers/branchmergeproposal.py'
164--- lib/lp/code/subscribers/branchmergeproposal.py 2010-10-18 03:43:08 +0000
165+++ lib/lp/code/subscribers/branchmergeproposal.py 2010-10-18 03:43:09 +0000
166@@ -27,6 +27,14 @@
167 Also create a job to email the subscribers about the new proposal.
168 """
169 getUtility(IUpdatePreviewDiffJobSource).create(merge_proposal)
170+
171+
172+def merge_proposal_needs_review(merge_proposal, event):
173+ """A new merge proposal needs a review.
174+
175+ This event is raised when the proposal moves from work in progress to
176+ needs review.
177+ """
178 getUtility(IMergeProposalNeedsReviewEmailJobSource).create(
179 merge_proposal)
180
181
182=== modified file 'lib/lp/testing/__init__.py'
183--- lib/lp/testing/__init__.py 2010-10-17 21:21:07 +0000
184+++ lib/lp/testing/__init__.py 2010-10-18 03:43:09 +0000
185@@ -357,27 +357,26 @@
186 verifyClass(interface, cls),
187 "%r does not correctly implement %r." % (cls, interface))
188
189- def assertNotifies(self, event_type, callable_obj, *args, **kwargs):
190+ def assertNotifies(self, event_types, callable_obj, *args, **kwargs):
191 """Assert that a callable performs a given notification.
192
193- :param event_type: The type of event that notification is expected
194- for.
195+ :param event_type: One or more event types that notification is
196+ expected for.
197 :param callable_obj: The callable to call.
198 :param *args: The arguments to pass to the callable.
199 :param **kwargs: The keyword arguments to pass to the callable.
200 :return: (result, event), where result was the return value of the
201 callable, and event is the event emitted by the callable.
202 """
203+ if not isinstance(event_types, (list, tuple)):
204+ event_types = [event_types]
205 result, events = capture_events(callable_obj, *args, **kwargs)
206 if len(events) == 0:
207 raise AssertionError('No notification was performed.')
208- elif len(events) > 1:
209- raise AssertionError('Too many (%d) notifications performed.'
210- % len(events))
211- elif not isinstance(events[0], event_type):
212- raise AssertionError('Wrong event type: %r (expected %r).' %
213- (events[0], event_type))
214- return result, events[0]
215+ self.assertEqual(len(event_types), len(events))
216+ for index, expected in enumerate(event_types):
217+ self.assertIsInstance(events[index], expected)
218+ return result, events
219
220 def assertNoNotification(self, callable_obj, *args, **kwargs):
221 """Assert that no notifications are generated by the callable.