vendor/Five/1.2b-r20590

view browser/tests/test_absoluteurl.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 AbsoluteURL
16 $Id: test_absoluteurl.py 17853 2005-09-25 13:34:25Z tseaver $
17 """
18 import os, sys
19 if __name__ == '__main__':
20 execfile(os.path.join(sys.path[0], 'framework.py'))
22 def test_absoluteurl():
23 """This tests the absolute url view (IAbsoluteURL or @@absolute_url),
24 in particular the breadcrumb functionality.
26 First we make some preparations:
28 >>> import Products.Five
29 >>> from Products.Five import zcml
30 >>> zcml.load_config("configure.zcml", Products.Five)
32 >>> from Products.Five.tests.testing import manage_addFiveTraversableFolder
33 >>> manage_addFiveTraversableFolder(self.folder, 'testoid', 'Testoid')
35 A simple traversal will yield us the @@absolute_url view:
37 >>> view = self.folder.unrestrictedTraverse('testoid/@@absolute_url')
38 >>> view()
39 'http://nohost/test_folder_1_/testoid'
41 IAbsoluteURL also defines a breadcrumbs() method that returns a
42 simple Python structure:
44 >>> for crumb in view.breadcrumbs():
45 ... info = crumb.items()
46 ... info.sort()
47 ... info
48 [('name', ''), ('url', 'http://nohost')]
49 [('name', 'test_folder_1_'), ('url', 'http://nohost/test_folder_1_')]
50 [('name', 'testoid'), ('url', 'http://nohost/test_folder_1_/testoid')]
52 This test assures and demonstrates that the absolute url stops
53 traversing through an object's parents when it has reached the
54 root object. In Zope 3 this is marked with the IContainmentRoot
55 interface:
57 >>> from zope.interface import directlyProvides, providedBy
58 >>> from zope.app.traversing.interfaces import IContainmentRoot
59 >>> directlyProvides(self.folder, IContainmentRoot)
61 >>> for crumb in view.breadcrumbs():
62 ... info = crumb.items()
63 ... info.sort()
64 ... info
65 [('name', 'test_folder_1_'), ('url', 'http://nohost/test_folder_1_')]
66 [('name', 'testoid'), ('url', 'http://nohost/test_folder_1_/testoid')]
68 >>> directlyProvides(self.folder,
69 ... providedBy(self.folder) - IContainmentRoot)
71 The absolute url view is obviously not affected by virtual hosting:
73 >>> request = self.app.REQUEST
74 >>> request['PARENTS'] = [self.folder.test_folder_1_]
75 >>> url = request.setServerURL(
76 ... protocol='http', hostname='foo.bar.com', port='80')
77 >>> request.setVirtualRoot('')
79 >>> for crumb in view.breadcrumbs():
80 ... info = crumb.items()
81 ... info.sort()
82 ... info
83 [('name', 'test_folder_1_'), ('url', 'http://foo.bar.com')]
84 [('name', 'testoid'), ('url', 'http://foo.bar.com/testoid')]
87 Clean up:
89 >>> from zope.app.tests.placelesssetup import tearDown
90 >>> tearDown()
91 """
93 def test_suite():
94 from Testing.ZopeTestCase import ZopeDocTestSuite
95 return ZopeDocTestSuite()
97 if __name__ == '__main__':
98 framework()