diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-11-27 04:46:05 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-11-27 04:46:05 +0000 |
| commit | d0b398eeb8ce9e1b13b2c93674e220d804d2de2e (patch) | |
| tree | a71b6007259ad04172273bcfed65f7183be6ed22 /repoze/bfg/tests/test_configuration.py | |
| parent | f850ec2bf2565e1fb227afa77c2ec2e72fe96522 (diff) | |
| download | pyramid-d0b398eeb8ce9e1b13b2c93674e220d804d2de2e.tar.gz pyramid-d0b398eeb8ce9e1b13b2c93674e220d804d2de2e.tar.bz2 pyramid-d0b398eeb8ce9e1b13b2c93674e220d804d2de2e.zip | |
- The ``repoze.bfg.testing.setUp`` function now accepts three extra
optional keyword arguments: ``registry``, ``request`` and
``hook_zca``.
If the ``registry`` argument is not ``None``, the argument will be
treated as the registry that is set as the "current registry" (it
will be returned by ``repoze.bfg.threadlocal.get_current_registry``)
for the duration of the test. If the ``registry`` argument is
``None`` (the default), a new registry is created and used for the
duration of the test.
The value of the ``request`` argument is used as the "current
request" (it will be returned by
``repoze.bfg.threadlocal.get_current_request``) for the duration of
the test; it defaults to ``None``.
If ``hook_zca`` is ``True`` (the default), the
``zope.component.getSiteManager`` function will be hooked with a
function that returns the value of ``registry`` (or the
default-created registry if ``registry`` is ``None``) instead of the
registry returned by ``zope.component.getGlobalSiteManager``,
causing the Zope Component Architecture API (``getSiteManager``,
``getAdapter``, ``getUtility``, and so on) to use the registry we're
using for testing instead of the global ZCA registry.
- The ``repoze.bfg.testing.tearDown`` function now accepts an
``unhook_zca`` argument. If this argument is ``True`` (the
default), ``zope.component.getSiteManager.reset()`` will be called,
causing the "base" registry to once again start returnining the
result of ``zope.component.getSiteManager``.
- Remove hook_zca and unhook_zca methods from Configurator.
Diffstat (limited to 'repoze/bfg/tests/test_configuration.py')
| -rw-r--r-- | repoze/bfg/tests/test_configuration.py | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py index ae75494e4..ed84735b4 100644 --- a/repoze/bfg/tests/test_configuration.py +++ b/repoze/bfg/tests/test_configuration.py @@ -134,31 +134,6 @@ class ConfiguratorTests(unittest.TestCase): self.assertEqual(config.registry.getUtility(IRendererFactory, 'yeah'), renderer) - def test_hook_zca(self): - from zope.component import getSiteManager - from repoze.bfg.threadlocal import get_current_registry - try: - getSiteManager.reset() - config = self._makeOne() - config.hook_zca() - hooked = getSiteManager.sethook(None) - self.assertEqual(hooked, get_current_registry) - finally: - getSiteManager.reset() - - def test_unhook_zca(self): - from zope.component import getSiteManager - try: - config = self._makeOne() - reg = object() - hook = lambda *arg: reg - hooked = getSiteManager.sethook(hook) - self.assertEqual(getSiteManager(), reg) - config.unhook_zca() - self.assertNotEqual(getSiteManager(), reg) - finally: - getSiteManager.reset() - def test_add_subscriber_defaults(self): from zope.interface import implements from zope.interface import Interface @@ -2488,14 +2463,17 @@ class TestMakeApp(unittest.TestCase): return make_app(*arg, **kw) def test_it(self): + from repoze.bfg.threadlocal import get_current_registry settings = {'a':1} rootfactory = object() + gsm = DummyGetSiteManager() app = self._callFUT(rootfactory, settings=settings, - Configurator=DummyConfigurator) + Configurator=DummyConfigurator, + getSiteManager=gsm) self.assertEqual(app.root_factory, rootfactory) self.assertEqual(app.settings, settings) self.assertEqual(app.zcml_file, 'configure.zcml') - self.assertEqual(app.zca_hooked, True) + self.assertEqual(gsm.hook, get_current_registry) def test_it_options_means_settings(self): settings = {'a':1} @@ -2633,3 +2611,9 @@ class DummyMultiView: return 'OK1' def __permitted__(self, context, request): """ """ + +class DummyGetSiteManager(object): + def sethook(self, hook): + self.hook = hook + + |
