diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-10-31 16:21:51 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-10-31 16:21:51 +0000 |
| commit | ad406f50aea5db8b399e7f9d502c06b6253f8a21 (patch) | |
| tree | 6399e252c3e068fa5b789b305b543de4ec154950 /repoze | |
| parent | 6db2c53850b33015faf8db627c5cf2fda00fc295 (diff) | |
| download | pyramid-ad406f50aea5db8b399e7f9d502c06b6253f8a21.tar.gz pyramid-ad406f50aea5db8b399e7f9d502c06b6253f8a21.tar.bz2 pyramid-ad406f50aea5db8b399e7f9d502c06b6253f8a21.zip | |
Fix default root factory in the face of changes to root factory construction arg.
Diffstat (limited to 'repoze')
| -rw-r--r-- | repoze/bfg/configuration.py | 12 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_configuration.py | 24 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_router.py | 20 |
3 files changed, 30 insertions, 26 deletions
diff --git a/repoze/bfg/configuration.py b/repoze/bfg/configuration.py index 7ea74853c..077b72438 100644 --- a/repoze/bfg/configuration.py +++ b/repoze/bfg/configuration.py @@ -127,12 +127,12 @@ def make_registry(root_factory, package=None, filename='configure.zcml', class DefaultRootFactory: __parent__ = None __name__ = None - def __init__(self, environ): - if 'bfg.routes.matchdict' in environ: - # provide backwards compatibility for applications which - # used routes (at least apps without any custom "context - # factory") in BFG 0.9.X and before - self.__dict__.update(environ['bfg.routes.matchdict']) + def __init__(self, request): + matchdict = getattr(request, 'matchdict', {}) + # provide backwards compatibility for applications which + # used routes (at least apps without any custom "context + # factory") in BFG 0.9.X and before + self.__dict__.update(matchdict) def zcml_configure(name, package): """ Given a ZCML filename as ``name`` and a Python package as diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py index e15bba5a9..669ee2ecf 100644 --- a/repoze/bfg/tests/test_configuration.py +++ b/repoze/bfg/tests/test_configuration.py @@ -217,6 +217,30 @@ class MakeRegistryTests(unittest.TestCase): self.assertEqual(dummylock.acquired, True) self.assertEqual(dummylock.released, True) +class TestDefaultRootFactory(unittest.TestCase): + def _getTargetClass(self): + from repoze.bfg.configuration import DefaultRootFactory + return DefaultRootFactory + + def _makeOne(self, environ): + return self._getTargetClass()(environ) + + def test_no_matchdict(self): + environ = {} + root = self._makeOne(environ) + self.assertEqual(root.__parent__, None) + self.assertEqual(root.__name__, None) + + def test_matchdict(self): + request = DummyRequest() + request.matchdict = {'a':1, 'b':2} + root = self._makeOne(request) + self.assertEqual(root.a, 1) + self.assertEqual(root.b, 2) + +class DummyRequest: + pass + class DummyRegistryManager: def push(self, registry): from repoze.bfg.threadlocal import manager diff --git a/repoze/bfg/tests/test_router.py b/repoze/bfg/tests/test_router.py index ac77508ef..1e5382dde 100644 --- a/repoze/bfg/tests/test_router.py +++ b/repoze/bfg/tests/test_router.py @@ -417,26 +417,6 @@ class TestRouter(unittest.TestCase): self.assertEqual(len(router.threadlocal_manager.popped), 1) -class TestDefaultRootFactory(unittest.TestCase): - def _getTargetClass(self): - from repoze.bfg.router import DefaultRootFactory - return DefaultRootFactory - - def _makeOne(self, environ): - return self._getTargetClass()(environ) - - def test_no_matchdict(self): - environ = {} - root = self._makeOne(environ) - self.assertEqual(root.__parent__, None) - self.assertEqual(root.__name__, None) - - def test_matchdict(self): - environ = {'bfg.routes.matchdict':{'a':1, 'b':2}} - root = self._makeOne(environ) - self.assertEqual(root.a, 1) - self.assertEqual(root.b, 2) - class TestMakeApp(unittest.TestCase): def setUp(self): cleanUp() |
