vendor/Five/1.2b-r20590

view site/tests/functional.txt @ 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 Functional test for local sites
2 ===============================
4 Set up all of Five:
6 >>> import Products.Five
7 >>> from Products.Five import zcml
8 >>> zcml.load_config("configure.zcml", Products.Five)
10 First we turn our DummySite class into a site in ZCML (and register
11 some views that will provide us with some test info),
13 >>> zcml_text = """
14 ... <configure xmlns="http://namespaces.zope.org/zope"
15 ... xmlns:meta="http://namespaces.zope.org/meta"
16 ... xmlns:five="http://namespaces.zope.org/five"
17 ... xmlns:browser="http://namespaces.zope.org/browser">
18 ...
19 ... <!-- make the zope2.Public permission work -->
20 ... <meta:redefinePermission from="zope2.Public" to="zope.Public" />
21 ...
22 ... <five:localsite class="Products.Five.site.tests.dummy.DummySite" />
23 ...
24 ... <browser:page
25 ... for="Products.Five.site.tests.dummy.IDummySite"
26 ... name="checkServices.html"
27 ... class="Products.Five.site.tests.test_functional.CheckServicesView"
28 ... permission="zope2.Public"
29 ... />
30 ...
31 ... <browser:page
32 ... for="Products.Five.site.tests.dummy.IDummySite"
33 ... name="lookupUtilities.html"
34 ... class="Products.Five.site.tests.test_functional.LookupUtilitiesView"
35 ... permission="zope2.Public"
36 ... />
37 ...
38 ... </configure>"""
39 >>> zcml.load_string(zcml_text)
41 then we add an instance to our folder:
43 >>> from Products.Five.site.tests.dummy import manage_addDummySite
44 >>> nothing = manage_addDummySite(self.folder, 'site')
46 Now we check what the info view tells us about local component lookup:
48 >>> print http(r'''
49 ... GET /test_folder_1_/site/@@checkServices.html HTTP/1.1
50 ... ''')
51 HTTP/1.1 200 OK
52 ...
53 {'IFiveUtilityService.providedBy(utility_service)': False,
54 'isinstance(zapi.getServices(), FiveSiteManager)': False,
55 'zapi.getServices() is zapi.getGlobalServices()': True}
57 We see that we have no local component lookup yet, because we haven't
58 set the site. Therefore, enable the traversal hook by using the view
59 that's provided for this task (we first need to create a manager
60 account in order to be able to access it):
62 >>> uf = self.folder.acl_users
63 >>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
65 >>> print http(r'''
66 ... POST /test_folder_1_/site/@@manage_site.html HTTP/1.1
67 ... Authorization: Basic manager:r00t
68 ... Content-Length: 25
69 ...
70 ... UPDATE_MAKESITE=Make site''')
71 HTTP/1.1 200 OK
72 ...
74 Now we call the info view again and find that local component lookup
75 is working:
77 >>> print http(r'''
78 ... GET /test_folder_1_/site/@@checkServices.html HTTP/1.1
79 ... ''')
80 HTTP/1.1 200 OK
81 ...
82 {'IFiveUtilityService.providedBy(utility_service)': True,
83 'isinstance(zapi.getServices(), FiveSiteManager)': True,
84 'zapi.getServices() is zapi.getGlobalServices()': False}
86 Of course, sites are only active *during* traversal; after traversal
87 they're gone:
89 >>> from zope.app.component.hooks import getSite
90 >>> getSite() is None
91 True
94 We can also register utilities now:
96 >>> from zope.app import zapi
97 >>> sm = self.folder.site.getSiteManager()
99 >>> from Products.Five.site.tests.dummy import IDummyUtility, DummyUtility
100 >>> dummy = DummyUtility()
101 >>> sm.registerUtility(IDummyUtility, dummy)
103 and find them being looked up just fine:
105 >>> print http(r'''
106 ... GET /test_folder_1_/site/@@lookupUtilities.html HTTP/1.1
107 ... ''')
108 HTTP/1.1 200 OK
109 ...
110 zapi.getUtility(IDummyUtility) == dummy: True
112 Of course, we can't look it up once the request has ended, because we
113 lose the local site setup:
115 >>> zapi.getUtility(IDummyUtility)
116 Traceback (most recent call last):
117 ...
118 ComponentLookupError: (<InterfaceClass Products.Five.site.tests.dummy.IDummyUtility>, '')
120 At last we can "unmake" the site using the browser view provided by
121 Five:
123 >>> print http(r'''
124 ... POST /test_folder_1_/site/@@manage_site.html HTTP/1.1
125 ... Authorization: Basic manager:r00t
126 ... Content-Length: 29
127 ...
128 ... UPDATE_UNMAKESITE=Unmake site''')
129 HTTP/1.1 200 OK
130 ...
132 And everything is back to normal with respect to local component
133 lookup:
135 >>> print http(r'''
136 ... GET /test_folder_1_/site/@@checkServices.html HTTP/1.1
137 ... ''')
138 HTTP/1.1 200 OK
139 ...
140 {'IFiveUtilityService.providedBy(utility_service)': False,
141 'isinstance(zapi.getServices(), FiveSiteManager)': False,
142 'zapi.getServices() is zapi.getGlobalServices()': True}
144 Finally, global services and the monkeys:
146 >>> from zope.app.tests.placelesssetup import tearDown
147 >>> tearDown()