vendor/Five/1.2b-r20590

view tests/test_viewable.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 """Unit tests for the viewable module.
16 $Id: test_viewable.py 19645 2005-11-08 15:45:35Z yuppie $
17 """
18 import os, sys
19 if __name__ == '__main__':
20 execfile(os.path.join(sys.path[0], 'framework.py'))
22 def test_defaultView():
23 """
24 Testing default view functionality
26 >>> from zope.app.tests.placelesssetup import setUp, tearDown
27 >>> setUp()
29 Take a class Foo and an interface IFoo:
31 >>> class Foo:
32 ... pass
34 >>> from zope.interface import Interface
35 >>> class IFoo(Interface):
36 ... pass
38 Set up a default view for IFoo:
40 >>> from zope.app import zapi
41 >>> pres = zapi.getGlobalService('Presentation')
42 >>> from zope.publisher.interfaces.browser import IBrowserRequest
44 and default view names for everything and IFoo objects in particular:
46 >>> pres.setDefaultViewName(None, IBrowserRequest, u'index.html')
47 >>> pres.setDefaultViewName(IFoo, IBrowserRequest, u'foo.html')
49 Now take a BrowserDefault for an instance of Foo::
51 >>> foo = Foo()
52 >>> from Products.Five.viewable import BrowserDefault
53 >>> bd = BrowserDefault(foo)
55 For now the default view name is index.html, like we set above:
57 >>> from Products.Five.traversable import FakeRequest
58 >>> request = FakeRequest()
60 >>> obj, path = bd.defaultView(request)
61 >>> obj is foo
62 True
63 >>> path
64 [u'index.html']
66 until we mark the object with IFoo:
68 >>> from zope.interface import directlyProvides
69 >>> directlyProvides(foo, IFoo)
70 >>> obj, path = bd.defaultView(request)
71 >>> obj is foo
72 True
73 >>> path
74 [u'foo.html']
77 Clean up:
79 >>> tearDown()
80 """
82 def test_suite():
83 import unittest
84 from Products.Five.testing.doctest import DocTestSuite
85 from Testing.ZopeTestCase import FunctionalDocFileSuite
86 return unittest.TestSuite((
87 DocTestSuite(),
88 FunctionalDocFileSuite('viewable.txt',
89 package="Products.Five.tests",),
90 ))
92 if __name__ == '__main__':
93 framework()