From b57adfea3d136bc33367ae8aab4371810c9a9359 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 11 Jun 2009 05:35:45 +0000 Subject: # provide backwards compatibility for applications which # used routes (at least apps without any custom "context # factory") in BFG 0.9.X and before --- repoze/bfg/router.py | 8 +++++++- repoze/bfg/tests/test_router.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/repoze/bfg/router.py b/repoze/bfg/router.py index 670a6a05c..65044b6e1 100644 --- a/repoze/bfg/router.py +++ b/repoze/bfg/router.py @@ -392,4 +392,10 @@ class DefaultRootFactory: __parent__ = None __name__ = None def __init__(self, environ): - pass + 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']) + + diff --git a/repoze/bfg/tests/test_router.py b/repoze/bfg/tests/test_router.py index 589843b0f..be4fbad59 100644 --- a/repoze/bfg/tests/test_router.py +++ b/repoze/bfg/tests/test_router.py @@ -876,6 +876,26 @@ class TestDefaultForbiddenView(unittest.TestCase): response = self._callFUT(context, request) self.failUnless('abc&123' in response.body) +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 DummyRegistryManager: def push(self, registry): -- cgit v1.2.3