From 81a833da2adff04d11b9228406bbc1528be65c64 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 24 Jul 2010 07:04:49 +0000 Subject: - A new method of the ``Configurator`` exists: ``set_request_factory``. If used, this method will set the factory used by the :mod:`repoze.bfg` router to create all request objects. - The ``Configurator`` constructor takes an additional argument: ``request_factory``. If used, this argument will set the factory used by the :mod:`repoze.bfg` router to create all request objects. - The ``Hooks`` narrative chapter now contains a section about changing the request factory. --- repoze/bfg/tests/test_scripting.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'repoze/bfg/tests/test_scripting.py') diff --git a/repoze/bfg/tests/test_scripting.py b/repoze/bfg/tests/test_scripting.py index 4d45a6456..2663c4a0f 100644 --- a/repoze/bfg/tests/test_scripting.py +++ b/repoze/bfg/tests/test_scripting.py @@ -28,12 +28,33 @@ class TestGetRoot(unittest.TestCase): closer() self.assertEqual(len(app.threadlocal_manager.popped), 1) + def test_it_requestfactory_overridden(self): + app = DummyApp() + request = Dummy() + class DummyFactory(object): + @classmethod + def blank(cls, path): + return request + registry = DummyRegistry(DummyFactory) + app.registry = registry + root, closer = self._callFUT(app) + self.assertEqual(len(app.threadlocal_manager.pushed), 1) + pushed = app.threadlocal_manager.pushed[0] + self.assertEqual(pushed['request'], request) class Dummy: pass dummy_root = Dummy() -dummy_registry = Dummy() + +class DummyRegistry(object): + def __init__(self, result=None): + self.result = result + + def queryUtility(self, iface, default=None): + return self.result or default + +dummy_registry = DummyRegistry() class DummyApp: def __init__(self): -- cgit v1.2.3