summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests/test_zcml.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-07-12 10:46:04 +0000
committerChris McDonough <chrism@agendaless.com>2008-07-12 10:46:04 +0000
commit69dfd4ba10c01181ae006266efce5d6057091b72 (patch)
tree1066c244dfc531f60e100e0eaa938feec90cd006 /repoze/bfg/tests/test_zcml.py
parent8823e22b7caf3ef72aefaccec9e33f21bb37018c (diff)
downloadpyramid-69dfd4ba10c01181ae006266efce5d6057091b72.tar.gz
pyramid-69dfd4ba10c01181ae006266efce5d6057091b72.tar.bz2
pyramid-69dfd4ba10c01181ae006266efce5d6057091b72.zip
metaconfigure.py -> zcml.py
Diffstat (limited to 'repoze/bfg/tests/test_zcml.py')
-rw-r--r--repoze/bfg/tests/test_zcml.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py
new file mode 100644
index 000000000..bcb065d9e
--- /dev/null
+++ b/repoze/bfg/tests/test_zcml.py
@@ -0,0 +1,92 @@
+import unittest
+
+from zope.component.testing import PlacelessSetup
+
+class TestPageDirective(unittest.TestCase, PlacelessSetup):
+ def setUp(self):
+ PlacelessSetup.setUp(self)
+
+ def tearDown(self):
+ PlacelessSetup.tearDown(self)
+
+ def _getFUT(self):
+ from repoze.bfg.zcml import page
+ return page
+
+ def test_no_class_or_template(self):
+ f = self._getFUT()
+ from zope.configuration.exceptions import ConfigurationError
+ context = DummyContext()
+ self.assertRaises(ConfigurationError, f, context, 'repoze.view', None)
+
+ def test_no_such_file(self):
+ f = self._getFUT()
+ from zope.configuration.exceptions import ConfigurationError
+ context = DummyContext()
+ self.assertRaises(ConfigurationError, f, context, 'repoze.view', None,
+ template='notthere.pt')
+
+ def test_only_template(self):
+ f = self._getFUT()
+ context = DummyContext()
+ f(context, 'repoze.view', None, template='minimal.pt')
+ actions = context.actions
+ from repoze.bfg.interfaces import IRequest
+ from repoze.bfg.interfaces import IViewFactory
+ from zope.component.zcml import handler
+ expected0 = ('view', None, '', IRequest, IViewFactory)
+ expected1 = handler
+ self.assertEqual(actions[0]['discriminator'], expected0)
+ self.assertEqual(actions[0]['callable'], expected1)
+ self.assertEqual(actions[0]['args'][0], 'registerAdapter')
+ import types
+ self.failUnless(isinstance(actions[0]['args'][1], types.FunctionType))
+ self.assertEqual(actions[0]['args'][2], (None, IRequest))
+ self.assertEqual(actions[0]['args'][3], IViewFactory)
+ self.assertEqual(actions[0]['args'][4], '')
+ self.assertEqual(actions[0]['args'][5], None)
+
+ def test_template_and_class(self):
+ f = self._getFUT()
+ context = DummyContext()
+ f(context, 'repoze.view', None, template='minimal.pt',
+ class_=DummyViewClass)
+ actions = context.actions
+ from repoze.bfg.interfaces import IRequest
+ from repoze.bfg.interfaces import IViewFactory
+ from zope.component.zcml import handler
+ expected0 = ('view', None, '', IRequest, IViewFactory)
+ expected1 = handler
+ self.assertEqual(actions[0]['discriminator'], expected0)
+ self.assertEqual(actions[0]['callable'], expected1)
+ self.assertEqual(actions[0]['args'][0], 'registerAdapter')
+ import types
+ self.failUnless(isinstance(actions[0]['args'][1], types.FunctionType))
+ self.assertEqual(actions[0]['args'][2], (None, IRequest))
+ self.assertEqual(actions[0]['args'][3], IViewFactory)
+ self.assertEqual(actions[0]['args'][4], '')
+ self.assertEqual(actions[0]['args'][5], None)
+
+class DummyViewClass:
+ pass
+
+class DummyContext:
+ def __init__(self):
+ self.actions = []
+ self.info = None
+
+ def path(self, name):
+ import os
+ here = os.path.dirname(__file__)
+ fixtures = os.path.join(here, 'fixtures')
+ return os.path.join(fixtures, name)
+
+ def action(self, discriminator, callable, args):
+ self.actions.append(
+ {'discriminator':discriminator,
+ 'callable':callable,
+ 'args':args}
+ )
+
+
+