From 8cc399ae9291f34166bc8a8fc1983a9941b57e97 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 25 Apr 2010 21:53:04 +0000 Subject: - Add a new method of the Configurator named ``derive_view`` which can be used to generate a BFG view callable from a user-supplied function, instance, or class. This useful for external framework and plugin authors wishing to wrap callables supplied by their users which follow the same calling conventions and response conventions as objects that can be supplied directly to BFG as a view callable. See the ``derive_view`` method in the ``repoze.bfg.configuration.Configurator`` docs. --- repoze/bfg/tests/test_configuration.py | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'repoze/bfg/tests') diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py index fa18b75cb..0a443720f 100644 --- a/repoze/bfg/tests/test_configuration.py +++ b/repoze/bfg/tests/test_configuration.py @@ -1879,6 +1879,48 @@ class ConfiguratorTests(unittest.TestCase): result = config._renderer_from_name(None) self.assertEqual(result, 'OK') + def test_derive_view_function(self): + def view(request): + return 'OK' + config = self._makeOne() + result = config.derive_view(view) + self.failIf(result is view) + self.assertEqual(result(None, None), 'OK') + + def test_derive_view_with_renderer(self): + def view(request): + return 'OK' + config = self._makeOne() + class moo(object): + def __init__(self, *arg, **kw): + pass + def __call__(self, *arg, **kw): + return 'moo' + config.add_renderer('moo', moo) + result = config.derive_view(view, renderer='moo') + self.failIf(result is view) + self.assertEqual(result(None, None).body, 'moo') + + def test_derive_view_class_without_attr(self): + class View(object): + def __init__(self, request): + pass + def __call__(self): + return 'OK' + config = self._makeOne() + result = config.derive_view(View) + self.assertEqual(result(None, None), 'OK') + + def test_derive_view_class_with_attr(self): + class View(object): + def __init__(self, request): + pass + def another(self): + return 'OK' + config = self._makeOne() + result = config.derive_view(View, attr='another') + self.assertEqual(result(None, None), 'OK') + def test__derive_view_as_function_context_and_request(self): def view(context, request): return 'OK' -- cgit v1.2.3