summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests/test_integration.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-10-18 05:50:54 +0000
committerChris McDonough <chrism@agendaless.com>2009-10-18 05:50:54 +0000
commit1dc3907e59995852d5ee0251c1c92a360f03ed35 (patch)
tree38da7879503f2b55b995cee89a2aebe6c7d6f076 /repoze/bfg/tests/test_integration.py
parent2cce431f02a37c119eacfc3dfa94af9fe3305de1 (diff)
downloadpyramid-1dc3907e59995852d5ee0251c1c92a360f03ed35.tar.gz
pyramid-1dc3907e59995852d5ee0251c1c92a360f03ed35.tar.bz2
pyramid-1dc3907e59995852d5ee0251c1c92a360f03ed35.zip
- 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.
Diffstat (limited to 'repoze/bfg/tests/test_integration.py')
-rw-r--r--repoze/bfg/tests/test_integration.py26
1 files changed, 24 insertions, 2 deletions
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