Merge lp:~jml/launchpad/remove-doAsUser into lp:launchpad

Proposed by Jonathan Lange
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 11179
Proposed branch: lp:~jml/launchpad/remove-doAsUser
Merge into: lp:launchpad
Prerequisite: lp:~jml/launchpad/login-helper-love
Diff against target: 331 lines (+57/-96)
3 files modified
lib/canonical/launchpad/testing/pages.py (+3/-0)
lib/lp/bugs/stories/patches-view/patches-view.txt (+54/-82)
lib/lp/testing/factory.py (+0/-14)
To merge this branch: bzr merge lp:~jml/launchpad/remove-doAsUser
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+30208@code.launchpad.net

Commit message

Remove LaunchpadObjectFactory.doAsUser

Description of the change

This branch builds on the work in login-helper-love and deletes the "doAsUser" helper from the factory. It changes the one test where it was used to instead use some more sensible helpers, and to not rely on obscure sample data for its login methods.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

This looks nice to me. The underlying branch I had some concerns about
that I relayed face to face; I'll try to write them up tomorrow am.

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 'lib/canonical/launchpad/testing/pages.py'
2--- lib/canonical/launchpad/testing/pages.py 2010-07-14 14:11:15 +0000
3+++ lib/canonical/launchpad/testing/pages.py 2010-07-20 15:51:24 +0000
4@@ -1,6 +1,8 @@
5 # Copyright 2009 Canonical Ltd. This software is licensed under the
6 # GNU Affero General Public License version 3 (see the file LICENSE).
7
8+from __future__ import with_statement
9+
10 """Testing infrastructure for page tests."""
11
12 # Stop lint warning about not initializing TestCase parent on
13@@ -785,6 +787,7 @@
14 test.globs['print_tag_with_id'] = print_tag_with_id
15 test.globs['PageTestLayer'] = PageTestLayer
16 test.globs['stop'] = stop
17+ test.globs['with_statement'] = with_statement
18 test.globs['ws_uncache'] = ws_uncache
19
20
21
22=== modified file 'lib/lp/bugs/stories/patches-view/patches-view.txt'
23--- lib/lp/bugs/stories/patches-view/patches-view.txt 2010-05-28 14:53:57 +0000
24+++ lib/lp/bugs/stories/patches-view/patches-view.txt 2010-07-20 15:51:24 +0000
25@@ -7,8 +7,11 @@
26 We have a view listing patches attached to bugs that target a given
27 product. At first, the product is new and has no bugs.
28
29- >>> patchy_product = factory.doAsUser(
30- ... 'foo.bar@canonical.com', factory.makeProduct,
31+ >>> from lp.testing import anonymous_logged_in, with_person_logged_in
32+ >>> with anonymous_logged_in():
33+ ... anybody = factory.makePerson()
34+ >>> with_anybody = with_person_logged_in(anybody)
35+ >>> patchy_product = with_anybody(factory.makeProduct)(
36 ... name='patchy-product-1', displayname="Patchy 1")
37 >>> transaction.commit()
38
39@@ -31,7 +34,8 @@
40
41 >>> from lp.bugs.interfaces.bugtask import (
42 ... BugTaskImportance, BugTaskStatus)
43- >>> def make_bug(
44+ >>> @with_anybody
45+ ... def make_bug(
46 ... title, product, importance=BugTaskImportance.UNDECIDED,
47 ... status=BugTaskStatus.NEW):
48 ... bug = factory.makeBug(title=title, product=product)
49@@ -43,9 +47,7 @@
50 ... transaction.commit()
51 ... return bug
52
53- >>> bug_a = factory.doAsUser(
54- ... 'foo.bar@canonical.com', make_bug,
55- ... title="bug_a title", product=patchy_product)
56+ >>> bug_a = make_bug(title="bug_a title", product=patchy_product)
57 >>> transaction.commit()
58 >>> anon_browser.open(
59 ... 'http://bugs.launchpad.dev/patchy-product-1/+patches')
60@@ -55,8 +57,7 @@
61 After we add a non-patch attachment to that bug, the patches view
62 still shows no patches.
63
64- >>> factory.doAsUser('foo.bar@canonical.com', factory.makeBugAttachment,
65- ... bug=bug_a, is_patch=False)
66+ >>> with_anybody(factory.makeBugAttachment)(bug=bug_a, is_patch=False)
67 <BugAttachment at...
68 >>> transaction.commit()
69 >>> anon_browser.open('http://bugs.launchpad.dev/patchy-product-1/+patches')
70@@ -66,12 +67,10 @@
71 After we add a patch attachment that's one day old, we see it in the
72 patches view.
73
74- >>> patch_submitter = factory.doAsUser(
75- ... 'foo.bar@canonical.com', factory.makePerson,
76+ >>> patch_submitter = with_anybody(factory.makePerson)(
77 ... name="patchy-person", displayname="Patchy Person")
78 >>> transaction.commit()
79- >>> factory.doAsUser(
80- ... 'foo.bar@canonical.com', factory.makeBugAttachment,
81+ >>> with_anybody(factory.makeBugAttachment)(
82 ... comment="comment about patch a",
83 ... filename="patch_a.diff", owner=patch_submitter,
84 ... description="description of patch a", bug=bug_a, is_patch=True)
85@@ -95,69 +94,58 @@
86 After creating some more bugs, with some non-patch and some patch
87 attachments, and various statuses...
88
89- >>> bug_b = factory.doAsUser(
90- ... 'foo.bar@canonical.com', make_bug,
91+ >>> bug_b = make_bug(
92 ... title="bug_b title", product=patchy_product,
93 ... importance=BugTaskImportance.CRITICAL,
94 ... status=BugTaskStatus.CONFIRMED)
95- >>> bug_c = factory.doAsUser(
96- ... 'foo.bar@canonical.com', make_bug,
97+ >>> bug_c = make_bug(
98 ... title="bug_c title", product=patchy_product,
99 ... importance=BugTaskImportance.WISHLIST,
100 ... status=BugTaskStatus.FIXCOMMITTED)
101- >>> bug_d = factory.doAsUser(
102- ... 'foo.bar@canonical.com', make_bug,
103+ >>> bug_d = make_bug(
104 ... title="bug_d title", product=patchy_product,
105 ... importance=BugTaskImportance.WISHLIST,
106 ... status=BugTaskStatus.FIXRELEASED)
107- >>> factory.doAsUser(
108- ... 'foo.bar@canonical.com', factory.makeBugAttachment,
109+ >>> with_anybody(factory.makeBugAttachment)(
110 ... comment="comment about patch b",
111 ... filename="patch_b.diff", owner=patch_submitter,
112 ... description="description of patch b", bug=bug_b, is_patch=True)
113 <BugAttachment at...
114 >>> transaction.commit()
115- >>> factory.doAsUser(
116- ... 'foo.bar@canonical.com', factory.makeBugAttachment,
117+ >>> with_anybody(factory.makeBugAttachment)(
118 ... comment="comment about patch c",
119 ... filename="patch_c.diff", owner=patch_submitter,
120 ... description="description of patch c", bug=bug_b, is_patch=True)
121 <BugAttachment at...
122 >>> transaction.commit()
123- >>> factory.doAsUser(
124- ... 'foo.bar@canonical.com', factory.makeBugAttachment,
125- ... bug=bug_c, is_patch=False)
126+ >>> with_anybody(factory.makeBugAttachment)(bug=bug_c, is_patch=False)
127 <BugAttachment at...
128 >>> transaction.commit()
129- >>> factory.doAsUser(
130- ... 'foo.bar@canonical.com', factory.makeBugAttachment,
131+ >>> with_anybody(factory.makeBugAttachment)(
132 ... comment="comment about patch d",
133 ... filename="patch_d.diff", owner=patch_submitter,
134 ... description="description of patch d", bug=bug_c, is_patch=True)
135 <BugAttachment at...
136 >>> transaction.commit()
137- >>> factory.doAsUser(
138- ... 'foo.bar@canonical.com', factory.makeBugAttachment,
139+ >>> with_anybody(factory.makeBugAttachment)(
140 ... comment="comment about patch e",
141 ... filename="patch_e.diff", owner=patch_submitter,
142 ... description="description of patch e", bug=bug_c, is_patch=True)
143 <BugAttachment at...
144 >>> transaction.commit()
145- >>> factory.doAsUser(
146- ... 'foo.bar@canonical.com', factory.makeBugAttachment,
147+ >>> with_anybody(factory.makeBugAttachment)(
148 ... comment="comment about patch f",
149 ... filename="patch_f.diff", owner=patch_submitter,
150 ... description="description of patch f", bug=bug_c, is_patch=True)
151 <BugAttachment at...
152 >>> transaction.commit()
153- >>> factory.doAsUser(
154- ... 'foo.bar@canonical.com', factory.makeBugAttachment,
155+ >>> with_anybody(factory.makeBugAttachment)(
156 ... comment="comment about patch g",
157 ... filename="patch_g.diff", owner=patch_submitter,
158 ... description="description of patch g", bug=bug_d, is_patch=True)
159 <BugAttachment at...
160 >>> transaction.commit()
161-
162+
163 ...the youngest patch on each bug is visible in the patch report
164 (except for bugs in "Fix Released" state, which aren't shown):
165
166@@ -221,7 +209,8 @@
167
168 >>> from zope.component import getUtility
169 >>> from lp.registry.interfaces.distribution import IDistributionSet
170- >>> def make_bugtask(
171+ >>> @with_anybody
172+ ... def make_bugtask(
173 ... # Meta-factory for making bugtasks.
174 ... #
175 ... # In all instances where a distro is needed, defaults to
176@@ -255,12 +244,8 @@
177 ... if status is not None:
178 ... bugtask.transitionToStatus(status, ubuntu_distro.owner)
179 >>> patchy_product_series = patchy_product.getSeries('trunk')
180- >>> factory.doAsUser(
181- ... 'foo.bar@canonical.com', make_bugtask,
182- ... bug=bug_a, target=patchy_product_series)
183- >>> factory.doAsUser(
184- ... 'foo.bar@canonical.com', make_bugtask,
185- ... bug=bug_c, target=patchy_product_series)
186+ >>> make_bugtask(bug=bug_a, target=patchy_product_series)
187+ >>> make_bugtask(bug=bug_c, target=patchy_product_series)
188 >>> anon_browser.open(
189 ... 'https://bugs.launchpad.dev/patchy-product-1/trunk/+patches')
190 >>> show_patches_view(anon_browser.contents)
191@@ -287,13 +272,13 @@
192 The patches view also works for distributions, and it shows the target
193 package when viewed via a distribution.
194
195- >>> factory.doAsUser(
196- ... 'foo.bar@canonical.com', make_bugtask, bug=bug_a,
197+ >>> make_bugtask(
198+ ... bug=bug_a,
199 ... target='evolution', target_is_spkg_name=True,
200 ... importance=BugTaskImportance.MEDIUM,
201 ... status=BugTaskStatus.FIXCOMMITTED)
202- >>> factory.doAsUser(
203- ... 'foo.bar@canonical.com', make_bugtask, bug=bug_c,
204+ >>> make_bugtask(
205+ ... bug=bug_c,
206 ... target='a52dec', target_is_spkg_name=True,
207 ... importance=BugTaskImportance.HIGH,
208 ... status=BugTaskStatus.TRIAGED)
209@@ -319,20 +304,15 @@
210
211 The patches view works for distro series.
212
213- >>> factory.doAsUser(
214- ... 'foo.bar@canonical.com', make_bugtask, bug=bug_a,
215- ... target='hoary', target_is_distroseries_name=True)
216- >>> factory.doAsUser(
217- ... 'foo.bar@canonical.com', make_bugtask, bug=bug_a,
218- ... target='warty', target_is_distroseries_name=True)
219- >>> factory.doAsUser(
220- ... 'foo.bar@canonical.com', make_bugtask, bug=bug_b,
221- ... target='warty', target_is_distroseries_name=True)
222- >>> factory.doAsUser(
223- ... 'foo.bar@canonical.com', make_bugtask, bug=bug_c,
224- ... target='warty', target_is_distroseries_name=True,
225- ... importance=BugTaskImportance.HIGH,
226- ... status=BugTaskStatus.TRIAGED)
227+ >>> make_bugtask(
228+ ... bug=bug_a, target='hoary', target_is_distroseries_name=True)
229+ >>> make_bugtask(
230+ ... bug=bug_a, target='warty', target_is_distroseries_name=True)
231+ >>> make_bugtask(
232+ ... bug=bug_b, target='warty', target_is_distroseries_name=True)
233+ >>> make_bugtask(
234+ ... bug=bug_c, target='warty', target_is_distroseries_name=True,
235+ ... importance=BugTaskImportance.HIGH, status=BugTaskStatus.TRIAGED)
236
237 >>> anon_browser.open('https://bugs.launchpad.dev/ubuntu/hoary/+patches')
238 >>> show_patches_view(anon_browser.contents)
239@@ -436,15 +416,11 @@
240 thoroughly tested in bugtask-search.txt so here a single structural
241 subscription will be tested.
242
243- >>> from canonical.launchpad.ftests import login, logout
244- >>> project_subscriber = factory.doAsUser(
245- ... 'foo.bar@canonical.com', factory.makePerson,
246+ >>> project_subscriber = with_anybody(factory.makePerson)(
247 ... name="project-subscriber", displayname="Project Subscriber")
248- >>> login('foo.bar@canonical.com')
249- >>> patchy_product.addBugSubscription(project_subscriber,
250- ... project_subscriber)
251+ >>> add_bug_sub = lambda *args: patchy_product.addBugSubscription(*args)
252+ >>> with_anybody(add_bug_sub)(project_subscriber, project_subscriber)
253 <StructuralSubscription at ...>
254- >>> logout()
255 >>> from zope.security.proxy import removeSecurityProxy
256 >>> subscriber_name = removeSecurityProxy(project_subscriber).name
257 >>> anon_browser.open(
258@@ -471,37 +447,33 @@
259 evolution source package for Ubuntu and it is tested that both groups of
260 patches are shown.
261
262- >>> hacky_product = factory.doAsUser(
263- ... 'foo.bar@canonical.com', factory.makeProduct,
264+ >>> hacky_product = with_anybody(factory.makeProduct)(
265 ... name='hacky-product', displayname="Hacky Product")
266 >>> transaction.commit()
267- >>> bug_e = factory.doAsUser(
268- ... 'foo.bar@canonical.com', make_bug,
269+ >>> bug_e = make_bug(
270 ... title="bug_e is for evolution", product=hacky_product,
271 ... importance=BugTaskImportance.WISHLIST,
272 ... status=BugTaskStatus.NEW)
273- >>> factory.doAsUser(
274- ... 'foo.bar@canonical.com', factory.makeBugAttachment,
275+ >>> with_anybody(factory.makeBugAttachment)(
276 ... comment="comment about patch h",
277 ... filename="patch_h.diff", owner=patch_submitter,
278 ... description="patch h is for helping", bug=bug_e, is_patch=True)
279 <BugAttachment at...
280- >>> factory.doAsUser(
281- ... 'foo.bar@canonical.com', make_bugtask, bug=bug_e,
282+ >>> make_bugtask(
283+ ... bug=bug_e,
284 ... target='evolution', target_is_spkg_name=True,
285 ... importance=BugTaskImportance.MEDIUM,
286 ... status=BugTaskStatus.TRIAGED)
287 >>> transaction.commit()
288- >>> from canonical.launchpad.ftests import login, logout
289 >>> from zope.component import getUtility
290 >>> from lp.registry.interfaces.distribution import IDistributionSet
291- >>> login('foo.bar@canonical.com')
292- >>> ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
293- >>> ubuntu_evolution = ubuntu.getSourcePackage("evolution")
294- >>> ubuntu_evolution.addBugSubscription(project_subscriber,
295- ... project_subscriber)
296- <StructuralSubscription at ...>
297- >>> logout()
298+ >>> @with_anybody
299+ ... def add_evolution_subscriber():
300+ ... ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
301+ ... ubuntu_evolution = ubuntu.getSourcePackage("evolution")
302+ ... ubuntu_evolution.addBugSubscription(
303+ ... project_subscriber, project_subscriber)
304+ >>> add_evolution_subscriber()
305 >>> from zope.security.proxy import removeSecurityProxy
306 >>> subscriber_name = removeSecurityProxy(project_subscriber).name
307 >>> anon_browser.open(
308
309=== modified file 'lib/lp/testing/factory.py'
310--- lib/lp/testing/factory.py 2010-07-17 18:59:08 +0000
311+++ lib/lp/testing/factory.py 2010-07-20 15:51:24 +0000
312@@ -333,20 +333,6 @@
313 for any other required objects.
314 """
315
316- def doAsUser(self, user, factory_method, **factory_args):
317- """Perform a factory method while temporarily logged in as a user.
318-
319- :param user: The user to log in as, and then to log out from.
320- :param factory_method: The factory method to invoke while logged in.
321- :param factory_args: Keyword arguments to pass to factory_method.
322- """
323- login(user)
324- try:
325- result = factory_method(**factory_args)
326- finally:
327- logout()
328- return result
329-
330 def loginAsAnyone(self):
331 """Log in as an arbitrary person.
332