From 5a11e2ad0828b7c763d0c81211f686a85bc0324c Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 21 May 2009 16:01:58 +0000 Subject: - Class objects may now be used as view callables (both via ZCML and via use of the ``bfg_view`` decorator in Python 2.6 as a class decorator). The calling semantics when using a class as a view callable is similar to that of using a class as a Zope "browser view": the class' ``__init__`` must accept two positional parameters (conventionally named ``context``, and ``request``). The resulting instance must be callable (it must have a ``__call__`` method). When called, the instance should return a response. For example:: from webob import Response class MyView(object): def __init__(self, context, request): self.context = context self.request = request def __call__(self): return Response('hello from %s!' % self.context) See the "Views" chapter in the documentation and the ``repoze.bfg.view`` API documentation for more information. --- repoze/bfg/tests/test_integration.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'repoze/bfg/tests/test_integration.py') diff --git a/repoze/bfg/tests/test_integration.py b/repoze/bfg/tests/test_integration.py index 8c088fce0..fdb85b87e 100644 --- a/repoze/bfg/tests/test_integration.py +++ b/repoze/bfg/tests/test_integration.py @@ -1,4 +1,5 @@ import os +import sys import unittest from repoze.bfg.push import pushpage @@ -142,8 +143,8 @@ class TestGrokkedApp(unittest.TestCase): cleanUp() def test_it(self): + import inspect import repoze.bfg.tests.grokkedapp as package - from zope.configuration import config from zope.configuration import xmlconfig context = config.ConfigurationMachine() @@ -151,7 +152,14 @@ class TestGrokkedApp(unittest.TestCase): context.package = package xmlconfig.include(context, 'configure.zcml', package) actions = context.actions - self.failUnless(actions) + klassview = actions[-1] + self.assertEqual(klassview[0][2], 'grokked_klass') + self.assertEqual(klassview[2][1], package.grokked_klass) + self.failUnless(inspect.isfunction(package.grokked_klass)) + self.assertEqual(package.grokked_klass(None, None), None) + funcview = actions[-2] + self.assertEqual(funcview[0][2], '') + self.assertEqual(funcview[2][1], package.grokked) class DummyContext: pass -- cgit v1.2.3