summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--repoze/bfg/router.py8
-rw-r--r--repoze/bfg/tests/test_router.py20
2 files changed, 27 insertions, 1 deletions
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('<code>abc&amp;123</code>' 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):