Merge lp:~brian-murray/launchpad/x-launchpad-bug-modifier-follow-on into lp:launchpad

Proposed by Brian Murray
Status: Merged
Approved by: Māris Fogels
Approved revision: no longer in the source branch.
Merged at revision: 11379
Proposed branch: lp:~brian-murray/launchpad/x-launchpad-bug-modifier-follow-on
Merge into: lp:launchpad
Diff against target: 77 lines (+61/-1)
2 files modified
lib/lp/bugs/mail/tests/test_bug_task_modification.py (+60/-0)
lib/lp/bugs/scripts/bugnotification.py (+1/-1)
To merge this branch: bzr merge lp:~brian-murray/launchpad/x-launchpad-bug-modifier-follow-on
Reviewer Review Type Date Requested Status
Māris Fogels (community) Approve
Review via email: mp+32900@code.launchpad.net

Commit message

Add in X-Launchpad-Bug-Modifier header, identifying the event creator's display name and name, to bug mail generated by bugnotification.py.

Description of the change

This branch is a follows up a merge proposal, https://code.edge.launchpad.net/~brian-murray/launchpad/bug-605340/+merge/31221, to add an X-Launchpad-Bug-Modifier header to emails sent regarding bug changes. That branch was supposed to fix bug 605340, however it does this incompletely by only adding the header when bug details are sent to new subscribers. This branch adds person to BugNotificationBuilder call in lp/bugs/scripts/bugnotification.py so that all bug mails will have the X-Launchpad-Bug-Modifier header.

I also added in a test, test_bug_task_modification.py, to confirm that the header appears when a bug's status is changed.

== Tests ==

bin/test -cvv -t bugnotification-email -t test_bug_task_modification

To post a comment you must log in.
Revision history for this message
Māris Fogels (mars) wrote :

Hi Brian,

These changes look good. I just had a few questions:

 * On line 28 of the diff, there are brackets around ObjectModifiedEvent. I assume that is a left-over from earlier imports?
 * The docstring for TestModificationNotification should either be made more general, or the class name should be made more specific to match the docstring.
 * Is the sanity check for the stub mailer on line 50 of the diff necessary? I would hope the TestCase object reliably cleans up the stub mailer for you.

I think the branch looks good. r=mars with the tweaks I listed above.

Maris

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'lib/lp/bugs/mail/tests/test_bug_task_modification.py'
--- lib/lp/bugs/mail/tests/test_bug_task_modification.py 1970-01-01 00:00:00 +0000
+++ lib/lp/bugs/mail/tests/test_bug_task_modification.py 2010-08-17 19:22:48 +0000
@@ -0,0 +1,60 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Test for emails sent after bug task modification."""
5
6from unittest import TestLoader
7
8import transaction
9
10from zope.component import getUtility
11from zope.interface import providedBy
12from zope.event import notify
13
14from canonical.testing import DatabaseFunctionalLayer
15from canonical.launchpad.database import BugNotification
16from canonical.launchpad.webapp.interfaces import ILaunchBag
17
18
19from lp.bugs.interfaces.bugtask import BugTaskStatus
20from lp.bugs.scripts.bugnotification import construct_email_notifications
21from lp.testing import TestCaseWithFactory
22
23from lazr.lifecycle.event import ObjectModifiedEvent
24from lazr.lifecycle.snapshot import Snapshot
25
26
27class TestModificationNotification(TestCaseWithFactory):
28 """Test email notifications when a bug task is modified."""
29
30 layer = DatabaseFunctionalLayer
31
32 def setUp(self):
33 # Run the tests as a logged-in user.
34 super(TestModificationNotification, self).setUp(
35 user='test@canonical.com')
36 self.user = getUtility(ILaunchBag).user
37 self.product = self.factory.makeProduct(owner=self.user)
38 self.bug = self.factory.makeBug(product=self.product)
39 self.bug_task = self.bug.getBugTask(self.product)
40 self.bug_task_before_modification = Snapshot(self.bug_task,
41 providing=providedBy(self.bug_task))
42
43 def test_for_bug_modifier_header(self):
44 """Test X-Launchpad-Bug-Modifier appears when a bug is modified."""
45 self.bug_task.transitionToStatus(BugTaskStatus.CONFIRMED, self.user)
46 notify(ObjectModifiedEvent(
47 self.bug_task, self.bug_task_before_modification,
48 ['status'], user=self.user))
49 transaction.commit()
50 latest_notification = BugNotification.selectFirst(orderBy='-id')
51 notifications, messages = construct_email_notifications(
52 [latest_notification])
53 self.assertEqual(len(notifications), 1,
54 'email notification not created')
55 headers = [msg['X-Launchpad-Bug-Modifier'] for msg in messages]
56 self.assertEqual(len(headers), len(messages))
57
58
59def test_suite():
60 return TestLoader().loadTestsFromName(__name__)
061
=== modified file 'lib/lp/bugs/scripts/bugnotification.py'
--- lib/lp/bugs/scripts/bugnotification.py 2010-06-23 09:36:02 +0000
+++ lib/lp/bugs/scripts/bugnotification.py 2010-08-17 19:22:48 +0000
@@ -111,7 +111,7 @@
111 (email_person, recipient)111 (email_person, recipient)
112 for email_person, recipient in recipients.items()112 for email_person, recipient in recipients.items()
113 if recipient.person.inTeam(comment_syncing_team))113 if recipient.person.inTeam(comment_syncing_team))
114 bug_notification_builder = BugNotificationBuilder(bug)114 bug_notification_builder = BugNotificationBuilder(bug, person)
115 sorted_recipients = sorted(115 sorted_recipients = sorted(
116 recipients.items(), key=lambda t: t[0].preferredemail.email)116 recipients.items(), key=lambda t: t[0].preferredemail.email)
117 for email_person, recipient in sorted_recipients:117 for email_person, recipient in sorted_recipients: