Merge lp:~wgrant/launchpad/bug548-db-2-tests into lp:launchpad/db-devel

Proposed by William Grant
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 10177
Proposed branch: lp:~wgrant/launchpad/bug548-db-2-tests
Merge into: lp:launchpad/db-devel
Prerequisite: lp:~gary/launchpad/bug548-db-2-tests
Diff against target: 495 lines (+139/-96)
6 files modified
database/schema/security.cfg (+6/-0)
lib/canonical/widgets/__init__.py (+12/-0)
lib/lp/archivepublisher/tests/publishing-meta-data-files.txt (+1/-3)
lib/lp/archivepublisher/tests/test_dominator.py (+1/-3)
lib/lp/archivepublisher/tests/test_publisher.py (+4/-7)
lib/lp/bugs/doc/bugnotification-sending.txt (+115/-83)
To merge this branch: bzr merge lp:~wgrant/launchpad/bug548-db-2-tests
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+48580@code.launchpad.net

This proposal supersedes a proposal from 2011-02-04.

Commit message

[r=lifeless][no-qa] Add "selfgenerated_bugnotifications" as a global option for people so that we can work on bug 548. Only in the DB at this time, since the actual implementation is not yet done.

Description of the change

This branch fixes lp:~gary/launchpad/bug548-db-2-tests to hopefully not break the test suite.

Creating a person creates a personsettings, so everywhere that can create a person also needs to create a personsettings: I've granted SELECT and INSERT on personsettings to every role that has INSERT on person.

I also reverted some earlier changes to tests to create people as the 'launchpad' user, since the original users now have sufficient privileges.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) :
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 2011-02-04 06:45:00 +0000
3+++ database/schema/security.cfg 2011-02-04 06:45:01 +0000
4@@ -578,6 +578,7 @@
5 public.milestone = SELECT
6 public.packagebugsupervisor = SELECT
7 public.person = SELECT, INSERT, UPDATE
8+public.personsettings = SELECT, INSERT
9 public.personlanguage = SELECT
10 public.product = SELECT, UPDATE
11 public.productseries = SELECT
12@@ -1093,6 +1094,7 @@
13 public.packageselection = SELECT, INSERT, UPDATE
14 public.packaging = SELECT, INSERT, UPDATE
15 public.person = SELECT, INSERT, UPDATE
16+public.personsettings = SELECT, INSERT, UPDATE
17 public.personlanguage = SELECT, INSERT, UPDATE
18 public.pocketchroot = SELECT, INSERT, UPDATE
19 public.pocomment = SELECT, INSERT, UPDATE
20@@ -1211,6 +1213,7 @@
21 public.account = SELECT, INSERT
22 public.accountpassword = SELECT, INSERT
23 public.person = SELECT, INSERT, UPDATE
24+public.personsettings = SELECT, INSERT
25 public.emailaddress = SELECT, INSERT, UPDATE
26 public.teamparticipation = SELECT, INSERT
27 public.teammembership = SELECT
28@@ -1323,6 +1326,7 @@
29 # Announce handling
30 public.account = SELECT, INSERT
31 public.person = SELECT, INSERT
32+public.personsettings = SELECT, INSERT
33 public.emailaddress = SELECT, INSERT
34 public.teamparticipation = SELECT, INSERT
35 public.teammembership = SELECT
36@@ -1763,6 +1767,7 @@
37 public.mailinglist = SELECT, INSERT, UPDATE
38 public.mailinglistsubscription = SELECT, INSERT, UPDATE
39 public.person = SELECT, INSERT, UPDATE
40+public.personsettings = SELECT, INSERT
41 public.teammembership = SELECT, INSERT, UPDATE
42 public.teamparticipation = SELECT, INSERT, UPDATE
43
44@@ -1944,6 +1949,7 @@
45 groups=script
46 public.account = SELECT, INSERT, UPDATE
47 public.person = SELECT, INSERT
48+public.personsettings = SELECT, INSERT
49 public.product = SELECT, INSERT, UPDATE
50 public.productseries = SELECT, INSERT
51 public.productlicense = SELECT, INSERT
52
53=== added directory 'lib/canonical/widgets'
54=== added file 'lib/canonical/widgets/__init__.py'
55--- lib/canonical/widgets/__init__.py 1970-01-01 00:00:00 +0000
56+++ lib/canonical/widgets/__init__.py 2011-02-02 21:39:04 +0000
57@@ -0,0 +1,12 @@
58+# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
59+# GNU Affero General Public License version 3 (see the file LICENSE).
60+
61+# This is a stub to keep canonical.shipit operational. this module
62+# can delete when shipit is independent.
63+
64+from lp.app.widgets.itemswidgets import (
65+ CheckBoxMatrixWidget,
66+ LabeledMultiCheckBoxWidget,
67+ )
68+
69+
70
71=== modified file 'lib/lp/archivepublisher/tests/publishing-meta-data-files.txt'
72--- lib/lp/archivepublisher/tests/publishing-meta-data-files.txt 2011-02-04 06:45:00 +0000
73+++ lib/lp/archivepublisher/tests/publishing-meta-data-files.txt 2010-12-22 20:46:21 +0000
74@@ -17,11 +17,9 @@
75 >>> from lp.soyuz.enums import PackageUploadCustomFormat
76 >>> from lp.soyuz.interfaces.publishing import PackagePublishingPocket
77 >>> from lp.soyuz.model.queue import PackageUploadCustom
78- >>> from lp.testing.dbuser import lp_dbuser
79
80 >>> bat = getUtility(IDistributionSet)['ubuntutest']['breezy-autotest']
81- >>> with lp_dbuser():
82- ... ppa = factory.makeArchive(distribution=bat.distribution)
83+ >>> ppa = factory.makeArchive(distribution=bat.distribution)
84 >>> package_upload = bat.createQueueEntry(
85 ... pocket=PackagePublishingPocket.RELEASE, changesfilename="test",
86 ... changesfilecontent="test",
87
88=== modified file 'lib/lp/archivepublisher/tests/test_dominator.py'
89--- lib/lp/archivepublisher/tests/test_dominator.py 2011-02-04 06:45:00 +0000
90+++ lib/lp/archivepublisher/tests/test_dominator.py 2010-10-17 13:35:20 +0000
91@@ -13,7 +13,6 @@
92 from lp.registry.interfaces.series import SeriesStatus
93 from lp.soyuz.enums import PackagePublishingStatus
94 from lp.soyuz.tests.test_publishing import TestNativePublishingBase
95-from lp.testing.dbuser import lp_dbuser
96
97
98 class TestDominator(TestNativePublishingBase):
99@@ -117,8 +116,7 @@
100 in an AssertionError), and shouldn't be directly considered for
101 superseding either.
102 """
103- with lp_dbuser():
104- ppa = self.factory.makeArchive()
105+ ppa = self.factory.makeArchive()
106 foo_10_source, foo_10_binaries = self.createSourceAndBinaries(
107 '1.0', with_debug=True, archive=ppa)
108 foo_11_source, foo_11_binaries = self.createSourceAndBinaries(
109
110=== modified file 'lib/lp/archivepublisher/tests/test_publisher.py'
111--- lib/lp/archivepublisher/tests/test_publisher.py 2011-02-04 06:45:00 +0000
112+++ lib/lp/archivepublisher/tests/test_publisher.py 2010-12-19 22:47:25 +0000
113@@ -50,7 +50,6 @@
114 IArchiveSet,
115 )
116 from lp.soyuz.tests.test_publishing import TestNativePublishingBase
117-from lp.testing.dbuser import lp_dbuser
118
119
120 class TestPublisherBase(TestNativePublishingBase):
121@@ -476,8 +475,7 @@
122 # status of DELETING.
123 ubuntu = getUtility(IDistributionSet)['ubuntu']
124
125- with lp_dbuser():
126- archive = self.factory.makeArchive()
127+ archive = self.factory.makeArchive()
128 old_num_pending_archives = ubuntu.getPendingPublicationPPAs().count()
129 archive.status = ArchiveStatus.DELETING
130 new_num_pending_archives = ubuntu.getPendingPublicationPPAs().count()
131@@ -1041,10 +1039,9 @@
132 def testHtaccessForPrivatePPA(self):
133 # A htaccess file is created for new private PPA's.
134
135- with lp_dbuser():
136- ppa = self.factory.makeArchive(
137- distribution=self.ubuntutest, private=True)
138- ppa.buildd_secret = "geheim"
139+ ppa = self.factory.makeArchive(
140+ distribution=self.ubuntutest, private=True)
141+ ppa.buildd_secret = "geheim"
142
143 # Setup the publisher for it and publish its repository.
144 archive_publisher = getPublisher(ppa, [], self.logger)
145
146=== modified file 'lib/lp/bugs/doc/bugnotification-sending.txt'
147--- lib/lp/bugs/doc/bugnotification-sending.txt 2011-02-04 06:45:00 +0000
148+++ lib/lp/bugs/doc/bugnotification-sending.txt 2011-02-04 06:45:01 +0000
149@@ -30,9 +30,20 @@
150 ... print email_notification.get_payload(decode=True)
151 ... print "-" * 70
152
153-We'll also import a helper function to help us with database users.
154-
155- >>> from lp.testing.dbuser import lp_dbuser
156+We'll also define some helper functions to help us with database users.
157+
158+ >>> from canonical.config import config
159+ >>> from canonical.database.sqlbase import commit
160+ >>> from canonical.testing.layers import LaunchpadZopelessLayer
161+
162+ >>> def switch_db_to_launchpad():
163+ ... commit()
164+ ... LaunchpadZopelessLayer.switchDbUser('launchpad')
165+
166+ >>> def switch_db_to_bugnotification():
167+ ... commit()
168+ ... LaunchpadZopelessLayer.switchDbUser(
169+ ... config.malone.bugnotification_dbuser)
170
171 You'll note that we are printing out an X-Launchpad-Message-Rationale
172 header. This header is a simple string that allows people to filter
173@@ -345,13 +356,16 @@
174 ... print member.preferredemail.email
175 marilize@hbd.com
176
177- >>> with lp_dbuser():
178- ... ignored = bug_one.subscribe(shipit_admins, shipit_admins)
179- ... comment = getUtility(IMessageSet).fromText(
180- ... 'subject', 'a comment.', sample_person,
181- ... datecreated=ten_minutes_ago)
182- ... bug_one.addCommentNotification(comment)
183-
184+ >>> switch_db_to_launchpad()
185+ >>> bug_one.subscribe(shipit_admins, shipit_admins)
186+ <...>
187+
188+ >>> comment = getUtility(IMessageSet).fromText(
189+ ... 'subject', 'a comment.', sample_person,
190+ ... datecreated=ten_minutes_ago)
191+ >>> bug_one.addCommentNotification(comment)
192+
193+ >>> switch_db_to_bugnotification()
194 >>> pending_notifications = getUtility(
195 ... IBugNotificationSet).getNotificationsToSend()
196 >>> len(pending_notifications)
197@@ -384,15 +398,17 @@
198 >>> params = CreateBugParams(
199 ... msg=description, owner=sample_person, title='new bug')
200
201- >>> with lp_dbuser():
202- ... new_bug = ubuntu.createBug(params)
203+ >>> switch_db_to_launchpad()
204+ >>> new_bug = ubuntu.createBug(params)
205+ >>> switch_db_to_bugnotification()
206+ >>> flush_notifications()
207
208 If a bug is a duplicate of another bug, a marker gets inserted at the
209 top of the email:
210
211- >>> flush_notifications()
212- >>> with lp_dbuser():
213- ... new_bug.markAsDuplicate(bug_one)
214+ >>> switch_db_to_launchpad()
215+ >>> new_bug.markAsDuplicate(bug_one)
216+ >>> switch_db_to_bugnotification()
217 >>> comment = getUtility(IMessageSet).fromText(
218 ... 'subject', 'a comment.', sample_person,
219 ... datecreated=ten_minutes_ago)
220@@ -458,11 +474,12 @@
221 ... 'Zero-day on Frobulator', 'Woah.', sample_person,
222 ... datecreated=ten_minutes_ago)
223
224- >>> with lp_dbuser():
225- ... sec_vuln_bug = ubuntu.createBug(CreateBugParams(
226+ >>> switch_db_to_launchpad()
227+ >>> sec_vuln_bug = ubuntu.createBug(CreateBugParams(
228 ... msg=sec_vuln_description, owner=sample_person,
229 ... title='Zero-day on Frobulator',
230 ... security_related=True, private=True))
231+ >>> switch_db_to_bugnotification()
232
233 >>> sec_vuln_bug.security_related
234 True
235@@ -713,8 +730,10 @@
236 The tags will be space-separated to allow the list to be wrapped if it
237 gets over-long.
238
239- >>> with lp_dbuser():
240- ... bug_three.tags = [u'layout-test', u'another-tag', u'yet-another']
241+ >>> switch_db_to_launchpad()
242+ >>> bug_three.tags = [u'layout-test', u'another-tag', u'yet-another']
243+
244+ >>> switch_db_to_bugnotification()
245
246 >>> bug_three = getUtility(IBugSet).get(3)
247 >>> for message in trigger_and_get_email_messages(bug_three):
248@@ -724,13 +743,15 @@
249 If we remove the tags from the bug, the X-Launchpad-Bug-Tags header
250 won't be included.
251
252- >>> with lp_dbuser():
253- ... bug_three.tags = []
254+ >>> switch_db_to_launchpad()
255+ >>> bug_three.tags = []
256+ >>> switch_db_to_bugnotification()
257
258 >>> bug_three = getUtility(IBugSet).get(3)
259 >>> for message in trigger_and_get_email_messages(bug_three):
260 ... message.get_all('X-Launchpad-Bug-Tags')
261
262+ >>> switch_db_to_launchpad()
263 >>> #bug_three.unsubscribe(sample_person, sample_person)
264
265
266@@ -750,8 +771,7 @@
267
268 Predictably, private bugs are sent with a slightly different header:
269
270- >>> with lp_dbuser():
271- ... bug_three.setPrivate(True, sample_person)
272+ >>> bug_three.setPrivate(True, sample_person)
273 True
274 >>> bug_three.private
275 True
276@@ -779,8 +799,7 @@
277 The presence of the security flag on a bug is, surprise, denoted by a
278 simple "yes":
279
280- >>> with lp_dbuser():
281- ... bug_three.setSecurityRelated(True)
282+ >>> bug_three.setSecurityRelated(True)
283 True
284 >>> bug_three.security_related
285 True
286@@ -805,9 +824,9 @@
287 >>> foo_bar = getUtility(IPersonSet).getByEmail('foo.bar@canonical.com')
288
289 >>> from lp.bugs.interfaces.bugmessage import IBugMessageSet
290- >>> with lp_dbuser():
291- ... ignored = getUtility(IBugMessageSet).createMessage(
292- ... 'Hungry', bug_three, foo_bar, "Make me a sandwich.")
293+ >>> getUtility(IBugMessageSet).createMessage(
294+ ... 'Hungry', bug_three, foo_bar, "Make me a sandwich.")
295+ <BugMessage ...>
296
297 >>> for message in trigger_and_get_email_messages(bug_three):
298 ... print message.get('X-Launchpad-Bug-Commenters')
299@@ -816,9 +835,9 @@
300 It only lists each user once, no matter how many comments they've
301 made.
302
303- >>> with lp_dbuser():
304- ... ignored = getUtility(IBugMessageSet).createMessage(
305- ... 'Hungry', bug_three, foo_bar, "Make me a sandwich.")
306+ >>> getUtility(IBugMessageSet).createMessage(
307+ ... 'Hungry', bug_three, foo_bar, "Make me a sandwich.")
308+ <BugMessage ...>
309
310 >>> for message in trigger_and_get_email_messages(bug_three):
311 ... print message.get('X-Launchpad-Bug-Commenters')
312@@ -849,58 +868,63 @@
313 Concise Person does not. We'll also create teams and give them members
314 with different verbose_bugnotifications settings.
315
316- >>> with lp_dbuser():
317- ... bug = factory.makeBug(
318- ... product=factory.makeProduct(title='Foo'),
319- ... title='In the beginning, the universe was created. This '
320- ... 'has made a lot of people very angry and has been '
321- ... 'widely regarded as a bad move',
322- ... description="This is a long description of the bug, which "
323- ... "will be automatically wrapped by the BugNotification "
324- ... "machinery. Ain't technology great?")
325- ... verbose_person = factory.makePerson(
326- ... displayname='Verbose Person', email='verbose@example.com')
327- ... verbose_person.verbose_bugnotifications = True
328- ... ignored = bug.subscribe(verbose_person, verbose_person)
329- ... concise_person = factory.makePerson(
330- ... displayname='Concise Person', email='concise@example.com')
331- ... concise_person.verbose_bugnotifications = False
332- ... ignored = bug.subscribe(concise_person, concise_person)
333+ >>> switch_db_to_launchpad()
334+ >>> bug = factory.makeBug(
335+ ... product=factory.makeProduct(title='Foo'),
336+ ... title='In the beginning, the universe was created. This '
337+ ... 'has made a lot of people very angry and has been '
338+ ... 'widely regarded as a bad move',
339+ ... description="This is a long description of the bug, which "
340+ ... "will be automatically wrapped by the BugNotification "
341+ ... "machinery. Ain't technology great?")
342+
343+ >>> verbose_person = factory.makePerson(
344+ ... displayname='Verbose Person', email='verbose@example.com')
345+ >>> verbose_person.verbose_bugnotifications = True
346+ >>> bug.subscribe(verbose_person, verbose_person)
347+ <lp.bugs.model.bugsubscription.BugSubscription ...>
348+
349+ >>> concise_person = factory.makePerson(
350+ ... displayname='Concise Person', email='concise@example.com')
351+ >>> concise_person.verbose_bugnotifications = False
352+ >>> bug.subscribe(concise_person, concise_person)
353+ <lp.bugs.model.bugsubscription.BugSubscription ...>
354
355
356 Concise Team doesn't want verbose notifications, while Concise Team
357 Person, a member, does.
358
359- >>> with lp_dbuser():
360- ... concise_team = factory.makeTeam(
361- ... name='conciseteam', displayname='Concise Team')
362- ... concise_team.verbose_bugnotifications = False
363- ... concise_team_person = factory.makePerson(
364- ... displayname='Concise Team Person',
365- ... email='conciseteam@example.com')
366- ... concise_team_person.verbose_bugnotifications = True
367- ... ignored = concise_team.addMember(
368- ... concise_team_person, concise_team_person)
369- ... ignored = bug.subscribe(concise_team, concise_team_person)
370+ >>> concise_team = factory.makeTeam(
371+ ... name='conciseteam', displayname='Concise Team')
372+ >>> concise_team.verbose_bugnotifications = False
373+ >>> concise_team_person = factory.makePerson(
374+ ... displayname='Concise Team Person',
375+ ... email='conciseteam@example.com')
376+ >>> concise_team_person.verbose_bugnotifications = True
377+ >>> ignored = concise_team.addMember(
378+ ... concise_team_person, concise_team_person)
379+ >>> bug.subscribe(concise_team, concise_team_person)
380+ <lp.bugs.model.bugsubscription.BugSubscription ...>
381
382 Verbose Team wants verbose notifications, while Verbose Team Person, a
383 member, does not.
384
385- >>> with lp_dbuser():
386- ... verbose_team = factory.makeTeam(
387- ... name='verboseteam', displayname='Verbose Team')
388- ... verbose_team.verbose_bugnotifications = True
389- ... verbose_team_person = factory.makePerson(
390- ... displayname='Verbose Team Person',
391- ... email='verboseteam@example.com')
392- ... verbose_team_person.verbose_bugnotifications = False
393- ... ignored = verbose_team.addMember(
394- ... verbose_team_person, verbose_team_person)
395- ... ignored = bug.subscribe(verbose_team, verbose_team_person)
396+ >>> verbose_team = factory.makeTeam(
397+ ... name='verboseteam', displayname='Verbose Team')
398+ >>> verbose_team.verbose_bugnotifications = True
399+ >>> verbose_team_person = factory.makePerson(
400+ ... displayname='Verbose Team Person',
401+ ... email='verboseteam@example.com')
402+ >>> verbose_team_person.verbose_bugnotifications = False
403+ >>> ignored = verbose_team.addMember(
404+ ... verbose_team_person, verbose_team_person)
405+ >>> bug.subscribe(verbose_team, verbose_team_person)
406+ <lp.bugs.model.bugsubscription.BugSubscription ...>
407
408 We'll expire all existing notifications since we're not interested in
409 them:
410
411+ >>> switch_db_to_bugnotification()
412 >>> notifications = getUtility(
413 ... IBugNotificationSet).getNotificationsToSend()
414 >>> len(notifications)
415@@ -1081,6 +1105,8 @@
416 they generated. For now, everyone receives these notifications whether they
417 want them or not. However, we can show that the attribute exists for now.
418
419+ >>> flush_notifications()
420+ >>> switch_db_to_launchpad()
421 >>> verbose_person.selfgenerated_bugnotifications
422 True
423
424@@ -1099,14 +1125,16 @@
425 notification level of the subscription.
426
427 >>> flush_notifications()
428+ >>> switch_db_to_launchpad()
429
430 >>> from lp.bugs.enum import BugNotificationLevel
431 >>> from lp.registry.interfaces.product import IProductSet
432 >>> firefox = getUtility(IProductSet).getByName('firefox')
433 >>> mr_no_privs = getUtility(IPersonSet).getByName('no-priv')
434- >>> with lp_dbuser():
435- ... subscription_no_priv = firefox.addBugSubscription(
436- ... mr_no_privs, mr_no_privs)
437+ >>> subscription_no_priv = firefox.addBugSubscription(
438+ ... mr_no_privs, mr_no_privs)
439+
440+ >>> switch_db_to_bugnotification()
441
442 The notifications generated by addCommentNotification() are sent only to
443 structural subscribers with no filters, or with the notification level
444@@ -1172,9 +1200,10 @@
445
446
447 >>> flush_notifications()
448- >>> with lp_dbuser():
449- ... filter = subscription_no_priv.newBugFilter()
450- ... filter.bug_notification_level = BugNotificationLevel.COMMENTS
451+ >>> switch_db_to_launchpad()
452+ >>> filter = subscription_no_priv.newBugFilter()
453+ >>> filter.bug_notification_level = BugNotificationLevel.COMMENTS
454+ >>> switch_db_to_bugnotification()
455
456 >>> comment = getUtility(IMessageSet).fromText(
457 ... 'subject', 'another comment.', sample_person,
458@@ -1232,8 +1261,9 @@
459 no comment notifications.
460
461 >>> flush_notifications()
462- >>> with lp_dbuser():
463- ... filter.bug_notification_level = BugNotificationLevel.METADATA
464+ >>> switch_db_to_launchpad()
465+ >>> filter.bug_notification_level = BugNotificationLevel.METADATA
466+ >>> switch_db_to_bugnotification()
467
468 >>> comment = getUtility(IMessageSet).fromText(
469 ... 'subject', 'no comment for no-priv.', sample_person,
470@@ -1343,8 +1373,9 @@
471 no notifications created by addChangeNotification().
472
473 >>> flush_notifications()
474- >>> with lp_dbuser():
475- ... filter.bug_notification_level = BugNotificationLevel.LIFECYCLE
476+ >>> switch_db_to_launchpad()
477+ >>> filter.bug_notification_level = BugNotificationLevel.LIFECYCLE
478+ >>> switch_db_to_bugnotification()
479
480 >>> bug_one.addChangeNotification('** Summary changed to: something.',
481 ... sample_person, when=ten_minutes_ago)
482@@ -1402,9 +1433,10 @@
483 after all.
484
485 >>> flush_notifications()
486- >>> with lp_dbuser():
487- ... filter2 = subscription_no_priv.newBugFilter()
488- ... filter2.bug_notification_level = BugNotificationLevel.METADATA
489+ >>> switch_db_to_launchpad()
490+ >>> filter2 = subscription_no_priv.newBugFilter()
491+ >>> filter2.bug_notification_level = BugNotificationLevel.METADATA
492+ >>> switch_db_to_bugnotification()
493
494 >>> bug_one.addChangeNotification('** Summary changed to: whatever.',
495 ... sample_person, when=ten_minutes_ago)

Subscribers

People subscribed via source and target branches

to status/vote changes: