# # Test installation script # import os, sys, string if __name__ == '__main__': execfile(os.path.join(sys.path[0], 'framework.py')) from Products.PloneTestCase import PloneTestCase from Products.CMFCore.utils import getToolByName from Products.CMFQuickInstallerTool.InstalledProduct import InstalledProduct from Products.CMFCore.CMFCorePermissions import ManagePortal from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager import re from Products.qSEOptimizer.config import * props = {'stop_words':STOP_WORDS, 'fields':FIELDS} configlets = ({'id':'qSEOptimizer', 'name':'Search Engine Optimizer', 'action':'string:${portal_url}/prefs_qseo_setup_form', 'condition':'', 'category':'Products', 'visible':1, 'appId':'qSEOptimizer', 'permission':ManagePortal},) PRODUCT = 'qSEOptimizer' qSEO_CONTENT = ['File','Document','News Item','BlogEntry'] qSEO_FOLDER = [] qSEO_TYPES = qSEO_CONTENT + qSEO_FOLDER PloneTestCase.installProduct(PRODUCT) PloneTestCase.setupPloneSite() class TestInstallation(PloneTestCase.PloneTestCase): def afterSetUp(self): self.properties = getToolByName(self.portal, 'portal_properties') self.qi = self.portal.portal_quickinstaller self.qi.installProduct(PRODUCT) def testAddingPropertySheet(self): """ Test adding property sheet to portal_properties tool """ self.failUnless(hasattr(self.properties.aq_base, PROPERTY_SHEET)) def testAddingPropertyFields(self): """ Test adding property field to portal_properties.maps_properties sheet """ map_sheet = self.properties[PROPERTY_SHEET] for key, value in props.items(): self.failUnless(map_sheet.hasProperty(key) and list(map_sheet.getProperty(key)) == value) def test_configlet_install(self): configTool = getToolByName(self.portal, 'portal_controlpanel', None) self.assert_(PRODUCT in [a.getId() for a in configTool.listActions()], 'Configlet not found') def test_actions_install(self): portal_types = getToolByName(self.portal, 'portal_types') for ptype in portal_types.objectValues(): action = ptype.getActionById('seo_properties', default=None ) if ptype.getId() in qSEO_TYPES: self.assert_(action, 'Action for %s not found' % ptype.getId()) else: self.assert_(not action, 'Action found for %s' % ptype.getId()) def test_skins_install(self): skinstool=getToolByName(self.portal, 'portal_skins') for skin in skinstool.getSkinSelections(): path = skinstool.getSkinPath(skin) path = map( string.strip, string.split( path,',' ) ) self.assert_(PRODUCT in path, 'qSEOptimizer layer not found in %s' %skin) def test_versionedskin_install(self): skinstool=getToolByName(self.portal, 'portal_skins') mtool = getToolByName(self.portal, 'portal_migration') plone_version = mtool.getFileSystemVersion() for skin in skinstool.getSkinSelections(): path = skinstool.getSkinPath(skin) path = map( string.strip, string.split( path,',' ) ) self.assert_(PRODUCT+'/%s' % plone_version in path, 'qSEOptimizer versioned layer not found in %s' %skin) def test_actions_uninstall(self): self.qi.uninstallProducts([PRODUCT]) self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') portal_types = getToolByName(self.portal, 'portal_types') for ptype in portal_types.objectValues(): action = ptype.getActionById('seo_properties', default=None ) self.assert_(not action, 'Action for %s found after uninstallation' % ptype.getId()) def test_skins_uninstall(self): self.qi.uninstallProducts([PRODUCT]) self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') skinstool=getToolByName(self.portal, 'portal_skins') for skin in skinstool.getSkinSelections(): path = skinstool.getSkinPath(skin) path = map( string.strip, string.split( path,',' ) ) self.assert_(not PRODUCT in path, 'qSEOptimizer layer found in %s after uninstallation' %skin) def test_versionedskin_uninstall(self): self.qi.uninstallProducts([PRODUCT]) self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') skinstool=getToolByName(self.portal, 'portal_skins') mtool = getToolByName(self.portal, 'portal_migration') plone_version = mtool.getFileSystemVersion() for skin in skinstool.getSkinSelections(): path = skinstool.getSkinPath(skin) path = map( string.strip, string.split( path,',' ) ) self.assert_(not PRODUCT+'/%s' % plone_version in path, 'qSEOptimizer versioned layer found in %s after uninstallation' %skin) def test_configlet_uninstall(self): self.qi.uninstallProducts([PRODUCT]) self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') configTool = getToolByName(self.portal, 'portal_controlpanel', None) self.assert_(not PRODUCT in [a.getId() for a in configTool.listActions()], 'Configlet found after uninstallation') class TestResponse(PloneTestCase.FunctionalTestCase): def afterSetUp(self): self.qi = self.portal.portal_quickinstaller self.qi.installProduct(PRODUCT) self.portal.changeSkin('Plone Default') self.basic_auth = 'mgr:mgrpw' self.loginAsPortalOwner() '''Preparation for functional testing''' my_doc = self.portal.invokeFactory('Document', id='my_doc') my_doc = self.portal['my_doc'] my_doc.qseo_properties_edit(title='hello world', description='it is description', keywords='my1|key2', html_comment='no comments', robots='ALL', distribution='Global', title_override=1, description_override=1, keywords_override=1, html_comment_override=1, robots_override=1, distribution_override=1) self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) def testTitle(self): m = re.match('.*