diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-05-16 20:59:41 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-05-16 20:59:41 +0000 |
| commit | def444c2c310c8cb117e0c5181bf74f5beed064c (patch) | |
| tree | 7415757b8463512dd62923c6c7b400cee0eb8be8 /repoze/bfg/tests/test_urldispatch.py | |
| parent | 090f6b77dcc8cd738caba4dbb3885ccb6ddb3d41 (diff) | |
| download | pyramid-def444c2c310c8cb117e0c5181bf74f5beed064c.tar.gz pyramid-def444c2c310c8cb117e0c5181bf74f5beed064c.tar.bz2 pyramid-def444c2c310c8cb117e0c5181bf74f5beed064c.zip | |
Speed up common case (use default factory).
Diffstat (limited to 'repoze/bfg/tests/test_urldispatch.py')
| -rw-r--r-- | repoze/bfg/tests/test_urldispatch.py | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/repoze/bfg/tests/test_urldispatch.py b/repoze/bfg/tests/test_urldispatch.py index e1640bfdf..e5ae483e7 100644 --- a/repoze/bfg/tests/test_urldispatch.py +++ b/repoze/bfg/tests/test_urldispatch.py @@ -1,6 +1,13 @@ import unittest +from repoze.bfg.testing import cleanUp class RoutesRootFactoryTests(unittest.TestCase): + def setUp(self): + cleanUp() + + def tearDown(self): + cleanUp() + def _getEnviron(self, **kw): environ = {'SERVER_NAME':'localhost', 'wsgi.url_scheme':'http'} @@ -15,6 +22,32 @@ class RoutesRootFactoryTests(unittest.TestCase): klass = self._getTargetClass() return klass(get_root) + def test_init_custom_default_context_factory_dont_decorate(self): + from zope.component import getGlobalSiteManager + from repoze.bfg.interfaces import IRoutesContextFactory + class Dummy(object): + pass + gsm = getGlobalSiteManager() + gsm.registerUtility(Dummy, IRoutesContextFactory) + mapper = self._makeOne(None) + self.assertEqual(mapper.default_context_factory, + Dummy) + self.assertEqual(mapper.decorate_context, True) + + def test_init_custom_default_context_factory_decorate(self): + from zope.component import getGlobalSiteManager + from repoze.bfg.interfaces import IRoutesContextFactory + from repoze.bfg.interfaces import IRoutesContext + from zope.interface import implements + class Dummy(object): + implements(IRoutesContext) + gsm = getGlobalSiteManager() + gsm.registerUtility(Dummy, IRoutesContextFactory) + mapper = self._makeOne(None) + self.assertEqual(mapper.default_context_factory, + Dummy) + self.assertEqual(mapper.decorate_context, False) + def test_no_route_matches(self): marker = () get_root = make_get_root(marker) @@ -80,12 +113,12 @@ class RoutesRootFactoryTests(unittest.TestCase): self.assertEqual(routing_args[la.encode('utf-8')], 'id') def test_no_fallback_get_root(self): + from repoze.bfg.urldispatch import RoutesContextNotFound marker = () mapper = self._makeOne(None) mapper.connect('wont', 'wont/:be/:found') environ = self._getEnviron(PATH_INFO='/archives/action1/article1') result = mapper(environ) - from repoze.bfg.urldispatch import RoutesContextNotFound self.failUnless(isinstance(result, RoutesContextNotFound)) def test_custom_factory(self): @@ -111,6 +144,32 @@ class RoutesRootFactoryTests(unittest.TestCase): self.failUnless(IDummy.providedBy(result)) self.failIf(hasattr(result, '_factory')) + def test_decorate_context_false(self): + from repoze.bfg.interfaces import IRoutesContext + class Dummy: + def __init__(self, **kw): + pass + mapper = self._makeOne(None) + mapper.connect('root', '') + environ = self._getEnviron(PATH_INFO='/') + mapper.decorate_context = False + mapper.default_context_factory = Dummy + result = mapper(environ) + self.failIf(IRoutesContext.providedBy(result)) + + def test_decorate_context_true(self): + from repoze.bfg.interfaces import IRoutesContext + class Dummy: + def __init__(self, **kw): + pass + mapper = self._makeOne(None) + mapper.connect('root', '') + environ = self._getEnviron(PATH_INFO='/') + mapper.decorate_context = True + mapper.default_context_factory = Dummy + result = mapper(environ) + self.failUnless(IRoutesContext.providedBy(result)) + def test_has_routes(self): mapper = self._makeOne(None) self.assertEqual(mapper.has_routes(), False) |
