diff options
| author | Chris McDonough <chrism@agendaless.com> | 2010-04-25 21:53:04 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2010-04-25 21:53:04 +0000 |
| commit | 8cc399ae9291f34166bc8a8fc1983a9941b57e97 (patch) | |
| tree | 7c11a39f2926593e85d158ba9d7a056a235c7eb5 /repoze/bfg/tests | |
| parent | 30b89889183acb9243f13cc141fae08a22b2d317 (diff) | |
| download | pyramid-8cc399ae9291f34166bc8a8fc1983a9941b57e97.tar.gz pyramid-8cc399ae9291f34166bc8a8fc1983a9941b57e97.tar.bz2 pyramid-8cc399ae9291f34166bc8a8fc1983a9941b57e97.zip | |
- 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.
Diffstat (limited to 'repoze/bfg/tests')
| -rw-r--r-- | repoze/bfg/tests/test_configuration.py | 42 |
1 files changed, 42 insertions, 0 deletions
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' |
