From 04e182bbc0c077afcd921f0df4231020549dc217 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 14 Sep 2009 04:33:38 +0000 Subject: - A ZCML ``view`` directive (and the associated ``bfg_view`` decorator) can now accept an "attr" value. If an "attr" value is supplied, it is considered a method named of the view object to be called when the response is required. This is typically only good for views that are classes or instances (not so useful for functions, as functions typically have no methods other than ``__call__``). - A ZCML ``view`` directive (and the associated ``bfg_view`` decorator) can now accept a "template" value. If a "template" value is supplied, and the view callable returns a dictionary, the associated template is rendered with the dictionary as keyword arguments. --- repoze/bfg/tests/test_templating.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'repoze/bfg/tests/test_templating.py') diff --git a/repoze/bfg/tests/test_templating.py b/repoze/bfg/tests/test_templating.py index 6b317fb7d..c3894cce4 100644 --- a/repoze/bfg/tests/test_templating.py +++ b/repoze/bfg/tests/test_templating.py @@ -142,6 +142,37 @@ class TestRendererFromCache(unittest.TestCase): self.assertNotEqual(queryUtility(ITemplateRenderer, name=spec), None) +class TestRendererFromPath(unittest.TestCase): + def setUp(self): + cleanUp() + + def tearDown(self): + cleanUp() + + def _callFUT(self, path, level=4, **kw): + from repoze.bfg.templating import renderer_from_path + return renderer_from_path(path, level, **kw) + + def test_with_default(self): + from repoze.bfg.templating import TextTemplateRenderer + import os + here = os.path.dirname(os.path.abspath(__file__)) + fixture = os.path.join(here, 'fixtures/minimal.txt') + result = self._callFUT(fixture) + self.assertEqual(result.__class__, TextTemplateRenderer) + + def test_with_nondefault(self): + from repoze.bfg.interfaces import ITemplateRendererFactory + import os + here = os.path.dirname(os.path.abspath(__file__)) + fixture = os.path.join(here, 'fixtures/minimal.pt') + renderer = {} + def factory(path, **kw): + return renderer + testing.registerUtility(factory, ITemplateRendererFactory, name='.pt') + result = self._callFUT(fixture) + self.assertEqual(result, renderer) + class DummyFactory: def __init__(self, renderer): self.renderer = renderer -- cgit v1.2.3