summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests/test_testing.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-10-10 03:58:41 +0000
committerChris McDonough <chrism@agendaless.com>2009-10-10 03:58:41 +0000
commit927acdcb1419e636a67d328084a546834aaa173d (patch)
tree691789b788621374bf8dd5476db1e3f0bfad7321 /repoze/bfg/tests/test_testing.py
parentd85ac83b981cce853790c1b58bfcab0f0d7a003a (diff)
downloadpyramid-927acdcb1419e636a67d328084a546834aaa173d.tar.gz
pyramid-927acdcb1419e636a67d328084a546834aaa173d.tar.bz2
pyramid-927acdcb1419e636a67d328084a546834aaa173d.zip
- Add a new ``repoze.bfg.testing`` API: ``registerRoute``, for
registering routes to satisfy calls to e.g. ``repoze.bfg.url.route_url`` in unit tests.
Diffstat (limited to 'repoze/bfg/tests/test_testing.py')
-rw-r--r--repoze/bfg/tests/test_testing.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_testing.py b/repoze/bfg/tests/test_testing.py
index 938115ecd..05cddc980 100644
--- a/repoze/bfg/tests/test_testing.py
+++ b/repoze/bfg/tests/test_testing.py
@@ -259,6 +259,34 @@ class TestTestingFunctions(unittest.TestCase):
testing.registerUtility(utility, iface, name='mudge')
self.assertEqual(getUtility(iface, name='mudge')(), 'foo')
+ def test_registerRoute(self):
+ from repoze.bfg.url import route_url
+ from repoze.bfg.interfaces import IRoutesMapper
+ from repoze.bfg.testing import registerRoute
+ from zope.component import getSiteManager
+ class Factory:
+ def __init__(self, environ):
+ """ """
+ class DummyRequest:
+ application_url = 'http://example.com'
+ registerRoute(':pagename', 'home', Factory)
+ sm = getSiteManager()
+ mapper = sm.getUtility(IRoutesMapper)
+ self.assertEqual(len(mapper.routelist), 1)
+ request = DummyRequest()
+ self.assertEqual(route_url('home', request, pagename='abc'),
+ 'http://example.com/abc')
+
+class TestDummyRootFactory(unittest.TestCase):
+ def _makeOne(self, environ):
+ from repoze.bfg.testing import DummyRootFactory
+ return DummyRootFactory(environ)
+
+ def test_it(self):
+ environ = {'bfg.routes.matchdict':{'a':1}}
+ factory = self._makeOne(environ)
+ self.assertEqual(factory.a, 1)
+
class TestDummySecurityPolicy(unittest.TestCase):
def _getTargetClass(self):
from repoze.bfg.testing import DummySecurityPolicy