From d0b398eeb8ce9e1b13b2c93674e220d804d2de2e Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 27 Nov 2009 04:46:05 +0000 Subject: - 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. --- repoze/bfg/view.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'repoze/bfg/view.py') diff --git a/repoze/bfg/view.py b/repoze/bfg/view.py index f037ed839..d682d762b 100644 --- a/repoze/bfg/view.py +++ b/repoze/bfg/view.py @@ -28,6 +28,7 @@ from repoze.bfg.interfaces import IView from repoze.bfg.path import caller_package from repoze.bfg.resource import resolve_resource_spec from repoze.bfg.static import PackageURLParser +from repoze.bfg.threadlocal import get_current_registry # b/c imports from repoze.bfg.security import view_execution_permitted @@ -61,7 +62,10 @@ def render_view_to_response(context, request, name='', secure=True): ``args`` attribute explains why the view access was disallowed. If ``secure`` is ``False``, no permission checking is done.""" provides = map(providedBy, (context, request)) - reg = request.registry + try: + reg = request.registry + except AttributeError: + reg = get_current_registry() view = reg.adapters.lookup(provides, IView, name=name) if view is None: return None -- cgit v1.2.3