summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/api/config.rst4
-rw-r--r--pyramid/config.py12
-rw-r--r--pyramid/tests/test_config.py48
3 files changed, 38 insertions, 26 deletions
diff --git a/docs/api/config.rst b/docs/api/config.rst
index 4b5f1fa21..38f809c7e 100644
--- a/docs/api/config.rst
+++ b/docs/api/config.rst
@@ -16,9 +16,9 @@
.. automethod:: end
- .. automethod:: hook_zca()
+ .. automethod:: hook_zca
- .. automethod:: unhook_zca()
+ .. automethod:: unhook_zca
.. automethod:: get_settings
diff --git a/pyramid/config.py b/pyramid/config.py
index 906c5f935..17bc972d1 100644
--- a/pyramid/config.py
+++ b/pyramid/config.py
@@ -720,8 +720,7 @@ class Configurator(object):
self.set_view_mapper(default_view_mapper)
self.commit()
- # getSiteManager is a unit testing dep injection
- def hook_zca(self, getSiteManager=None):
+ def hook_zca(self):
""" Call :func:`zope.component.getSiteManager.sethook` with
the argument
:data:`pyramid.threadlocal.get_current_registry`, causing
@@ -731,19 +730,16 @@ class Configurator(object):
:app:`Pyramid` :term:`application registry` rather than the
Zope 'global' registry. If :mod:`zope.component` cannot be
imported, this method will raise an :exc:`ImportError`."""
- if getSiteManager is None:
- from zope.component import getSiteManager
+ from zope.component import getSiteManager
getSiteManager.sethook(get_current_registry)
- # getSiteManager is a unit testing dep injection
- def unhook_zca(self, getSiteManager=None):
+ def unhook_zca(self):
""" Call :func:`zope.component.getSiteManager.reset` to undo
the action of
:meth:`pyramid.config.Configurator.hook_zca`. If
:mod:`zope.component` cannot be imported, this method will
raise an :exc:`ImportError`."""
- if getSiteManager is None: # pragma: no cover
- from zope.component import getSiteManager
+ from zope.component import getSiteManager
getSiteManager.reset()
def begin(self, request=None):
diff --git a/pyramid/tests/test_config.py b/pyramid/tests/test_config.py
index d4be27bd1..c0b39c40e 100644
--- a/pyramid/tests/test_config.py
+++ b/pyramid/tests/test_config.py
@@ -210,6 +210,15 @@ class ConfiguratorTests(unittest.TestCase):
newconfig = config.with_package(pyramid.tests)
self.assertEqual(newconfig.package, pyramid.tests)
+ def test_with_package_context_is_not_None(self):
+ import pyramid.tests
+ config = self._makeOne()
+ config._ctx = DummyContext()
+ config._ctx.registry = None
+ config._ctx.autocommit = True
+ newconfig = config.with_package(pyramid.tests)
+ self.assertEqual(newconfig.package, pyramid.tests)
+
def test_maybe_dotted_string_success(self):
import pyramid.tests
config = self._makeOne()
@@ -2770,18 +2779,31 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(L[-1], event2)
def test_hook_zca(self):
- from pyramid.threadlocal import get_current_registry
- gsm = DummyGetSiteManager()
- config = self._makeOne()
- config.hook_zca(getSiteManager=gsm)
- self.assertEqual(gsm.hook, get_current_registry)
+ from zope.component import getSiteManager
+ def foo():
+ '123'
+ try:
+ config = self._makeOne()
+ config.hook_zca()
+ config.begin()
+ sm = getSiteManager()
+ self.assertEqual(sm, config.registry)
+ finally:
+ getSiteManager.reset()
def test_unhook_zca(self):
- gsm = DummyGetSiteManager()
- config = self._makeOne()
- config.unhook_zca(getSiteManager=gsm)
- self.assertEqual(gsm.unhooked, True)
-
+ from zope.component import getSiteManager
+ def foo():
+ '123'
+ try:
+ getSiteManager.sethook(foo)
+ config = self._makeOne()
+ config.unhook_zca()
+ sm = getSiteManager()
+ self.assertNotEqual(sm, '123')
+ finally:
+ getSiteManager.reset()
+
def test_testing_add_renderer(self):
config = self._makeOne(autocommit=True)
renderer = config.testing_add_renderer('templates/foo.pt')
@@ -4720,12 +4742,6 @@ class DummyMultiView:
def __permitted__(self, context, request):
""" """
-class DummyGetSiteManager(object):
- def sethook(self, hook):
- self.hook = hook
- def reset(self):
- self.unhooked = True
-
class DummyThreadLocalManager(object):
pushed = None
popped = False