Merge lp:~wgrant/launchpad/reconnect_stores-is-a-horrible-person into lp:launchpad
- reconnect_stores-is-a-horrible-person
- Merge into devel
Proposed by
William Grant
Status: | Merged |
---|---|
Approved by: | Robert Collins |
Approved revision: | no longer in the source branch. |
Merged at revision: | 14349 |
Proposed branch: | lp:~wgrant/launchpad/reconnect_stores-is-a-horrible-person |
Merge into: | lp:launchpad |
Diff against target: |
584 lines (+81/-188) 11 files modified
lib/canonical/testing/layers.py (+7/-10) lib/lp/registry/browser/tests/distributionsourcepackage-views.txt (+7/-15) lib/lp/registry/browser/tests/product-portlet-packages-view.txt (+6/-12) lib/lp/registry/browser/tests/test_distroseries.py (+6/-10) lib/lp/registry/tests/test_dsp_vocabularies.py (+9/-16) lib/lp/registry/tests/test_person.py (+23/-44) lib/lp/registry/tests/test_teammembership.py (+3/-8) lib/lp/soyuz/stories/distribution/xx-distribution-packages.txt (+8/-17) lib/lp/soyuz/stories/soyuz/xx-distributionsourcepackagerelease-pages.txt (+4/-7) lib/lp/soyuz/tests/test_publishing.py (+8/-19) lib/lp/testing/storm.py (+0/-30) |
To merge this branch: | bzr merge lp:~wgrant/launchpad/reconnect_stores-is-a-horrible-person |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Robert Collins (community) | Approve | ||
Review via email: mp+82844@code.launchpad.net |
Commit message
[r=lifeless][no-qa] Tests that used reconnect_stores() now use "with dbuser" instead.
Description of the change
Lots of tests in DatabaseFunctio
In addition to replacing the commit/
No longer used except to restore the default DB config, reconnect_stores() no longer overrides. Instead it just resets the config if asked.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lib/canonical/testing/layers.py' |
2 | --- lib/canonical/testing/layers.py 2011-11-03 22:13:25 +0000 |
3 | +++ lib/canonical/testing/layers.py 2011-11-21 05:15:04 +0000 |
4 | @@ -215,18 +215,15 @@ |
5 | store.close() |
6 | |
7 | |
8 | -def reconnect_stores(database_config_section=None): |
9 | +def reconnect_stores(reset=False): |
10 | """Reconnect Storm stores, resetting the dbconfig to its defaults. |
11 | |
12 | After reconnecting, the database revision will be checked to make |
13 | sure the right data is available. |
14 | """ |
15 | disconnect_stores() |
16 | - if database_config_section: |
17 | - section = getattr(config, database_config_section) |
18 | - dbconfig.override( |
19 | - dbuser=getattr(section, 'dbuser', None), |
20 | - isolation_level=getattr(section, 'isolation_level', None)) |
21 | + if reset: |
22 | + dbconfig.reset() |
23 | |
24 | main_store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR) |
25 | assert main_store is not None, 'Failed to reconnect' |
26 | @@ -1353,7 +1350,7 @@ |
27 | @profiled |
28 | def testSetUp(cls): |
29 | # Connect Storm |
30 | - reconnect_stores('launchpad') |
31 | + reconnect_stores(reset=True) |
32 | |
33 | @classmethod |
34 | @profiled |
35 | @@ -1382,7 +1379,7 @@ |
36 | OpStats.resetStats() |
37 | |
38 | # Connect Storm |
39 | - reconnect_stores('launchpad') |
40 | + reconnect_stores(reset=True) |
41 | |
42 | @classmethod |
43 | @profiled |
44 | @@ -1447,7 +1444,7 @@ |
45 | def testSetUp(cls): |
46 | # LaunchpadZopelessLayer takes care of reconnecting the stores |
47 | if not LaunchpadZopelessLayer.isSetUp: |
48 | - reconnect_stores('launchpad') |
49 | + reconnect_stores(reset=True) |
50 | |
51 | @classmethod |
52 | @profiled |
53 | @@ -1480,7 +1477,7 @@ |
54 | def testSetUp(cls): |
55 | # LaunchpadZopelessLayer takes care of reconnecting the stores |
56 | if not LaunchpadZopelessLayer.isSetUp: |
57 | - reconnect_stores('launchpad') |
58 | + reconnect_stores(reset=True) |
59 | |
60 | @classmethod |
61 | @profiled |
62 | |
63 | === modified file 'lib/lp/registry/browser/tests/distributionsourcepackage-views.txt' |
64 | --- lib/lp/registry/browser/tests/distributionsourcepackage-views.txt 2011-08-03 11:00:11 +0000 |
65 | +++ lib/lp/registry/browser/tests/distributionsourcepackage-views.txt 2011-11-21 05:15:04 +0000 |
66 | @@ -132,26 +132,18 @@ |
67 | # Give the creators of the above source packages some soyuz |
68 | # karma for their efforts. |
69 | >>> from lp.registry.model.karma import KarmaCategory |
70 | + >>> from lp.registry.model.karma import KarmaTotalCache |
71 | + >>> from lp.testing.dbuser import dbuser |
72 | >>> soyuz_category = KarmaCategory.byName('soyuz') |
73 | >>> sourcepackagerelease = gedit_nightly_src_breezy.sourcepackagerelease |
74 | >>> gedit_name = sourcepackagerelease.sourcepackagename |
75 | >>> ppa_beta_owner_id = ppa_beta.owner.id |
76 | >>> ppa_nightly_owner_id = ppa_nightly.owner.id |
77 | - >>> transaction.commit() |
78 | - |
79 | - # XXX: Michael Nelson 2009-07-07 bug=396419. Currently there is no |
80 | - # test api call to switchDbUser that works for non-zopeless layers. |
81 | - # When bug 396419 is fixed, we can instead use |
82 | - # DatabaseLayer.switchDbUser() instead of reconnect_stores() |
83 | - >>> from canonical.testing.layers import reconnect_stores |
84 | - >>> reconnect_stores('karmacacheupdater') |
85 | - >>> from lp.registry.model.karma import KarmaTotalCache |
86 | - >>> cache_entry = KarmaTotalCache( |
87 | - ... person=ppa_beta_owner_id, karma_total=200) |
88 | - >>> cache_entry = KarmaTotalCache( |
89 | - ... person=ppa_nightly_owner_id, karma_total=201) |
90 | - >>> transaction.commit() |
91 | - >>> reconnect_stores('launchpad') |
92 | + >>> with dbuser('karma'): |
93 | + ... cache_entry = KarmaTotalCache( |
94 | + ... person=ppa_beta_owner_id, karma_total=200) |
95 | + ... cache_entry = KarmaTotalCache( |
96 | + ... person=ppa_nightly_owner_id, karma_total=201) |
97 | |
98 | # Because our connection has been closed during the reconnect, we |
99 | # need to get the distro and source package again. |
100 | |
101 | === modified file 'lib/lp/registry/browser/tests/product-portlet-packages-view.txt' |
102 | --- lib/lp/registry/browser/tests/product-portlet-packages-view.txt 2011-08-28 08:36:14 +0000 |
103 | +++ lib/lp/registry/browser/tests/product-portlet-packages-view.txt 2011-11-21 05:15:04 +0000 |
104 | @@ -23,21 +23,15 @@ |
105 | >>> from lp.services.log.logger import BufferLogger |
106 | >>> logger = BufferLogger() |
107 | >>> from canonical.config import config |
108 | - >>> from canonical.testing.layers import reconnect_stores |
109 | + >>> from lp.testing.dbuser import dbuser |
110 | >>> def updateCache(): |
111 | ... # Switch to the statistician user who is the only user with |
112 | ... # write permission to the source package cache tables. |
113 | - ... transaction.commit() |
114 | - ... reconnect_stores(config.statistician.dbuser) |
115 | - ... ubuntu = getUtility(ILaunchpadCelebrities).ubuntu |
116 | - ... DistributionSourcePackageCache.updateAll( |
117 | - ... ubuntu, archive=ubuntu.main_archive, log=logger, |
118 | - ... ztm=transaction) |
119 | - ... transaction.commit() |
120 | - ... reconnect_stores('launchpad') |
121 | - ... # Get ubuntu, our product, and the sourcepackage name again |
122 | - ... # since the transaction changed. |
123 | - ... ubuntu = getUtility(ILaunchpadCelebrities).ubuntu |
124 | + ... ubuntu = getUtility(ILaunchpadCelebrities).ubuntu |
125 | + ... with dbuser(config.statistician.dbuser): |
126 | + ... DistributionSourcePackageCache.updateAll( |
127 | + ... ubuntu, archive=ubuntu.main_archive, log=logger, |
128 | + ... ztm=transaction) |
129 | ... product = getUtility(IProductSet)['bingo'] |
130 | ... spn = getUtility(ISourcePackageNameSet)['bingo'] |
131 | ... login(ANONYMOUS) |
132 | |
133 | === modified file 'lib/lp/registry/browser/tests/test_distroseries.py' |
134 | --- lib/lp/registry/browser/tests/test_distroseries.py 2011-11-18 15:25:51 +0000 |
135 | +++ lib/lp/registry/browser/tests/test_distroseries.py 2011-11-21 05:15:04 +0000 |
136 | @@ -28,7 +28,6 @@ |
137 | LessThan, |
138 | Not, |
139 | ) |
140 | -import transaction |
141 | from zope.component import getUtility |
142 | from zope.security.proxy import ( |
143 | ProxyFactory, |
144 | @@ -57,7 +56,6 @@ |
145 | DatabaseFunctionalLayer, |
146 | LaunchpadFunctionalLayer, |
147 | LaunchpadZopelessLayer, |
148 | - reconnect_stores, |
149 | ) |
150 | from lp.app.interfaces.launchpad import ILaunchpadCelebrities |
151 | from lp.archivepublisher.debversion import Version |
152 | @@ -115,6 +113,7 @@ |
153 | TestCaseWithFactory, |
154 | with_celebrity_logged_in, |
155 | ) |
156 | +from lp.testing.dbuser import dbuser |
157 | from lp.testing.fakemethod import FakeMethod |
158 | from lp.testing.matchers import ( |
159 | DocTestMatches, |
160 | @@ -608,14 +607,11 @@ |
161 | # We need to switch to the initializedistroseries user to set the |
162 | # error_description on the given job. Which is a PITA. |
163 | distroseries = job.distroseries |
164 | - transaction.commit() |
165 | - reconnect_stores("initializedistroseries") |
166 | - job = self.job_source.get(distroseries) |
167 | - job.start() |
168 | - job.fail() |
169 | - job.notifyUserError(error) |
170 | - transaction.commit() |
171 | - reconnect_stores('launchpad') |
172 | + with dbuser("initializedistroseries"): |
173 | + job = self.job_source.get(distroseries) |
174 | + job.start() |
175 | + job.fail() |
176 | + job.notifyUserError(error) |
177 | |
178 | def test_initialization_failure_explanation_shown(self): |
179 | # When initialization has failed an explanation of the failure can be |
180 | |
181 | === modified file 'lib/lp/registry/tests/test_dsp_vocabularies.py' |
182 | --- lib/lp/registry/tests/test_dsp_vocabularies.py 2011-10-04 22:00:18 +0000 |
183 | +++ lib/lp/registry/tests/test_dsp_vocabularies.py 2011-11-21 05:15:04 +0000 |
184 | @@ -5,21 +5,17 @@ |
185 | |
186 | __metaclass__ = type |
187 | |
188 | -import transaction |
189 | - |
190 | from zope.component import getUtility |
191 | |
192 | from canonical.launchpad.webapp.vocabulary import IHugeVocabulary |
193 | -from canonical.testing.layers import ( |
194 | - DatabaseFunctionalLayer, |
195 | - reconnect_stores, |
196 | - ) |
197 | +from canonical.testing.layers import DatabaseFunctionalLayer |
198 | from lp.registry.interfaces.distribution import IDistributionSet |
199 | from lp.registry.vocabularies import DistributionSourcePackageVocabulary |
200 | from lp.soyuz.model.distributionsourcepackagecache import ( |
201 | DistributionSourcePackageCache, |
202 | ) |
203 | from lp.testing import TestCaseWithFactory |
204 | +from lp.testing.dbuser import dbuser |
205 | |
206 | |
207 | class TestDistributionSourcePackageVocabulary(TestCaseWithFactory): |
208 | @@ -221,16 +217,13 @@ |
209 | else: |
210 | archive = self.factory.makeArchive( |
211 | distribution=distribution, purpose=archive) |
212 | - transaction.commit() |
213 | - reconnect_stores('statistician') |
214 | - DistributionSourcePackageCache( |
215 | - distribution=dsp.distribution, |
216 | - sourcepackagename=dsp.sourcepackagename, |
217 | - archive=archive, |
218 | - name=package_name, |
219 | - binpkgnames=binary_names) |
220 | - transaction.commit() |
221 | - reconnect_stores('launchpad') |
222 | + with dbuser('statistician'): |
223 | + DistributionSourcePackageCache( |
224 | + distribution=dsp.distribution, |
225 | + sourcepackagename=dsp.sourcepackagename, |
226 | + archive=archive, |
227 | + name=package_name, |
228 | + binpkgnames=binary_names) |
229 | |
230 | def test_searchForTerms_None(self): |
231 | # Searching for nothing gets you that. |
232 | |
233 | === modified file 'lib/lp/registry/tests/test_person.py' |
234 | --- lib/lp/registry/tests/test_person.py 2011-11-10 01:13:44 +0000 |
235 | +++ lib/lp/registry/tests/test_person.py 2011-11-21 05:15:04 +0000 |
236 | @@ -18,6 +18,7 @@ |
237 | from zope.security.interfaces import Unauthorized |
238 | from zope.security.proxy import removeSecurityProxy |
239 | |
240 | +from canonical.config import config |
241 | from canonical.database.sqlbase import cursor |
242 | from canonical.launchpad.database.account import Account |
243 | from canonical.launchpad.database.emailaddress import EmailAddress |
244 | @@ -36,10 +37,7 @@ |
245 | IStore, |
246 | ) |
247 | from canonical.launchpad.testing.pages import LaunchpadWebServiceCaller |
248 | -from canonical.testing.layers import ( |
249 | - DatabaseFunctionalLayer, |
250 | - reconnect_stores, |
251 | - ) |
252 | +from canonical.testing.layers import DatabaseFunctionalLayer |
253 | from lp.answers.model.answercontact import AnswerContact |
254 | from lp.app.interfaces.launchpad import ILaunchpadCelebrities |
255 | from lp.blueprints.model.specification import Specification |
256 | @@ -89,11 +87,8 @@ |
257 | TestCaseWithFactory, |
258 | ) |
259 | from lp.testing._webservice import QueryCollector |
260 | +from lp.testing.dbuser import dbuser |
261 | from lp.testing.matchers import HasQueryCount |
262 | -from lp.testing.storm import ( |
263 | - reload_dsp, |
264 | - reload_object, |
265 | - ) |
266 | from lp.testing.views import create_initialized_view |
267 | |
268 | |
269 | @@ -814,20 +809,17 @@ |
270 | user 'karma'. This invalidates the objects under test so they |
271 | must be retrieved again. |
272 | """ |
273 | - transaction.commit() |
274 | - reconnect_stores('karmacacheupdater') |
275 | - total = 0 |
276 | - # Insert category total for person and project. |
277 | - for category_name, value in category_name_values: |
278 | - category = KarmaCategory.byName(category_name) |
279 | + with dbuser('karma'): |
280 | + total = 0 |
281 | + # Insert category total for person and project. |
282 | + for category_name, value in category_name_values: |
283 | + category = KarmaCategory.byName(category_name) |
284 | + self.cache_manager.new( |
285 | + value, person.id, category.id, product_id=product.id) |
286 | + total += value |
287 | + # Insert total cache for person and project. |
288 | self.cache_manager.new( |
289 | - value, person.id, category.id, product_id=product.id) |
290 | - total += value |
291 | - # Insert total cache for person and project. |
292 | - self.cache_manager.new( |
293 | - total, person.id, None, product_id=product.id) |
294 | - transaction.commit() |
295 | - reconnect_stores('launchpad') |
296 | + total, person.id, None, product_id=product.id) |
297 | |
298 | def _makeKarmaTotalCache(self, person, total): |
299 | """Create a KarmaTotalCache entry. |
300 | @@ -836,11 +828,8 @@ |
301 | user 'karma'. This invalidates the objects under test so they |
302 | must be retrieved again. |
303 | """ |
304 | - transaction.commit() |
305 | - reconnect_stores('karmacacheupdater') |
306 | - KarmaTotalCache(person=person.id, karma_total=total) |
307 | - transaction.commit() |
308 | - reconnect_stores('launchpad') |
309 | + with dbuser('karma'): |
310 | + KarmaTotalCache(person=person.id, karma_total=total) |
311 | |
312 | |
313 | class TestPersonSetMerge(TestCaseWithFactory, KarmaTestMixin): |
314 | @@ -864,13 +853,8 @@ |
315 | |
316 | def _do_merge(self, from_person, to_person, reviewer=None): |
317 | # Perform the merge as the db user that will be used by the jobs. |
318 | - transaction.commit() |
319 | - reconnect_stores('IPersonMergeJobSource') |
320 | - from_person = reload_object(from_person) |
321 | - to_person = reload_object(to_person) |
322 | - if reviewer is not None: |
323 | - reviewer = reload_object(reviewer) |
324 | - self.person_set.merge(from_person, to_person, reviewer=reviewer) |
325 | + with dbuser(config.IPersonMergeJobSource.dbuser): |
326 | + self.person_set.merge(from_person, to_person, reviewer=reviewer) |
327 | return from_person, to_person |
328 | |
329 | def _get_testable_account(self, person, date_created, openid_identifier): |
330 | @@ -884,10 +868,8 @@ |
331 | team = self.factory.makeTeam() |
332 | owner = team.teamowner |
333 | transaction.commit() |
334 | - reconnect_stores('IPersonMergeJobSource') |
335 | - team = reload_object(team) |
336 | - owner = reload_object(owner) |
337 | - self.person_set.delete(team, owner) |
338 | + with dbuser(config.IPersonMergeJobSource.dbuser): |
339 | + self.person_set.delete(team, owner) |
340 | notification_set = getUtility(IPersonNotificationSet) |
341 | notifications = notification_set.getNotificationsToSend() |
342 | self.assertEqual(0, notifications.count()) |
343 | @@ -1101,7 +1083,7 @@ |
344 | self.assertEqual([u'TO', u'FROM'], descriptions) |
345 | self.assertEqual(u'foo-1', recipes[1].name) |
346 | |
347 | - def assertSubscriptionMerges(self, target, reloader=reload_object): |
348 | + def assertSubscriptionMerges(self, target): |
349 | # Given a subscription target, we want to make sure that subscriptions |
350 | # that the duplicate person made are carried over to the merged |
351 | # account. |
352 | @@ -1114,12 +1096,10 @@ |
353 | duplicate, person = self._do_merge(duplicate, person) |
354 | # The merged person has the subscription, and the duplicate person |
355 | # does not. |
356 | - target = reloader(target) |
357 | self.assertTrue(target.getSubscription(person) is not None) |
358 | self.assertTrue(target.getSubscription(duplicate) is None) |
359 | |
360 | - def assertConflictingSubscriptionDeletes(self, target, |
361 | - reloader=reload_object): |
362 | + def assertConflictingSubscriptionDeletes(self, target): |
363 | # Given a subscription target, we want to make sure that subscriptions |
364 | # that the duplicate person made that conflict with existing |
365 | # subscriptions in the merged account are deleted. |
366 | @@ -1135,7 +1115,6 @@ |
367 | self._do_premerge(duplicate, person) |
368 | login_person(person) |
369 | duplicate, person = self._do_merge(duplicate, person) |
370 | - target = reloader(target) |
371 | # The merged person still has the original subscription, as shown |
372 | # by the marker name. |
373 | self.assertEqual( |
374 | @@ -1199,12 +1178,12 @@ |
375 | def test_merge_with_sourcepackage_subscription(self): |
376 | # See comments in assertSubscriptionMerges. |
377 | dsp = self.factory.makeDistributionSourcePackage() |
378 | - self.assertSubscriptionMerges(dsp, reloader=reload_dsp) |
379 | + self.assertSubscriptionMerges(dsp) |
380 | |
381 | def test_merge_with_conflicting_sourcepackage_subscription(self): |
382 | # See comments in assertConflictingSubscriptionDeletes. |
383 | dsp = self.factory.makeDistributionSourcePackage() |
384 | - self.assertConflictingSubscriptionDeletes(dsp, reloader=reload_dsp) |
385 | + self.assertConflictingSubscriptionDeletes(dsp) |
386 | |
387 | def test_mergeAsync(self): |
388 | # mergeAsync() creates a new `PersonMergeJob`. |
389 | |
390 | === modified file 'lib/lp/registry/tests/test_teammembership.py' |
391 | --- lib/lp/registry/tests/test_teammembership.py 2011-11-04 21:02:33 +0000 |
392 | +++ lib/lp/registry/tests/test_teammembership.py 2011-11-21 05:15:04 +0000 |
393 | @@ -73,9 +73,9 @@ |
394 | TestCase, |
395 | TestCaseWithFactory, |
396 | ) |
397 | +from lp.testing.dbuser import dbuser |
398 | from lp.testing.mail_helpers import pop_notifications |
399 | from lp.testing.matchers import HasQueryCount |
400 | -from lp.testing.storm import reload_object |
401 | |
402 | |
403 | class TestTeamMembershipSetScripts(TestCaseWithFactory): |
404 | @@ -105,15 +105,10 @@ |
405 | # Set expiration time to now |
406 | now = datetime.now(pytz.UTC) |
407 | removeSecurityProxy(teammembership).dateexpires = now |
408 | - transaction.commit() |
409 | |
410 | - # Switch dbuser to the user running the membership flagging |
411 | - # cronscript. Reload the membership object so we can assert against |
412 | - # it. |
413 | - self.layer.switchDbUser(config.expiredmembershipsflagger.dbuser) |
414 | - reload_object(teammembership) |
415 | janitor = getUtility(ILaunchpadCelebrities).janitor |
416 | - membershipset.handleMembershipsExpiringToday(janitor) |
417 | + with dbuser(config.expiredmembershipsflagger.dbuser): |
418 | + membershipset.handleMembershipsExpiringToday(janitor) |
419 | self.assertEqual( |
420 | teammembership.status, TeamMembershipStatus.APPROVED) |
421 | |
422 | |
423 | === modified file 'lib/lp/soyuz/stories/distribution/xx-distribution-packages.txt' |
424 | --- lib/lp/soyuz/stories/distribution/xx-distribution-packages.txt 2011-07-18 08:53:48 +0000 |
425 | +++ lib/lp/soyuz/stories/distribution/xx-distribution-packages.txt 2011-11-21 05:15:04 +0000 |
426 | @@ -176,27 +176,18 @@ |
427 | # Give the creators of the above source packages some soyuz |
428 | # karma for their efforts. |
429 | >>> from lp.registry.model.karma import KarmaTotalCache |
430 | + >>> from lp.testing.dbuser import dbuser |
431 | >>> ppa_beta_owner_id = ppa_beta.owner.id |
432 | >>> ppa_nightly_owner_id = ppa_nightly.owner.id |
433 | >>> ppa_disabled_owner_id = ppa_disabled.owner.id |
434 | >>> ppa_disabled.disable() |
435 | - >>> transaction.commit() |
436 | - |
437 | - # XXX: Michael Nelson 2009-07-07 bug=396419. Currently there is no |
438 | - # test api call to switchDbUser that works for non-zopeless layers. |
439 | - # When bug 396419 is fixed, we can instead use |
440 | - # DatabaseLayer.switchDbUser() instead of reconnect_stores() |
441 | - >>> from canonical.testing.layers import reconnect_stores |
442 | - >>> reconnect_stores('karmacacheupdater') |
443 | - >>> from zope.component import getUtility |
444 | - >>> cache_entry = KarmaTotalCache( |
445 | - ... person=ppa_beta_owner_id, karma_total=200) |
446 | - >>> cache_entry = KarmaTotalCache( |
447 | - ... person=ppa_nightly_owner_id, karma_total=201) |
448 | - >>> cache_entry = KarmaTotalCache( |
449 | - ... person=ppa_disabled_owner_id, karma_total=202) |
450 | - >>> transaction.commit() |
451 | - >>> reconnect_stores('launchpad') |
452 | + >>> with dbuser('karma'): |
453 | + ... cache_entry = KarmaTotalCache( |
454 | + ... person=ppa_beta_owner_id, karma_total=200) |
455 | + ... cache_entry = KarmaTotalCache( |
456 | + ... person=ppa_nightly_owner_id, karma_total=201) |
457 | + ... cache_entry = KarmaTotalCache( |
458 | + ... person=ppa_disabled_owner_id, karma_total=202) |
459 | |
460 | >>> logout() |
461 | |
462 | |
463 | === modified file 'lib/lp/soyuz/stories/soyuz/xx-distributionsourcepackagerelease-pages.txt' |
464 | --- lib/lp/soyuz/stories/soyuz/xx-distributionsourcepackagerelease-pages.txt 2011-08-23 08:33:15 +0000 |
465 | +++ lib/lp/soyuz/stories/soyuz/xx-distributionsourcepackagerelease-pages.txt 2011-11-21 05:15:04 +0000 |
466 | @@ -250,20 +250,17 @@ |
467 | >>> from zope.component import getUtility |
468 | >>> from canonical.config import config |
469 | >>> from lp.services.log.logger import BufferLogger |
470 | - >>> from canonical.testing.layers import reconnect_stores |
471 | >>> from lp.registry.interfaces.distribution import IDistributionSet |
472 | >>> from lp.soyuz.model.distroseriespackagecache import ( |
473 | ... DistroSeriesPackageCache) |
474 | + >>> from lp.testing.dbuser import dbuser |
475 | >>> login('foo.bar@canonical.com') |
476 | - >>> transaction.commit() |
477 | - >>> reconnect_stores(config.statistician.dbuser) |
478 | >>> logger = BufferLogger() |
479 | >>> ubuntutest = getUtility(IDistributionSet).getByName('ubuntutest') |
480 | >>> breezy_autotest = ubuntutest.getSeries('breezy-autotest') |
481 | - >>> unused = DistroSeriesPackageCache.updateAll( |
482 | - ... breezy_autotest, ubuntutest.main_archive, logger, transaction) |
483 | - >>> transaction.commit() |
484 | - >>> reconnect_stores('launchpad') |
485 | + >>> with dbuser(config.statistician.dbuser): |
486 | + ... unused = DistroSeriesPackageCache.updateAll( |
487 | + ... breezy_autotest, ubuntutest.main_archive, logger, transaction) |
488 | >>> logout() |
489 | |
490 | >>> anon_browser.reload() |
491 | |
492 | === modified file 'lib/lp/soyuz/tests/test_publishing.py' |
493 | --- lib/lp/soyuz/tests/test_publishing.py 2011-11-04 10:47:21 +0000 |
494 | +++ lib/lp/soyuz/tests/test_publishing.py 2011-11-21 05:15:04 +0000 |
495 | @@ -23,7 +23,6 @@ |
496 | from canonical.testing.layers import ( |
497 | DatabaseFunctionalLayer, |
498 | LaunchpadZopelessLayer, |
499 | - reconnect_stores, |
500 | ZopelessDatabaseLayer, |
501 | ) |
502 | from lp.app.errors import NotFoundError |
503 | @@ -31,7 +30,6 @@ |
504 | from lp.archivepublisher.diskpool import DiskPool |
505 | from lp.buildmaster.enums import BuildStatus |
506 | from lp.registry.interfaces.distribution import IDistributionSet |
507 | -from lp.registry.interfaces.distroseries import IDistroSeriesSet |
508 | from lp.registry.interfaces.person import IPersonSet |
509 | from lp.registry.interfaces.pocket import PackagePublishingPocket |
510 | from lp.registry.interfaces.sourcepackage import SourcePackageUrgency |
511 | @@ -69,6 +67,7 @@ |
512 | StormStatementRecorder, |
513 | TestCaseWithFactory, |
514 | ) |
515 | +from lp.testing.dbuser import dbuser |
516 | from lp.testing.factory import LaunchpadObjectFactory |
517 | from lp.testing.matchers import HasQueryCount |
518 | |
519 | @@ -553,23 +552,13 @@ |
520 | distroseries=source_pub.distroseries, |
521 | source_package=source_pub.meta_sourcepackage) |
522 | |
523 | - def updateDistroSeriesPackageCache( |
524 | - self, distroseries, restore_db_connection='launchpad'): |
525 | - # XXX: EdwinGrubbs 2010-08-04 bug=396419. Currently there is no |
526 | - # test api call to switchDbUser that works for non-zopeless layers. |
527 | - # When bug 396419 is fixed, we can instead use |
528 | - # DatabaseLayer.switchDbUser() instead of reconnect_stores() |
529 | - transaction.commit() |
530 | - reconnect_stores(config.statistician.dbuser) |
531 | - distroseries = getUtility(IDistroSeriesSet).get(distroseries.id) |
532 | - |
533 | - DistroSeriesPackageCache.updateAll( |
534 | - distroseries, |
535 | - archive=distroseries.distribution.main_archive, |
536 | - ztm=transaction, |
537 | - log=DevNullLogger()) |
538 | - transaction.commit() |
539 | - reconnect_stores(restore_db_connection) |
540 | + def updateDistroSeriesPackageCache(self, distroseries): |
541 | + with dbuser(config.statistician.dbuser): |
542 | + DistroSeriesPackageCache.updateAll( |
543 | + distroseries, |
544 | + archive=distroseries.distribution.main_archive, |
545 | + ztm=transaction, |
546 | + log=DevNullLogger()) |
547 | |
548 | |
549 | class TestNativePublishingBase(TestCaseWithFactory, SoyuzTestPublisher): |
550 | |
551 | === removed file 'lib/lp/testing/storm.py' |
552 | --- lib/lp/testing/storm.py 2011-05-10 17:54:16 +0000 |
553 | +++ lib/lp/testing/storm.py 1970-01-01 00:00:00 +0000 |
554 | @@ -1,30 +0,0 @@ |
555 | -# Copyright 2011 Canonical Ltd. This software is licensed under the |
556 | -# GNU Affero General Public License version 3 (see the file LICENSE). |
557 | - |
558 | -__metaclass__ = type |
559 | -__all__ = [ |
560 | - 'reload_object', |
561 | - 'reload_dsp', |
562 | - ] |
563 | - |
564 | - |
565 | -from zope.security.proxy import removeSecurityProxy |
566 | - |
567 | -from canonical.launchpad.interfaces.lpstorm import IStore |
568 | -from lp.registry.model.distribution import Distribution |
569 | - |
570 | - |
571 | -def reload_object(obj): |
572 | - """Return a new instance of a storm objet from the store.""" |
573 | - store = IStore(Distribution) |
574 | - return store.get(removeSecurityProxy(obj).__class__, obj.id) |
575 | - |
576 | - |
577 | -def reload_dsp(dsp): |
578 | - """Return a new instance of a DistributionSourcePackage from the store.""" |
579 | - store = IStore(Distribution) |
580 | - distribution_class = removeSecurityProxy(dsp.distribution.__class__) |
581 | - distribution = store.get(distribution_class, dsp.distribution.id) |
582 | - spn_class = removeSecurityProxy(dsp.sourcepackagename.__class__) |
583 | - spn = store.get(spn_class, dsp.sourcepackagename.id) |
584 | - return distribution.getSourcePackage(name=spn.name) |
thanks