1 | # |
---|
2 | # Test installation script |
---|
3 | # |
---|
4 | |
---|
5 | import os, sys, string |
---|
6 | if __name__ == '__main__': |
---|
7 | execfile(os.path.join(sys.path[0], 'framework.py')) |
---|
8 | |
---|
9 | from Products.PloneTestCase import PloneTestCase |
---|
10 | from Products.CMFCore.utils import getToolByName |
---|
11 | from Products.CMFQuickInstallerTool.InstalledProduct import InstalledProduct |
---|
12 | |
---|
13 | try: |
---|
14 | from Products.CMFCore.CMFCorePermissions import ManagePortal |
---|
15 | except: |
---|
16 | from Products.CMFCore.permissions import ManagePortal |
---|
17 | |
---|
18 | from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager |
---|
19 | import re |
---|
20 | |
---|
21 | from Products.qSEOptimizer.config import * |
---|
22 | |
---|
23 | props = {'stop_words':STOP_WORDS, 'fields':FIELDS, 'additional_keywords': []} |
---|
24 | |
---|
25 | configlets = ({'id':'qSEOptimizer', |
---|
26 | 'name':'Search Engine Optimizer', |
---|
27 | 'action':'string:${portal_url}/prefs_qseo_setup_form', |
---|
28 | 'condition':'', |
---|
29 | 'category':'Products', |
---|
30 | 'visible':1, |
---|
31 | 'appId':'qSEOptimizer', |
---|
32 | 'permission':ManagePortal},) |
---|
33 | |
---|
34 | PRODUCT = 'qSEOptimizer' |
---|
35 | qSEO_CONTENT = ['File','Document','News Item','BlogEntry'] |
---|
36 | qSEO_FOLDER = [] |
---|
37 | qSEO_TYPES = qSEO_CONTENT + qSEO_FOLDER |
---|
38 | |
---|
39 | PloneTestCase.installProduct('Five') |
---|
40 | PloneTestCase.installProduct(PRODUCT) |
---|
41 | PloneTestCase.setupPloneSite() |
---|
42 | |
---|
43 | """ |
---|
44 | class TestBeforeInstall(PloneTestCase.FunctionalTestCase): |
---|
45 | |
---|
46 | def afterSetUp(self): |
---|
47 | self.basic_auth = 'mgr:mgrpw' |
---|
48 | self.portal_path = '/%s' % self.portal.absolute_url(1) |
---|
49 | |
---|
50 | def testAccessPortalRootAnonymous(self): |
---|
51 | response = self.publish(self.portal_path) |
---|
52 | self.assertEqual(response.getStatus(), 200) |
---|
53 | |
---|
54 | def testAccessPortalRootAuthenticated(self): |
---|
55 | response = self.publish(self.portal_path, self.basic_auth) |
---|
56 | self.assertEqual(response.getStatus(), 200) |
---|
57 | """ |
---|
58 | |
---|
59 | class TestInstallation(PloneTestCase.PloneTestCase): |
---|
60 | |
---|
61 | def afterSetUp(self): |
---|
62 | self.properties = getToolByName(self.portal, 'portal_properties') |
---|
63 | self.qi = self.portal.portal_quickinstaller |
---|
64 | self.qi.installProduct(PRODUCT) |
---|
65 | |
---|
66 | def testAddingPropertySheet(self): |
---|
67 | """ Test adding property sheet to portal_properties tool """ |
---|
68 | self.failUnless(hasattr(self.properties.aq_base, PROPERTY_SHEET)) |
---|
69 | |
---|
70 | def testAddingPropertyFields(self): |
---|
71 | """ Test adding property field to portal_properties.maps_properties sheet """ |
---|
72 | map_sheet = self.properties[PROPERTY_SHEET] |
---|
73 | for key, value in props.items(): |
---|
74 | self.failUnless(map_sheet.hasProperty(key) and list(map_sheet.getProperty(key)) == value) |
---|
75 | |
---|
76 | def test_configlet_install(self): |
---|
77 | configTool = getToolByName(self.portal, 'portal_controlpanel', None) |
---|
78 | self.assert_(PRODUCT in [a.getId() for a in configTool.listActions()], 'Configlet not found') |
---|
79 | |
---|
80 | def test_actions_install(self): |
---|
81 | portal_types = getToolByName(self.portal, 'portal_types') |
---|
82 | for ptype in portal_types.objectValues(): |
---|
83 | try: |
---|
84 | #for Plone-2.5 and higher |
---|
85 | acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions()) |
---|
86 | action = acts and acts[0] or None |
---|
87 | except AttributeError: |
---|
88 | action = ptype.getActionById('seo_properties', default=None ) |
---|
89 | |
---|
90 | if ptype.getId() in qSEO_TYPES: |
---|
91 | self.assert_(action, 'Action for %s not found' % ptype.getId()) |
---|
92 | else: |
---|
93 | self.assert_(not action, 'Action found for %s' % ptype.getId()) |
---|
94 | |
---|
95 | def test_skins_install(self): |
---|
96 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
97 | |
---|
98 | for skin in skinstool.getSkinSelections(): |
---|
99 | path = skinstool.getSkinPath(skin) |
---|
100 | path = map( string.strip, string.split( path,',' ) ) |
---|
101 | self.assert_(PRODUCT in path, 'qSEOptimizer layer not found in %s' %skin) |
---|
102 | |
---|
103 | def test_versionedskin_install(self): |
---|
104 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
105 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
106 | plone_version = mtool.getFileSystemVersion() |
---|
107 | if plone_version < "3": |
---|
108 | for skin in skinstool.getSkinSelections(): |
---|
109 | path = skinstool.getSkinPath(skin) |
---|
110 | path = map( string.strip, string.split( path,',' ) ) |
---|
111 | self.assert_(PRODUCT+'/%s' % plone_version in path, 'qSEOptimizer versioned layer not found in %s' %skin) |
---|
112 | |
---|
113 | def test_actions_uninstall(self): |
---|
114 | self.qi.uninstallProducts([PRODUCT]) |
---|
115 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
116 | portal_types = getToolByName(self.portal, 'portal_types') |
---|
117 | for ptype in portal_types.objectValues(): |
---|
118 | try: |
---|
119 | #for Plone-2.5 and higher |
---|
120 | acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions()) |
---|
121 | action = acts and acts[0] or None |
---|
122 | except AttributeError: |
---|
123 | action = ptype.getActionById('seo_properties', default=None ) |
---|
124 | |
---|
125 | self.assert_(not action, 'Action for %s found after uninstallation' % ptype.getId()) |
---|
126 | |
---|
127 | def test_skins_uninstall(self): |
---|
128 | self.qi.uninstallProducts([PRODUCT]) |
---|
129 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
130 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
131 | |
---|
132 | for skin in skinstool.getSkinSelections(): |
---|
133 | path = skinstool.getSkinPath(skin) |
---|
134 | path = map( string.strip, string.split( path,',' ) ) |
---|
135 | self.assert_(not PRODUCT in path, 'qSEOptimizer layer found in %s after uninstallation' %skin) |
---|
136 | |
---|
137 | def test_versionedskin_uninstall(self): |
---|
138 | self.qi.uninstallProducts([PRODUCT]) |
---|
139 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
140 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
141 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
142 | plone_version = mtool.getFileSystemVersion() |
---|
143 | |
---|
144 | for skin in skinstool.getSkinSelections(): |
---|
145 | path = skinstool.getSkinPath(skin) |
---|
146 | path = map( string.strip, string.split( path,',' ) ) |
---|
147 | self.assert_(not PRODUCT+'/%s' % plone_version in path, 'qSEOptimizer versioned layer found in %s after uninstallation' %skin) |
---|
148 | |
---|
149 | def test_configlet_uninstall(self): |
---|
150 | self.qi.uninstallProducts([PRODUCT]) |
---|
151 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
152 | |
---|
153 | configTool = getToolByName(self.portal, 'portal_controlpanel', None) |
---|
154 | self.assert_(not PRODUCT in [a.getId() for a in configTool.listActions()], 'Configlet found after uninstallation') |
---|
155 | |
---|
156 | |
---|
157 | class TestResponse(PloneTestCase.FunctionalTestCase): |
---|
158 | |
---|
159 | def afterSetUp(self): |
---|
160 | self.qi = self.portal.portal_quickinstaller |
---|
161 | self.qi.installProduct(PRODUCT) |
---|
162 | self.portal.changeSkin('Plone Default') |
---|
163 | |
---|
164 | self.basic_auth = 'mgr:mgrpw' |
---|
165 | self.loginAsPortalOwner() |
---|
166 | |
---|
167 | '''Preparation for functional testing''' |
---|
168 | my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
169 | my_doc = self.portal['my_doc'] |
---|
170 | |
---|
171 | my_doc.qseo_properties_edit(title='hello world', description='it is description', |
---|
172 | keywords='my1|key2', html_comment='no comments', |
---|
173 | robots='ALL', distribution='Global', title_override=1, |
---|
174 | description_override=1, keywords_override=1, |
---|
175 | html_comment_override=1, robots_override=1, |
---|
176 | distribution_override=1) |
---|
177 | |
---|
178 | wf_tool = self.portal.portal_workflow |
---|
179 | wf_tool.doActionFor(my_doc, 'publish') |
---|
180 | |
---|
181 | abs_path = "/%s" % my_doc.absolute_url(1) |
---|
182 | self.html = self.publish(abs_path, self.basic_auth).getBody() |
---|
183 | |
---|
184 | def testTitle(self): |
---|
185 | m = re.match('.*<title>\\s*hello world\\s*</title>', self.html, re.S|re.M) |
---|
186 | self.assert_(m, 'Title not set in') |
---|
187 | |
---|
188 | def testDescription(self): |
---|
189 | m = re.match('.*<meta content="it is description" name="description" />', self.html, re.S|re.M) |
---|
190 | self.assert_(m, 'Description not set in') |
---|
191 | |
---|
192 | def testKeywords(self): |
---|
193 | m = re.match('.*<meta content="my1|key2" name="keywords" />', self.html, re.S|re.M) |
---|
194 | self.assert_(m, 'Keywords not set in') |
---|
195 | |
---|
196 | def testRobots(self): |
---|
197 | m = re.match('.*<meta content="ALL" name="robots" />', self.html, re.S|re.M) |
---|
198 | self.assert_(m, 'Robots not set in') |
---|
199 | |
---|
200 | def testDistribution(self): |
---|
201 | m = re.match('.*<meta content="Global" name="distribution" />', self.html, re.S|re.M) |
---|
202 | self.assert_(m, 'Distribution not set in') |
---|
203 | |
---|
204 | def testHTMLComments(self): |
---|
205 | m = re.match('.*<!--\\s*no comments\\s*-->', self.html, re.S|re.M) |
---|
206 | self.assert_(m, 'Comments not set in') |
---|
207 | |
---|
208 | def testTagsOrder(self): |
---|
209 | m = re.search('name="description".+name="keywords"', self.html, re.S|re.M) |
---|
210 | self.assert_(m, "Meta tags order not supported.") |
---|
211 | |
---|
212 | |
---|
213 | class TestAdditionalKeywords(PloneTestCase.FunctionalTestCase): |
---|
214 | |
---|
215 | def afterSetUp(self): |
---|
216 | self.qi = self.portal.portal_quickinstaller |
---|
217 | self.qi.installProduct(PRODUCT) |
---|
218 | self.sp = self.portal.portal_properties.seo_properties |
---|
219 | self.pu = self.portal.plone_utils |
---|
220 | self.portal.changeSkin('Plone Default') |
---|
221 | |
---|
222 | self.basic_auth = 'portal_manager:secret' |
---|
223 | uf = self.app.acl_users |
---|
224 | uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], []) |
---|
225 | user = uf.getUserById('portal_manager') |
---|
226 | if not hasattr(user, 'aq_base'): |
---|
227 | user = user.__of__(uf) |
---|
228 | newSecurityManager(None, user) |
---|
229 | |
---|
230 | '''Preparation for functional testing''' |
---|
231 | self.my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
232 | self.my_doc = self.portal['my_doc'] |
---|
233 | |
---|
234 | def test_additional_keywords_in_configlet(self): |
---|
235 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
236 | if mtool.getFileSystemVersion() < "2.5": |
---|
237 | return |
---|
238 | |
---|
239 | path = self.portal.id+'/prefs_qseo_setup?additionalKeywords=foo\nbar' |
---|
240 | self.publish(path, self.basic_auth) |
---|
241 | self.assertEqual(self.sp.additional_keywords, ('foo', 'bar')) |
---|
242 | self.publish(self.portal.id+'/prefs_qseo_setup', self.basic_auth) |
---|
243 | self.assertEqual(self.sp.additional_keywords, ()) |
---|
244 | |
---|
245 | def test_listMetaTags_empty(self): |
---|
246 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
247 | if mtool.getFileSystemVersion() < "2.5": |
---|
248 | return |
---|
249 | |
---|
250 | metatags = self.pu.listMetaTags(self.my_doc) |
---|
251 | self.assert_('keywords' not in metatags) |
---|
252 | |
---|
253 | def test_listMetaTags_one(self): |
---|
254 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
255 | if mtool.getFileSystemVersion() < "2.5": |
---|
256 | return |
---|
257 | |
---|
258 | self.my_doc.manage_addProperty('qSEO_keywords', ('foo',), 'lines') |
---|
259 | metatags = self.pu.listMetaTags(self.my_doc) |
---|
260 | keywords = metatags.get('keywords') |
---|
261 | self.assertEqual(keywords, 'foo') |
---|
262 | |
---|
263 | def test_listMetaTags_two(self): |
---|
264 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
265 | if mtool.getFileSystemVersion() < "2.5": |
---|
266 | return |
---|
267 | |
---|
268 | self.my_doc.manage_addProperty('qSEO_keywords', ('foo', 'bar'), 'lines') |
---|
269 | metatags = self.pu.listMetaTags(self.my_doc) |
---|
270 | keywords = metatags.get('keywords') |
---|
271 | self.assertEqual(keywords, 'foo, bar') |
---|
272 | |
---|
273 | def test_additional_keywords_in_listMetaTags_empty(self): |
---|
274 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
275 | if mtool.getFileSystemVersion() < "2.5": |
---|
276 | return |
---|
277 | |
---|
278 | self.sp.additional_keywords = ('foo',) |
---|
279 | metatags = self.pu.listMetaTags(self.my_doc) |
---|
280 | self.assert_('keywords' not in metatags) |
---|
281 | |
---|
282 | def test_additional_keywords_in_listMetaTags_one(self): |
---|
283 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
284 | if mtool.getFileSystemVersion() < "2.5": |
---|
285 | return |
---|
286 | |
---|
287 | self.my_doc.setText('<p>foo</p>') |
---|
288 | self.sp.additional_keywords = ('foo',) |
---|
289 | metatags = self.pu.listMetaTags(self.my_doc) |
---|
290 | keywords = metatags.get('keywords') |
---|
291 | self.assertEqual(keywords, 'foo') |
---|
292 | |
---|
293 | def test_additional_keywords_in_listMetaTags_two(self): |
---|
294 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
295 | if mtool.getFileSystemVersion() < "2.5": |
---|
296 | return |
---|
297 | |
---|
298 | self.my_doc.setText('<p>foo bar</p>') |
---|
299 | self.sp.additional_keywords = ('foo', 'bar') |
---|
300 | metatags = self.pu.listMetaTags(self.my_doc) |
---|
301 | keywords = metatags.get('keywords') |
---|
302 | self.assertEqual(keywords, 'foo, bar') |
---|
303 | |
---|
304 | def test_additional_keywords_in_listMetaTags_merge(self): |
---|
305 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
306 | if mtool.getFileSystemVersion() < "2.5": |
---|
307 | return |
---|
308 | |
---|
309 | self.my_doc.setText('<p>foo bar</p>') |
---|
310 | self.sp.additional_keywords = ('foo', 'bar') |
---|
311 | self.my_doc.manage_addProperty('qSEO_keywords', ('baz',), 'lines') |
---|
312 | metatags = self.pu.listMetaTags(self.my_doc) |
---|
313 | keywords = metatags.get('keywords') |
---|
314 | self.assertEqual(keywords, 'baz, foo, bar') |
---|
315 | |
---|
316 | |
---|
317 | class TestExposeDCMetaTags(PloneTestCase.FunctionalTestCase): |
---|
318 | |
---|
319 | def afterSetUp(self): |
---|
320 | self.qi = self.portal.portal_quickinstaller |
---|
321 | self.sp = self.portal.portal_properties.site_properties |
---|
322 | self.qi.installProduct(PRODUCT) |
---|
323 | self.portal.changeSkin('Plone Default') |
---|
324 | |
---|
325 | self.basic_auth = 'portal_manager:secret' |
---|
326 | uf = self.app.acl_users |
---|
327 | uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], []) |
---|
328 | user = uf.getUserById('portal_manager') |
---|
329 | if not hasattr(user, 'aq_base'): |
---|
330 | user = user.__of__(uf) |
---|
331 | newSecurityManager(None, user) |
---|
332 | |
---|
333 | '''Preparation for functional testing''' |
---|
334 | self.my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
335 | self.my_doc = self.portal['my_doc'] |
---|
336 | |
---|
337 | def test_exposeDCMetaTags_in_configletOn(self): |
---|
338 | path = self.portal.id+'/prefs_qseo_setup?exposeDCMetaTags=on' |
---|
339 | self.publish(path, self.basic_auth) |
---|
340 | self.assert_(self.sp.exposeDCMetaTags) |
---|
341 | |
---|
342 | def test_exposeDCMetaTags_in_configletOff(self): |
---|
343 | self.publish(self.portal.id+'/prefs_qseo_setup', self.basic_auth) |
---|
344 | self.assert_(not self.sp.exposeDCMetaTags) |
---|
345 | |
---|
346 | def test_exposeDCMetaTagsPropertyOff(self): |
---|
347 | self.sp.manage_changeProperties(exposeDCMetaTags = False) |
---|
348 | |
---|
349 | self.my_doc.qseo_properties_edit() |
---|
350 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
351 | |
---|
352 | m = re.match('.*<meta content=".*?" name="DC.format" />', self.html, re.S|re.M) or re.match('.*<meta content=".*?" name="DC.distribution" />', self.html, re.S|re.M) |
---|
353 | self.assert_(not m, 'DC meta tags avaliable when exposeDCMetaTags=False') |
---|
354 | |
---|
355 | def test_exposeDCMetaTagsPropertyOn(self): |
---|
356 | self.sp.manage_changeProperties(exposeDCMetaTags = True) |
---|
357 | |
---|
358 | self.my_doc.qseo_properties_edit() |
---|
359 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
360 | |
---|
361 | m = re.match('.*<meta content=".*?" name="DC.format" />', self.html, re.S|re.M) and re.match('.*<meta content=".*?" name="DC.distribution" />', self.html, re.S|re.M) |
---|
362 | |
---|
363 | self.assert_(m, 'DC meta tags not avaliable when createManager=True') |
---|
364 | |
---|
365 | |
---|
366 | TESTS = [TestInstallation, TestResponse, TestAdditionalKeywords, TestExposeDCMetaTags] |
---|
367 | |
---|
368 | def test_suite(): |
---|
369 | from unittest import TestSuite, makeSuite |
---|
370 | suite = TestSuite() |
---|
371 | for suite_class in TESTS: |
---|
372 | suite.addTest(makeSuite(suite_class)) |
---|
373 | |
---|
374 | return suite |
---|
375 | |
---|
376 | if __name__ == '__main__': |
---|
377 | framework() |
---|