[1] | 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} |
---|
| 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(PRODUCT) |
---|
| 40 | PloneTestCase.setupPloneSite() |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | class TestInstallation(PloneTestCase.PloneTestCase): |
---|
| 44 | |
---|
| 45 | def afterSetUp(self): |
---|
| 46 | self.properties = getToolByName(self.portal, 'portal_properties') |
---|
| 47 | self.qi = self.portal.portal_quickinstaller |
---|
| 48 | self.qi.installProduct(PRODUCT) |
---|
| 49 | |
---|
| 50 | def testAddingPropertySheet(self): |
---|
| 51 | """ Test adding property sheet to portal_properties tool """ |
---|
| 52 | self.failUnless(hasattr(self.properties.aq_base, PROPERTY_SHEET)) |
---|
| 53 | |
---|
| 54 | def testAddingPropertyFields(self): |
---|
| 55 | """ Test adding property field to portal_properties.maps_properties sheet """ |
---|
| 56 | map_sheet = self.properties[PROPERTY_SHEET] |
---|
| 57 | for key, value in props.items(): |
---|
| 58 | self.failUnless(map_sheet.hasProperty(key) and list(map_sheet.getProperty(key)) == value) |
---|
| 59 | |
---|
| 60 | def test_configlet_install(self): |
---|
| 61 | configTool = getToolByName(self.portal, 'portal_controlpanel', None) |
---|
| 62 | self.assert_(PRODUCT in [a.getId() for a in configTool.listActions()], 'Configlet not found') |
---|
| 63 | |
---|
| 64 | def test_actions_install(self): |
---|
| 65 | portal_types = getToolByName(self.portal, 'portal_types') |
---|
| 66 | for ptype in portal_types.objectValues(): |
---|
| 67 | try: |
---|
| 68 | #for Plone-2.5 and higher |
---|
| 69 | acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions()) |
---|
| 70 | action = acts and acts[0] or None |
---|
| 71 | except AttributeError: |
---|
| 72 | action = ptype.getActionById('seo_properties', default=None ) |
---|
| 73 | |
---|
| 74 | if ptype.getId() in qSEO_TYPES: |
---|
| 75 | self.assert_(action, 'Action for %s not found' % ptype.getId()) |
---|
| 76 | else: |
---|
| 77 | self.assert_(not action, 'Action found for %s' % ptype.getId()) |
---|
| 78 | |
---|
| 79 | def test_skins_install(self): |
---|
| 80 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 81 | |
---|
| 82 | for skin in skinstool.getSkinSelections(): |
---|
| 83 | path = skinstool.getSkinPath(skin) |
---|
| 84 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 85 | self.assert_(PRODUCT in path, 'qSEOptimizer layer not found in %s' %skin) |
---|
| 86 | |
---|
| 87 | def test_versionedskin_install(self): |
---|
| 88 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 89 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
| 90 | plone_version = mtool.getFileSystemVersion() |
---|
| 91 | if plone_version < "3": |
---|
| 92 | for skin in skinstool.getSkinSelections(): |
---|
| 93 | path = skinstool.getSkinPath(skin) |
---|
| 94 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 95 | self.assert_(PRODUCT+'/%s' % plone_version in path, 'qSEOptimizer versioned layer not found in %s' %skin) |
---|
| 96 | |
---|
| 97 | def test_actions_uninstall(self): |
---|
| 98 | self.qi.uninstallProducts([PRODUCT]) |
---|
| 99 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
| 100 | portal_types = getToolByName(self.portal, 'portal_types') |
---|
| 101 | for ptype in portal_types.objectValues(): |
---|
| 102 | try: |
---|
| 103 | #for Plone-2.5 and higher |
---|
| 104 | acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions()) |
---|
| 105 | action = acts and acts[0] or None |
---|
| 106 | except AttributeError: |
---|
| 107 | action = ptype.getActionById('seo_properties', default=None ) |
---|
| 108 | |
---|
| 109 | self.assert_(not action, 'Action for %s found after uninstallation' % ptype.getId()) |
---|
| 110 | |
---|
| 111 | def test_skins_uninstall(self): |
---|
| 112 | self.qi.uninstallProducts([PRODUCT]) |
---|
| 113 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
| 114 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 115 | |
---|
| 116 | for skin in skinstool.getSkinSelections(): |
---|
| 117 | path = skinstool.getSkinPath(skin) |
---|
| 118 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 119 | self.assert_(not PRODUCT in path, 'qSEOptimizer layer found in %s after uninstallation' %skin) |
---|
| 120 | |
---|
| 121 | def test_versionedskin_uninstall(self): |
---|
| 122 | self.qi.uninstallProducts([PRODUCT]) |
---|
| 123 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
| 124 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 125 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
| 126 | plone_version = mtool.getFileSystemVersion() |
---|
| 127 | |
---|
| 128 | for skin in skinstool.getSkinSelections(): |
---|
| 129 | path = skinstool.getSkinPath(skin) |
---|
| 130 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 131 | self.assert_(not PRODUCT+'/%s' % plone_version in path, 'qSEOptimizer versioned layer found in %s after uninstallation' %skin) |
---|
| 132 | |
---|
| 133 | def test_configlet_uninstall(self): |
---|
| 134 | self.qi.uninstallProducts([PRODUCT]) |
---|
| 135 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
| 136 | |
---|
| 137 | configTool = getToolByName(self.portal, 'portal_controlpanel', None) |
---|
| 138 | self.assert_(not PRODUCT in [a.getId() for a in configTool.listActions()], 'Configlet found after uninstallation') |
---|
| 139 | |
---|
| 140 | class TestResponse(PloneTestCase.FunctionalTestCase): |
---|
| 141 | |
---|
| 142 | def afterSetUp(self): |
---|
| 143 | self.qi = self.portal.portal_quickinstaller |
---|
| 144 | self.qi.installProduct(PRODUCT) |
---|
| 145 | self.portal.changeSkin('Plone Default') |
---|
| 146 | |
---|
| 147 | self.basic_auth = 'mgr:mgrpw' |
---|
| 148 | self.loginAsPortalOwner() |
---|
| 149 | |
---|
| 150 | '''Preparation for functional testing''' |
---|
| 151 | my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
| 152 | my_doc = self.portal['my_doc'] |
---|
| 153 | |
---|
| 154 | my_doc.qseo_properties_edit(title='hello world', description='it is description', |
---|
| 155 | keywords='my1|key2', html_comment='no comments', |
---|
| 156 | robots='ALL', distribution='Global', title_override=1, |
---|
| 157 | description_override=1, keywords_override=1, |
---|
| 158 | html_comment_override=1, robots_override=1, |
---|
| 159 | distribution_override=1) |
---|
| 160 | |
---|
| 161 | wf_tool = self.portal.portal_workflow |
---|
| 162 | wf_tool.doActionFor(my_doc, 'publish') |
---|
| 163 | |
---|
| 164 | abs_path = "/%s" % my_doc.absolute_url(1) |
---|
| 165 | self.html = self.publish(abs_path, self.basic_auth).getBody() |
---|
| 166 | |
---|
| 167 | def testTitle(self): |
---|
| 168 | m = re.match('.*<title>\\s*hello world\\s*</title>', self.html, re.S|re.M) |
---|
| 169 | self.assert_(m, 'Title not set in') |
---|
| 170 | |
---|
| 171 | def testDescription(self): |
---|
| 172 | m = re.match('.*<meta content="it is description" name="description" />', self.html, re.S|re.M) |
---|
| 173 | self.assert_(m, 'Description not set in') |
---|
| 174 | |
---|
| 175 | def testKeywords(self): |
---|
| 176 | m = re.match('.*<meta content="my1|key2" name="keywords" />', self.html, re.S|re.M) |
---|
| 177 | self.assert_(m, 'Keywords not set in') |
---|
| 178 | |
---|
| 179 | def testRobots(self): |
---|
| 180 | m = re.match('.*<meta content="ALL" name="robots" />', self.html, re.S|re.M) |
---|
| 181 | self.assert_(m, 'Robots not set in') |
---|
| 182 | |
---|
| 183 | def testDistribution(self): |
---|
| 184 | m = re.match('.*<meta content="Global" name="distribution" />', self.html, re.S|re.M) |
---|
| 185 | self.assert_(m, 'Distribution not set in') |
---|
| 186 | |
---|
| 187 | def testHTMLComments(self): |
---|
| 188 | m = re.match('.*<!--\\s*no comments\\s*-->', self.html, re.S|re.M) |
---|
| 189 | self.assert_(m, 'Comments not set in') |
---|
| 190 | |
---|
| 191 | def testTagsOrder(self): |
---|
| 192 | m = re.search('name="description".+name="keywords"', self.html, re.S|re.M) |
---|
| 193 | self.assert_(m, "Meta tags order not supported.") |
---|
| 194 | |
---|
| 195 | class TestExposeDCMetaTags(PloneTestCase.FunctionalTestCase): |
---|
| 196 | |
---|
| 197 | def afterSetUp(self): |
---|
| 198 | self.qi = self.portal.portal_quickinstaller |
---|
| 199 | self.sp = self.portal.portal_properties.site_properties |
---|
| 200 | self.qi.installProduct(PRODUCT) |
---|
| 201 | self.portal.changeSkin('Plone Default') |
---|
| 202 | |
---|
| 203 | self.basic_auth = 'portal_manager:secret' |
---|
| 204 | uf = self.app.acl_users |
---|
| 205 | uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], []) |
---|
| 206 | user = uf.getUserById('portal_manager') |
---|
| 207 | if not hasattr(user, 'aq_base'): |
---|
| 208 | user = user.__of__(uf) |
---|
| 209 | newSecurityManager(None, user) |
---|
| 210 | |
---|
| 211 | '''Preparation for functional testing''' |
---|
| 212 | self.my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
| 213 | self.my_doc = self.portal['my_doc'] |
---|
| 214 | |
---|
| 215 | def test_exposeDCMetaTags_in_configletOn(self): |
---|
| 216 | path = self.portal.id+'/prefs_qseo_setup?exposeDCMetaTags=on' |
---|
| 217 | self.publish(path, self.basic_auth) |
---|
| 218 | self.assert_(self.sp.exposeDCMetaTags) |
---|
| 219 | |
---|
| 220 | def test_exposeDCMetaTags_in_configletOff(self): |
---|
| 221 | self.publish(self.portal.id+'/prefs_qseo_setup', self.basic_auth) |
---|
| 222 | self.assert_(not self.sp.exposeDCMetaTags) |
---|
| 223 | |
---|
| 224 | def test_exposeDCMetaTagsPropertyOff(self): |
---|
| 225 | self.sp.manage_changeProperties(exposeDCMetaTags = False) |
---|
| 226 | |
---|
| 227 | self.my_doc.qseo_properties_edit() |
---|
| 228 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
| 229 | |
---|
| 230 | 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) |
---|
| 231 | self.assert_(not m, 'DC meta tags avaliable when exposeDCMetaTags=False') |
---|
| 232 | |
---|
| 233 | def test_exposeDCMetaTagsPropertyOn(self): |
---|
| 234 | self.sp.manage_changeProperties(exposeDCMetaTags = True) |
---|
| 235 | |
---|
| 236 | self.my_doc.qseo_properties_edit() |
---|
| 237 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
| 238 | |
---|
| 239 | 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) |
---|
| 240 | |
---|
| 241 | self.assert_(m, 'DC meta tags not avaliable when createManager=True') |
---|
| 242 | |
---|
| 243 | TESTS = [TestInstallation, TestResponse, TestExposeDCMetaTags] |
---|
| 244 | |
---|
| 245 | def test_suite(): |
---|
| 246 | from unittest import TestSuite, makeSuite |
---|
| 247 | suite = TestSuite() |
---|
| 248 | suite.addTest(makeSuite(TestInstallation)) |
---|
| 249 | suite.addTest(makeSuite(TestResponse)) |
---|
| 250 | suite.addTest(makeSuite(TestExposeDCMetaTags)) |
---|
| 251 | return suite |
---|
| 252 | |
---|
| 253 | if __name__ == '__main__': |
---|
| 254 | framework() |
---|
| 255 | |
---|