From 241390d911639cb658bbbbbf1bf3d8c21e0c0270 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Mon, 24 Aug 2009 17:21:10 +0000 Subject: Added ZCML directive to serve up static files from a directory. --- repoze/bfg/tests/test_zcml.py | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'repoze/bfg/tests') diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py index 556f22983..d17babaf3 100644 --- a/repoze/bfg/tests/test_zcml.py +++ b/repoze/bfg/tests/test_zcml.py @@ -1037,6 +1037,76 @@ class TestRouteDirective(unittest.TestCase): self.assertEqual(route_discriminator[3], 'GET') self.assertEqual(route_args, ('path', 'name', None)) +class TestStaticDirective(unittest.TestCase): + def setUp(self): + cleanUp() + import os + here = os.path.dirname(__file__) + self.static_path = os.path.join(here, 'fixtures', 'static') + + def tearDown(self): + cleanUp() + + def _callFUT(self, *arg, **kw): + from repoze.bfg.zcml import static + return static(*arg, **kw) + + def test_absolute(self): + from repoze.bfg.zcml import handler + from repoze.bfg.zcml import connect_route + from repoze.bfg.interfaces import IView + context = DummyContext() + self._callFUT(context, 'name', self.static_path) + actions = context.actions + self.assertEqual(len(actions), 2) + + route_action = actions[0] + route_callable = route_action['callable'] + route_discriminator = route_action['discriminator'] + route_args = route_action['args'] + self.assertEqual(route_callable, handler) + self.assertEqual(route_discriminator[:3], ( + 'view', None, '')) + self.assertEqual(route_discriminator[4], IView) + + route_action = actions[1] + route_callable = route_action['callable'] + route_discriminator = route_action['discriminator'] + route_args = route_action['args'] + self.assertEqual(route_callable, connect_route) + self.assertEqual(route_discriminator, ( + 'route', 'name', None, None)) + self.assertEqual(route_args, ( + 'name*subpath', 'name', None)) + + def test_package_relative(self): + from repoze.bfg.zcml import handler + from repoze.bfg.zcml import connect_route + from repoze.bfg.interfaces import IView + context = DummyContext() + self._callFUT(context, 'name', 'repoze.bfg.tests:fixtures/static') + actions = context.actions + self.assertEqual(len(actions), 2) + + route_action = actions[0] + route_callable = route_action['callable'] + route_discriminator = route_action['discriminator'] + route_args = route_action['args'] + self.assertEqual(route_callable, handler) + self.assertEqual(route_discriminator[:3], ( + 'view', None, '')) + self.assertEqual(route_discriminator[4], IView) + + route_action = actions[1] + route_callable = route_action['callable'] + route_discriminator = route_action['discriminator'] + route_args = route_action['args'] + self.assertEqual(route_callable, connect_route) + self.assertEqual(route_discriminator, ( + 'route', 'name', None, None)) + self.assertEqual(route_args, ( + 'name*subpath', 'name', None)) + class TestResourceDirective(unittest.TestCase): def setUp(self): cleanUp() -- cgit v1.2.3