From 39fccbbfbceacaf1b3d5fb6f03a07fbe4d861969 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 6 Aug 2008 03:30:40 +0000 Subject: - Small url dispatch overhaul: the ``connect`` method of the ``urldispatch.RoutesMapper`` object now accepts a keyword parameter named ``context_factory``. If this parameter is supplied, it must be a callable which returns an instance. This instance is used as the context for the request when a route is matched. - The registration of a RoutesModelTraverser no longer needs to be performed by the application; it's in the bfg ZCML now. --- repoze/bfg/tests/test_urldispatch.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'repoze/bfg/tests/test_urldispatch.py') diff --git a/repoze/bfg/tests/test_urldispatch.py b/repoze/bfg/tests/test_urldispatch.py index a3e156861..0b69b5bec 100644 --- a/repoze/bfg/tests/test_urldispatch.py +++ b/repoze/bfg/tests/test_urldispatch.py @@ -30,10 +30,36 @@ class RoutesMapperTests(unittest.TestCase): mapper.connect('archives/:action/:article', controller='foo') environ = self._getEnviron(PATH_INFO='/archives/action1/article1') result = mapper(environ) + from repoze.bfg.interfaces import IRoutesContext + self.failUnless(IRoutesContext.providedBy(result)) self.assertEqual(result.controller, 'foo') self.assertEqual(result.action, 'action1') self.assertEqual(result.article, 'article1') + def test_routes_mapper_custom_context_factory(self): + marker = () + get_root = make_get_root(marker) + mapper = self._makeOne(get_root) + from zope.interface import implements, Interface + class IDummy(Interface): + pass + class Dummy(object): + implements(IDummy) + def __init__(self, **kw): + self.__dict__.update(kw) + mapper.connect('archives/:action/:article', controller='foo', + context_factory=Dummy) + environ = self._getEnviron(PATH_INFO='/archives/action1/article1') + result = mapper(environ) + self.assertEqual(result.controller, 'foo') + self.assertEqual(result.action, 'action1') + self.assertEqual(result.article, 'article1') + from repoze.bfg.interfaces import IRoutesContext + self.failUnless(IRoutesContext.providedBy(result)) + self.failUnless(isinstance(result, Dummy)) + self.failUnless(IDummy.providedBy(result)) + self.failIf(hasattr(result, 'context_factory')) + def test_url_for(self): marker = () get_root = make_get_root(marker) -- cgit v1.2.3