diff options
| author | Chris McDonough <chrism@agendaless.com> | 2008-08-06 03:30:40 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2008-08-06 03:30:40 +0000 |
| commit | 39fccbbfbceacaf1b3d5fb6f03a07fbe4d861969 (patch) | |
| tree | b06b38c284eae4e37bd46bc5b1182153cff8b7fa /repoze/bfg/tests/test_urldispatch.py | |
| parent | e17c8d815136218d7dd07e21cf78f4104d773d48 (diff) | |
| download | pyramid-39fccbbfbceacaf1b3d5fb6f03a07fbe4d861969.tar.gz pyramid-39fccbbfbceacaf1b3d5fb6f03a07fbe4d861969.tar.bz2 pyramid-39fccbbfbceacaf1b3d5fb6f03a07fbe4d861969.zip | |
- 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.
Diffstat (limited to 'repoze/bfg/tests/test_urldispatch.py')
| -rw-r--r-- | repoze/bfg/tests/test_urldispatch.py | 26 |
1 files changed, 26 insertions, 0 deletions
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) |
