~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/testing/fixture.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-05 17:43:37 UTC
  • mfrom: (13333.6.49 lp-app-longpoll)
  • Revision ID: launchpad@pqm.canonical.com-20110705174337-4ygi4i0soakb5cs2
[r=gmb][no-qa] New lp.app.longpoll package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
__metaclass__ = type
7
7
__all__ = [
 
8
    'ZopeAdapterFixture',
8
9
    'ZopeEventHandlerFixture',
 
10
    'ZopeViewReplacementFixture',
9
11
    ]
10
12
 
11
13
from fixtures import Fixture
22
24
    )
23
25
 
24
26
 
 
27
class ZopeAdapterFixture(Fixture):
 
28
    """A fixture to register and unregister an adapter."""
 
29
 
 
30
    def __init__(self, *args, **kwargs):
 
31
        self._args, self._kwargs = args, kwargs
 
32
 
 
33
    def setUp(self):
 
34
        super(ZopeAdapterFixture, self).setUp()
 
35
        site_manager = getGlobalSiteManager()
 
36
        site_manager.registerAdapter(
 
37
            *self._args, **self._kwargs)
 
38
        self.addCleanup(
 
39
            site_manager.unregisterAdapter,
 
40
            *self._args, **self._kwargs)
 
41
 
 
42
 
25
43
class ZopeEventHandlerFixture(Fixture):
26
44
    """A fixture that provides and then unprovides a Zope event handler."""
27
45