Merge lp:~adeuring/launchpad/bug-333521-allow-mail-to-question-subscribers into lp:launchpad/db-devel

Proposed by Abel Deuring on 2010-04-21
Status: Merged
Merged at revision: not available
Proposed branch: lp:~adeuring/launchpad/bug-333521-allow-mail-to-question-subscribers
Merge into: lp:launchpad/db-devel
Diff against target: 98 lines (+45/-2)
2 files modified
database/schema/security.cfg (+4/-0)
lib/lp/bugs/tests/test_bugnotification.py (+41/-2)
To merge this branch: bzr merge lp:~adeuring/launchpad/bug-333521-allow-mail-to-question-subscribers
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) 2010-04-21 Approve on 2010-04-21
Review via email: mp+23833@code.launchpad.net

Description of the Change

A test run of the bug expiration script (cronscripts/expire-bugtasks.py) ended with an exception, caused by insufficient permissions of the DB user or this script. If a question is linked to a bug, subscribers to the question are notified about bug task status changes, and the DB user "bugnotification" needs access to several tables related to questions, parsons and languages in order to create the notification emails.

This branch adds the missing permissions and a unit test that ensures that the notification mails are properly created.

test: ./bin/test -vvt test_bugnotification

no lint

To post a comment you must log in.
Jeroen T. Vermeulen (jtv) wrote :

IRC notes:
 * No need to login(); pass the email address to the TestCaseWithFactory constructor instead.
 * No need to set up product_owner separately; might as well let makeProduct do that.
 * Don't make your test comparison rely on the ordering of the recipients list.
 * What is a "sub" as mentioned in the test docstring?
 * Don't say "Ensure that" in tests. Ensuring things is what tests do.
 * Don't hard-code persons' names and email addresses when all you want to do is compare for equality.

You've addressed all of these. Thanks for that!

Jeroen

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/schema/security.cfg'
2--- database/schema/security.cfg 2010-04-19 22:16:10 +0000
3+++ database/schema/security.cfg 2010-04-21 09:52:01 +0000
4@@ -1239,6 +1239,7 @@
5 type=user
6 groups=script
7 public.account = SELECT
8+public.answercontact = SELECT
9 public.archive = SELECT
10 public.archivearch = SELECT
11 public.bugnotification = SELECT, INSERT, UPDATE
12@@ -1257,11 +1258,13 @@
13 public.component = SELECT
14 public.packagebugsupervisor = SELECT
15 public.person = SELECT
16+public.personlanguage = SELECT
17 public.product = SELECT
18 public.project = SELECT
19 public.productseries = SELECT
20 public.question = SELECT
21 public.questionbug = SELECT
22+public.questionsubscription = SELECT
23 public.distribution = SELECT
24 public.distributionsourcepackage = SELECT, INSERT, UPDATE
25 public.distroseries = SELECT
26@@ -1279,6 +1282,7 @@
27 public.teamparticipation = SELECT
28 public.validpersoncache = SELECT
29 public.validpersonorteamcache = SELECT
30+public.language = SELECT
31
32 [personnotification]
33 type=user
34
35=== modified file 'lib/lp/bugs/tests/test_bugnotification.py'
36--- lib/lp/bugs/tests/test_bugnotification.py 2009-06-25 00:40:31 +0000
37+++ lib/lp/bugs/tests/test_bugnotification.py 2010-04-21 09:52:01 +0000
38@@ -12,12 +12,15 @@
39
40 from lazr.lifecycle.snapshot import Snapshot
41
42+from canonical.config import config
43 from canonical.launchpad.database import BugNotification
44 from lazr.lifecycle.event import ObjectModifiedEvent
45 from canonical.launchpad.ftests import login
46-from lp.bugs.interfaces.bugtask import BugTaskStatus
47+from lp.bugs.interfaces.bugtask import BugTaskStatus, IUpstreamBugTask
48+from lp.testing import TestCaseWithFactory
49 from lp.testing.factory import LaunchpadObjectFactory
50-from canonical.testing import LaunchpadFunctionalLayer
51+from lp.testing.mail_helpers import pop_notifications
52+from canonical.testing import LaunchpadFunctionalLayer, LaunchpadZopelessLayer
53
54
55 class TestNotificationRecipientsOfPrivateBugs(unittest.TestCase):
56@@ -80,6 +83,42 @@
57 self.assertEqual(notified_people, self.direct_subscribers)
58
59
60+class TestNotificationsSentForBugExpiration(TestCaseWithFactory):
61+ """Ensure that question subscribers are notified about bug expiration."""
62+
63+ layer = LaunchpadZopelessLayer
64+
65+ def setUp(self):
66+ super(TestNotificationsSentForBugExpiration, self).setUp(
67+ user='test@canonical.com')
68+ # We need a product, a bug for this product, a question linked
69+ # to the bug and a subscriber.
70+ self.product = self.factory.makeProduct()
71+ self.bug = self.factory.makeBug(product=self.product)
72+ question = self.factory.makeQuestion(target=self.product)
73+ self.subscriber = self.factory.makePerson()
74+ question.subscribe(self.subscriber)
75+ question.linkBug(self.bug)
76+ # Flush pending notifications for question creation.
77+ pop_notifications()
78+ self.layer.switchDbUser(config.malone.expiration_dbuser)
79+
80+ def test_notifications_for_question_subscribers(self):
81+ # Ensure that notifications are sent to subscribers of a
82+ # question linked to the expired bug.
83+ bugtask = self.bug.default_bugtask
84+ bugtask_before_modification = Snapshot(
85+ bugtask, providing=IUpstreamBugTask)
86+ bugtask.transitionToStatus(BugTaskStatus.EXPIRED, self.product.owner)
87+ bug_modified = ObjectModifiedEvent(
88+ bugtask, bugtask_before_modification, ["status"])
89+ notify(bug_modified)
90+ self.assertContentEqual(
91+ [self.product.owner.preferredemail.email,
92+ self.subscriber.preferredemail.email],
93+ [mail['To'] for mail in pop_notifications()])
94+
95+
96 def test_suite():
97 """Return the test suite for the tests in this module."""
98 return unittest.TestLoader().loadTestsFromName(__name__)

Subscribers

People subscribed via source and target branches

to status/vote changes: