[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 | from Products.CMFCore.CMFCorePermissions import ManagePortal |
---|
| 13 | from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager |
---|
| 14 | import re |
---|
| 15 | |
---|
| 16 | from Products.qSEOptimizer.config import * |
---|
| 17 | |
---|
| 18 | props = {'stop_words':STOP_WORDS, 'fields':FIELDS} |
---|
| 19 | |
---|
| 20 | configlets = ({'id':'qSEOptimizer', |
---|
| 21 | 'name':'Search Engine Optimizer', |
---|
| 22 | 'action':'string:${portal_url}/prefs_qseo_setup_form', |
---|
| 23 | 'condition':'', |
---|
| 24 | 'category':'Products', |
---|
| 25 | 'visible':1, |
---|
| 26 | 'appId':'qSEOptimizer', |
---|
| 27 | 'permission':ManagePortal},) |
---|
| 28 | |
---|
| 29 | PRODUCT = 'qSEOptimizer' |
---|
| 30 | qSEO_CONTENT = ['File','Document','News Item','BlogEntry'] |
---|
| 31 | qSEO_FOLDER = [] |
---|
| 32 | qSEO_TYPES = qSEO_CONTENT + qSEO_FOLDER |
---|
| 33 | |
---|
| 34 | PloneTestCase.installProduct(PRODUCT) |
---|
| 35 | PloneTestCase.setupPloneSite() |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | class TestInstallation(PloneTestCase.PloneTestCase): |
---|
| 39 | |
---|
| 40 | def afterSetUp(self): |
---|
| 41 | self.properties = getToolByName(self.portal, 'portal_properties') |
---|
| 42 | self.qi = self.portal.portal_quickinstaller |
---|
| 43 | self.qi.installProduct(PRODUCT) |
---|
| 44 | |
---|
| 45 | def testAddingPropertySheet(self): |
---|
| 46 | """ Test adding property sheet to portal_properties tool """ |
---|
| 47 | self.failUnless(hasattr(self.properties.aq_base, PROPERTY_SHEET)) |
---|
| 48 | |
---|
| 49 | def testAddingPropertyFields(self): |
---|
| 50 | """ Test adding property field to portal_properties.maps_properties sheet """ |
---|
| 51 | map_sheet = self.properties[PROPERTY_SHEET] |
---|
| 52 | for key, value in props.items(): |
---|
| 53 | self.failUnless(map_sheet.hasProperty(key) and list(map_sheet.getProperty(key)) == value) |
---|
| 54 | |
---|
| 55 | def test_configlet_install(self): |
---|
| 56 | configTool = getToolByName(self.portal, 'portal_controlpanel', None) |
---|
| 57 | self.assert_(PRODUCT in [a.getId() for a in configTool.listActions()], 'Configlet not found') |
---|
| 58 | |
---|
| 59 | def test_actions_install(self): |
---|
| 60 | portal_types = getToolByName(self.portal, 'portal_types') |
---|
| 61 | for ptype in portal_types.objectValues(): |
---|
| 62 | action = ptype.getActionById('seo_properties', default=None ) |
---|
| 63 | if ptype.getId() in qSEO_TYPES: |
---|
| 64 | self.assert_(action, 'Action for %s not found' % ptype.getId()) |
---|
| 65 | else: |
---|
| 66 | self.assert_(not action, 'Action found for %s' % ptype.getId()) |
---|
| 67 | |
---|
| 68 | def test_skins_install(self): |
---|
| 69 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 70 | |
---|
| 71 | for skin in skinstool.getSkinSelections(): |
---|
| 72 | path = skinstool.getSkinPath(skin) |
---|
| 73 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 74 | self.assert_(PRODUCT in path, 'qSEOptimizer layer not found in %s' %skin) |
---|
| 75 | |
---|
| 76 | def test_versionedskin_install(self): |
---|
| 77 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 78 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
| 79 | plone_version = mtool.getFileSystemVersion() |
---|
| 80 | |
---|
| 81 | for skin in skinstool.getSkinSelections(): |
---|
| 82 | path = skinstool.getSkinPath(skin) |
---|
| 83 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 84 | self.assert_(PRODUCT+'/%s' % plone_version in path, 'qSEOptimizer versioned layer not found in %s' %skin) |
---|
| 85 | |
---|
| 86 | def test_actions_uninstall(self): |
---|
| 87 | self.qi.uninstallProducts([PRODUCT]) |
---|
| 88 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
| 89 | portal_types = getToolByName(self.portal, 'portal_types') |
---|
| 90 | for ptype in portal_types.objectValues(): |
---|
| 91 | action = ptype.getActionById('seo_properties', default=None ) |
---|
| 92 | self.assert_(not action, 'Action for %s found after uninstallation' % ptype.getId()) |
---|
| 93 | |
---|
| 94 | def test_skins_uninstall(self): |
---|
| 95 | self.qi.uninstallProducts([PRODUCT]) |
---|
| 96 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
| 97 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 98 | |
---|
| 99 | for skin in skinstool.getSkinSelections(): |
---|
| 100 | path = skinstool.getSkinPath(skin) |
---|
| 101 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 102 | self.assert_(not PRODUCT in path, 'qSEOptimizer layer found in %s after uninstallation' %skin) |
---|
| 103 | |
---|
| 104 | def test_versionedskin_uninstall(self): |
---|
| 105 | self.qi.uninstallProducts([PRODUCT]) |
---|
| 106 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
| 107 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 108 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
| 109 | plone_version = mtool.getFileSystemVersion() |
---|
| 110 | |
---|
| 111 | for skin in skinstool.getSkinSelections(): |
---|
| 112 | path = skinstool.getSkinPath(skin) |
---|
| 113 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 114 | self.assert_(not PRODUCT+'/%s' % plone_version in path, 'qSEOptimizer versioned layer found in %s after uninstallation' %skin) |
---|
| 115 | |
---|
| 116 | def test_configlet_uninstall(self): |
---|
| 117 | self.qi.uninstallProducts([PRODUCT]) |
---|
| 118 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
| 119 | |
---|
| 120 | configTool = getToolByName(self.portal, 'portal_controlpanel', None) |
---|
| 121 | self.assert_(not PRODUCT in [a.getId() for a in configTool.listActions()], 'Configlet found after uninstallation') |
---|
| 122 | |
---|
| 123 | class TestResponse(PloneTestCase.FunctionalTestCase): |
---|
| 124 | |
---|
| 125 | def afterSetUp(self): |
---|
| 126 | self.qi = self.portal.portal_quickinstaller |
---|
| 127 | self.qi.installProduct(PRODUCT) |
---|
| 128 | self.portal.changeSkin('Plone Default') |
---|
| 129 | |
---|
| 130 | self.basic_auth = 'mgr:mgrpw' |
---|
| 131 | self.loginAsPortalOwner() |
---|
| 132 | |
---|
| 133 | '''Preparation for functional testing''' |
---|
| 134 | my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
| 135 | my_doc = self.portal['my_doc'] |
---|
| 136 | |
---|
| 137 | my_doc.qseo_properties_edit(title='hello world', description='it is description', |
---|
| 138 | keywords='my1|key2', html_comment='no comments', |
---|
| 139 | robots='ALL', distribution='Global', title_override=1, |
---|
| 140 | description_override=1, keywords_override=1, |
---|
| 141 | html_comment_override=1, robots_override=1, |
---|
| 142 | distribution_override=1) |
---|
| 143 | |
---|
| 144 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
| 145 | |
---|
| 146 | def testTitle(self): |
---|
| 147 | m = re.match('.*<title>\\s*hello world\\s*</title>', self.html, re.S|re.M) |
---|
| 148 | self.assert_(m, 'Title not set in') |
---|
| 149 | |
---|
| 150 | def testDescription(self): |
---|
| 151 | m = re.match('.*<meta content="it is description" name="description" />', self.html, re.S|re.M) |
---|
| 152 | self.assert_(m, 'Description not set in') |
---|
| 153 | |
---|
| 154 | def testKeywords(self): |
---|
| 155 | m = re.match('.*<meta content="my1|key2" name="keywords" />', self.html, re.S|re.M) |
---|
| 156 | self.assert_(m, 'Keywords not set in') |
---|
| 157 | |
---|
| 158 | def testRobots(self): |
---|
| 159 | m = re.match('.*<meta content="ALL" name="robots" />', self.html, re.S|re.M) |
---|
| 160 | self.assert_(m, 'Robots not set in') |
---|
| 161 | |
---|
| 162 | def testDistribution(self): |
---|
| 163 | m = re.match('.*<meta content="Global" name="distribution" />', self.html, re.S|re.M) |
---|
| 164 | self.assert_(m, 'Distribution not set in') |
---|
| 165 | |
---|
| 166 | def testHTMLComments(self): |
---|
| 167 | m = re.match('.*<!--\\s*no comments\\s*-->', self.html, re.S|re.M) |
---|
| 168 | self.assert_(m, 'Comments not set in') |
---|
| 169 | |
---|
| 170 | class TestExposeDCMetaTags(PloneTestCase.FunctionalTestCase): |
---|
| 171 | |
---|
| 172 | def afterSetUp(self): |
---|
| 173 | self.qi = self.portal.portal_quickinstaller |
---|
| 174 | self.sp = self.portal.portal_properties.site_properties |
---|
| 175 | self.qi.installProduct(PRODUCT) |
---|
| 176 | self.portal.changeSkin('Plone Default') |
---|
| 177 | |
---|
| 178 | self.basic_auth = 'portal_manager:secret' |
---|
| 179 | uf = self.app.acl_users |
---|
| 180 | uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], []) |
---|
| 181 | user = uf.getUserById('portal_manager') |
---|
| 182 | if not hasattr(user, 'aq_base'): |
---|
| 183 | user = user.__of__(uf) |
---|
| 184 | newSecurityManager(None, user) |
---|
| 185 | |
---|
| 186 | '''Preparation for functional testing''' |
---|
| 187 | self.my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
| 188 | self.my_doc = self.portal['my_doc'] |
---|
| 189 | |
---|
| 190 | def test_exposeDCMetaTags_in_configletOn(self): |
---|
| 191 | path = self.portal.id+'/prefs_qseo_setup?exposeDCMetaTags=on' |
---|
| 192 | self.publish(path, self.basic_auth) |
---|
| 193 | self.assert_(self.sp.exposeDCMetaTags) |
---|
| 194 | |
---|
| 195 | def test_exposeDCMetaTags_in_configletOff(self): |
---|
| 196 | self.publish(self.portal.id+'/prefs_qseo_setup', self.basic_auth) |
---|
| 197 | self.assert_(not self.sp.exposeDCMetaTags) |
---|
| 198 | |
---|
| 199 | def test_exposeDCMetaTagsPropertyOff(self): |
---|
| 200 | self.sp.manage_changeProperties(exposeDCMetaTags = False) |
---|
| 201 | |
---|
| 202 | self.my_doc.qseo_properties_edit() |
---|
| 203 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
| 204 | |
---|
| 205 | 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) |
---|
| 206 | self.assert_(not m, 'DC meta tags avaliable when exposeDCMetaTags=False') |
---|
| 207 | |
---|
| 208 | def test_exposeDCMetaTagsPropertyOn(self): |
---|
| 209 | self.sp.manage_changeProperties(exposeDCMetaTags = True) |
---|
| 210 | |
---|
| 211 | self.my_doc.qseo_properties_edit() |
---|
| 212 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
| 213 | |
---|
| 214 | 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) |
---|
| 215 | |
---|
| 216 | self.assert_(m, 'DC meta tags not avaliable when createManager=True') |
---|
| 217 | |
---|
| 218 | TESTS = [TestInstallation, TestResponse, TestExposeDCMetaTags] |
---|
| 219 | |
---|
| 220 | def test_suite(): |
---|
| 221 | from unittest import TestSuite, makeSuite |
---|
| 222 | suite = TestSuite() |
---|
| 223 | suite.addTest(makeSuite(TestInstallation)) |
---|
| 224 | suite.addTest(makeSuite(TestResponse)) |
---|
| 225 | suite.addTest(makeSuite(TestExposeDCMetaTags)) |
---|
| 226 | return suite |
---|
| 227 | |
---|
| 228 | if __name__ == '__main__': |
---|
| 229 | framework() |
---|
| 230 | |
---|