vendor/Five/1.2b-r20590

view browser/tests/test_recurse.py @ 0:3673ed425f80

Vendor import of Five 1.2b+ (r20590)
author fguillaume
date Fri, 02 Dec 2005 20:25:42 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2004, 2005 Zope Corporation and Contributors.
4 # All Rights Reserved.
5 #
6 # This software is subject to the provisions of the Zope Public License,
7 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11 # FOR A PARTICULAR PURPOSE.
12 #
13 ##############################################################################
14 """Test default view recursion
16 $Id: test_recurse.py 14595 2005-07-12 21:26:12Z philikon $
17 """
18 import os, sys
19 if __name__ == '__main__':
20 execfile(os.path.join(sys.path[0], 'framework.py'))
22 def test_recursion():
23 """
24 Test recursion
26 >>> from zope.app.tests.placelesssetup import setUp, tearDown
27 >>> setUp()
29 This test makes sure that recursion is avoided for view lookup.
30 First, we need to set up a stub interface...
32 >>> from zope.interface import Interface, implements
33 >>> class IRecurse(Interface):
34 ... pass
35 ...
37 and a class that is callable and has a view method:
39 >>> from OFS.Traversable import Traversable
40 >>> class Recurse(Traversable):
41 ... implements(IRecurse)
42 ... def view(self):
43 ... return self()
44 ... def __call__(self):
45 ... return 'foo'
46 ...
48 Now we make the class default viewable and register a default view
49 name for it:
51 >>> from Products.Five.fiveconfigure import classDefaultViewable
52 >>> classDefaultViewable(Recurse)
54 >>> from zope.app import zapi
55 >>> from zope.publisher.interfaces.browser import IBrowserRequest
56 >>> pres = zapi.getGlobalService('Presentation')
57 >>> pres.setDefaultViewName(IRecurse, IBrowserRequest, 'view')
59 Here comes the actual test:
61 >>> ob = Recurse()
62 >>> ob.view()
63 'foo'
64 >>> ob()
65 'foo'
68 Clean up:
70 >>> tearDown()
71 """
73 def test_suite():
74 from Testing.ZopeTestCase import ZopeDocTestSuite
75 return ZopeDocTestSuite()
77 if __name__ == '__main__':
78 framework()