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