From 1dc3907e59995852d5ee0251c1c92a360f03ed35 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 18 Oct 2009 05:50:54 +0000 Subject: - The ``@bfg_view`` decorator can now be used against a class method:: from webob import Response from repoze.bfg.view import bfg_view class MyView(object): def __init__(self, context, request): self.context = context self.request = request @bfg_view(name='hello') def amethod(self): return Response('hello from %s!' % self.context) When the bfg_view decorator is used against a class method, a view is registered for the *class* (it's a "class view" where the "attr" happens to be the method they're attached to), so the view class must have a suitable constructor. --- repoze/bfg/tests/test_integration.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 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 691d64e24..f05601031 100644 --- a/repoze/bfg/tests/test_integration.py +++ b/repoze/bfg/tests/test_integration.py @@ -109,9 +109,8 @@ class TestGrokkedApp(unittest.TestCase): actions = zcml_configure('configure.zcml', package) actions.sort() - num = 18 + num = 23 - action_names = [actions[x][0][2] for x in range(len(actions[:num]))] action_types = [(actions[x][0][1], actions[x][0][3], actions[x][0][4]) for x in range(len(actions[:num]))] @@ -119,6 +118,9 @@ class TestGrokkedApp(unittest.TestCase): for typ in action_types: self.assertEqual(typ, (None, IRequest, IView)) + action_names = [actions[x][0][2] for x in range(len(actions[:num]))] + action_names.sort() + self.assertEqual( action_names, [ '', @@ -132,13 +134,18 @@ class TestGrokkedApp(unittest.TestCase): 'another_stacked2', 'another_stacked_class1', 'another_stacked_class2', + 'basemethod', 'grokked_class', 'grokked_instance', + 'method1', + 'method2', 'oldstyle_grokked_class', 'stacked1', 'stacked2', 'stacked_class1', 'stacked_class2', + 'stacked_method1', + 'stacked_method2', ] ) @@ -206,6 +213,21 @@ class TestGrokkedApp(unittest.TestCase): result = render_view_to_response(ctx, req, 'another_stacked_class2') self.assertEqual(result, 'another_stacked_class') + self.assertRaises(TypeError, + render_view_to_response, ctx, req, 'basemethod') + + result = render_view_to_response(ctx, req, 'method1') + self.assertEqual(result, 'method1') + + result = render_view_to_response(ctx, req, 'method2') + self.assertEqual(result, 'method2') + + result = render_view_to_response(ctx, req, 'stacked_method1') + self.assertEqual(result, 'stacked_method') + + result = render_view_to_response(ctx, req, 'stacked_method2') + self.assertEqual(result, 'stacked_method') + class DummyContext(object): pass -- cgit v1.2.3