1 | # This Python file uses the following encoding: utf-8 |
---|
2 | """ |
---|
3 | cache tool implementation tests |
---|
4 | |
---|
5 | $Id: test_cache_tool.py 64214 2008-05-03 02:49:17Z newbery $ |
---|
6 | """ |
---|
7 | |
---|
8 | __author__ = 'Héctor Velarde <hvelarde@jornada.com.mx>' |
---|
9 | __docformat__ = 'restructuredtext' |
---|
10 | |
---|
11 | from base import CacheFuTestCase |
---|
12 | |
---|
13 | from AccessControl import Unauthorized |
---|
14 | from Interface.Verify import verifyObject |
---|
15 | from Products.Archetypes.interfaces import IBaseFolder |
---|
16 | from Products.Archetypes.interfaces.layer import ILayerContainer |
---|
17 | from Products.CMFCore.utils import getToolByName, UniqueObject |
---|
18 | |
---|
19 | from Products.CacheSetup.config import * |
---|
20 | from Products.CacheSetup.interfaces import ICacheTool |
---|
21 | |
---|
22 | class TestCacheTool(CacheFuTestCase): |
---|
23 | |
---|
24 | def afterSetUp(self): |
---|
25 | self.tool = getattr(self.folder, CACHE_TOOL_ID) |
---|
26 | |
---|
27 | def testIsUniqueObject(self): |
---|
28 | """ a tool has to be an UniqueObject """ |
---|
29 | self.failUnless(isinstance(self.tool, UniqueObject)) |
---|
30 | |
---|
31 | def testImplementsBaseFolder(self): |
---|
32 | iface = IBaseFolder |
---|
33 | self.failUnless(iface.providedBy(self.tool)) |
---|
34 | self.failUnless(verifyObject(iface, self.tool)) |
---|
35 | |
---|
36 | def testImplementsCacheTool(self): |
---|
37 | iface = ICacheTool |
---|
38 | self.failUnless(iface.providedBy(self.tool)) |
---|
39 | self.failUnless(verifyObject(iface, self.tool)) |
---|
40 | |
---|
41 | def testTypeInfo(self): |
---|
42 | ti = self.tool.getTypeInfo() |
---|
43 | self.failUnlessEqual(ti.Title(), 'Cache Configuration Tool') |
---|
44 | self.failUnlessEqual(ti.getId(), 'CacheTool') |
---|
45 | self.failUnlessEqual(ti.Metatype(), 'CacheTool') |
---|
46 | self.failUnlessEqual(ti.globalAllow(), 0) |
---|
47 | self.failUnlessEqual(ti.getMethodAliases(), {'(Default)': 'cache_tool_config', |
---|
48 | 'view' : 'cache_tool_config', |
---|
49 | 'edit': 'base_edit'}) |
---|
50 | |
---|
51 | def testAllowedContentTypes(self): |
---|
52 | allowed = ('CachePolicy',) |
---|
53 | for t in self.tool.allowedContentTypes(): |
---|
54 | self.failUnless(t.getId() in allowed) |
---|
55 | |
---|
56 | def testActions(self): |
---|
57 | # not pretty sure about this |
---|
58 | actions = ('object/view',) |
---|
59 | ttool = getToolByName(self.portal, 'portal_types') |
---|
60 | tool = ttool['CacheTool'] |
---|
61 | # actions have ManagePortal permission set |
---|
62 | self.assertRaises(Unauthorized, tool.getActionInfo, actions) |
---|
63 | self.setRoles(['Manager','Member']) |
---|
64 | info = tool.getActionInfo(actions) |
---|
65 | self.failUnless(info is not None) |
---|
66 | self.failUnlessEqual(info['url'], '') |
---|
67 | |
---|
68 | class TestCacheToolMethods(CacheFuTestCase): |
---|
69 | |
---|
70 | def afterSetUp(self): |
---|
71 | self.tool = getattr(self.folder, CACHE_TOOL_ID) |
---|
72 | |
---|
73 | def _test_initializeArchetype(self): |
---|
74 | self.fail('not yet implemented...') |
---|
75 | |
---|
76 | # The ActivePolicy vocabulary is likely to change with each release |
---|
77 | # There probably should be a better way to keep track of these instead |
---|
78 | # of hard coding the list in the test |
---|
79 | def _test_getActivePolicyVocabulary(self): |
---|
80 | """ check against default active policy vocabulary """ |
---|
81 | vocab = ( |
---|
82 | ('default-cache-policy', 'Default Cache Policy'), |
---|
83 | ('no-proxy-cache', 'No Proxy Cache'), |
---|
84 | ('default-cache-policy-v2', 'Default Cache Policy, slightly improved'), |
---|
85 | ('squid-without-vary', 'Squid without Vary header (Note: Turn off compression)') |
---|
86 | ) |
---|
87 | for i in self.tool.getActivePolicyVocabulary().items(): |
---|
88 | self.failUnless(i in vocab) |
---|
89 | # what about testing for self.tool.getActivePolicyVocabulary(display=1) |
---|
90 | |
---|
91 | def test_getActivePolicyId(self): |
---|
92 | self.failUnlessEqual(self.tool.getActivePolicyId(), DEFAULT_POLICY_ID) |
---|
93 | # need to test this after erasing the default one |
---|
94 | |
---|
95 | def _test_setDisplayPolicy(self): |
---|
96 | self.fail('not yet implemented...') |
---|
97 | |
---|
98 | def _test_setEnabled(self): |
---|
99 | self.fail('not yet implemented...') |
---|
100 | |
---|
101 | def _test_getPolicy(self): |
---|
102 | self.fail('not yet implemented...') |
---|
103 | |
---|
104 | def _test_getDisplayPolicy(self): |
---|
105 | self.fail('not yet implemented...') |
---|
106 | |
---|
107 | # The details of the cache policies are subject to change with each release |
---|
108 | # There probably should be a better way to keep track of this instead of |
---|
109 | # hard coding the lists in the tests |
---|
110 | def _test_getRules(self): |
---|
111 | """ test rules for all policies """ |
---|
112 | # right now all policies have the same rules |
---|
113 | rules = ( |
---|
114 | 'httpcache', 'plone-content-types', 'plone-containers', |
---|
115 | 'plone-templates', 'resource-registries', 'downloads', 'dtml-css' |
---|
116 | ) |
---|
117 | ids = (None, ) + POLICY_IDS # None is for default |
---|
118 | for id in ids: |
---|
119 | for r, t in self.tool.getRules(policy_id=id).items(): |
---|
120 | self.failUnless(r in rules) |
---|
121 | # what to test against t? |
---|
122 | |
---|
123 | # The details of the cache policies are subject to change with each release |
---|
124 | # There probably should be a better way to keep track of this instead of |
---|
125 | # hard coding the lists in the tests |
---|
126 | def _test_getHeaderSets(self): |
---|
127 | """ test header sets for all policies """ |
---|
128 | # right now all policies have the same header sets |
---|
129 | header_sets = ( |
---|
130 | 'no-cache', 'cache-in-memory', 'cache-with-etag', |
---|
131 | 'cache-with-last-modified', 'cache-in-proxy-1-hour', |
---|
132 | 'cache-in-proxy-24-hours', 'cache-in-browser-1-hour', |
---|
133 | 'cache-in-browser-24-hours', 'cache-in-browser-forever' |
---|
134 | ) |
---|
135 | ids = (None, ) + POLICY_IDS # None is for default |
---|
136 | for id in ids: |
---|
137 | for hs, t in self.tool.getHeaderSets(policy_id=id).items(): |
---|
138 | self.failUnless(hs in header_sets) |
---|
139 | # what to test against t? |
---|
140 | |
---|
141 | def _test_getHeaderSetById(self): |
---|
142 | self.fail('not yet implemented...') |
---|
143 | |
---|
144 | def _test_addPolicyFolder(self): |
---|
145 | self.fail('not yet implemented...') |
---|
146 | |
---|
147 | def _test_addRulesFolder(self): |
---|
148 | self.fail('not yet implemented...') |
---|
149 | |
---|
150 | def _test_addHeaderSetsFolder(self): |
---|
151 | self.fail('not yet implemented...') |
---|
152 | |
---|
153 | def _test_incrementCatalogCount(self): |
---|
154 | self.fail('not yet implemented...') |
---|
155 | |
---|
156 | def _test_getCatalogCount(self): |
---|
157 | self.fail('not yet implemented...') |
---|
158 | |
---|
159 | def _test_incrementPermissionCount(self): |
---|
160 | self.fail('not yet implemented...') |
---|
161 | |
---|
162 | def _test_getPermissionCount(self): |
---|
163 | self.fail('not yet implemented...') |
---|
164 | |
---|
165 | def _test_getCompleteUrl(self): |
---|
166 | self.fail('not yet implemented...') |
---|
167 | |
---|
168 | def _test_getSquidUrls(self): |
---|
169 | self.fail('not yet implemented...') |
---|
170 | |
---|
171 | def _test_setSquidUrls(self): |
---|
172 | self.fail('not yet implemented...') |
---|
173 | |
---|
174 | def _test_getCompleteUrl(self): |
---|
175 | self.fail('not yet implemented...') |
---|
176 | |
---|
177 | def _test_hasPurgeableProxy(self): |
---|
178 | self.fail('not yet implemented...') |
---|
179 | |
---|
180 | def _test_getDomains(self): |
---|
181 | self.fail('not yet implemented...') |
---|
182 | |
---|
183 | def _test_setDomains(self): |
---|
184 | self.fail('not yet implemented...') |
---|
185 | |
---|
186 | def _test_getSquidURLs(self): |
---|
187 | self.fail('not yet implemented...') |
---|
188 | |
---|
189 | def _test_setSquidURLs(self): |
---|
190 | self.fail('not yet implemented...') |
---|
191 | |
---|
192 | def _test_post_validate(self): |
---|
193 | self.fail('not yet implemented...') |
---|
194 | |
---|
195 | def _test_manage_purgePageCache(self): |
---|
196 | self.fail('not yet implemented...') |
---|
197 | |
---|
198 | def _test_canAnonymousView(self): |
---|
199 | self.fail('not yet implemented...') |
---|
200 | |
---|
201 | def _test_isGzippable(self): |
---|
202 | self.fail('not yet implemented...') |
---|
203 | |
---|
204 | def _test_getRuleAndHeaderSet(self): |
---|
205 | self.fail('not yet implemented...') |
---|
206 | |
---|
207 | def _test_getUrlsToPurge(self): |
---|
208 | self.fail('not yet implemented...') |
---|
209 | |
---|
210 | def _test_getMember(self): |
---|
211 | self.fail('not yet implemented...') |
---|
212 | |
---|
213 | def _test_generateUniqueId(self): |
---|
214 | self.fail('not yet implemented...') |
---|
215 | |
---|
216 | def _test_isIDAutoGenerated(self): |
---|
217 | self.fail('not yet implemented...') |
---|
218 | |
---|
219 | def test_suite(): |
---|
220 | from unittest import TestSuite, makeSuite |
---|
221 | suite = TestSuite() |
---|
222 | suite.addTest(makeSuite(TestCacheTool)) |
---|
223 | suite.addTest(makeSuite(TestCacheToolMethods)) |
---|
224 | return suite |
---|