[1493] | 1 | # |
---|
| 2 | # Test product's installation |
---|
| 3 | # |
---|
| 4 | import string |
---|
[1836] | 5 | from zope.interface import alsoProvides |
---|
| 6 | from zope.component import queryMultiAdapter |
---|
| 7 | from zope.publisher.browser import TestRequest |
---|
| 8 | from zope.viewlet.interfaces import IViewletManager |
---|
[1897] | 9 | |
---|
[1836] | 10 | from quintagroup.seoptimizer.browser.interfaces import IPloneSEOLayer |
---|
| 11 | |
---|
[1877] | 12 | from base import * |
---|
[1493] | 13 | |
---|
[1877] | 14 | PROPS = {'stop_words': STOP_WORDS, |
---|
| 15 | 'fields': ['seo_title', 'seo_description', 'seo_keywords']} |
---|
[1493] | 16 | |
---|
[1877] | 17 | DEFAULT_METATAGS_ORDER = [ |
---|
| 18 | 'DC.contributors', 'DC.creator', 'DC.date.created', |
---|
| 19 | 'DC.date.modified','DC.description', 'DC.distribution', |
---|
| 20 | 'DC.format', 'DC.language', 'DC.publisher', 'DC.rights', |
---|
| 21 | 'DC.subject', 'DC.type', 'description', 'distribution', |
---|
| 22 | 'keywords', 'robots'] |
---|
| 23 | DEFAULT_METATAGS_ORDER.sort() |
---|
| 24 | |
---|
| 25 | SEO_CONTENT = ['File', 'Document', 'News Item'] |
---|
| 26 | CONTENTTYPES_WITH_SEOACTION = ['File', 'Document', 'News Item', 'Folder', 'Event'] |
---|
| 27 | CONTENTTYPES_WITH_SEOACTION.sort() |
---|
| 28 | |
---|
| 29 | |
---|
[1897] | 30 | class TestBeforeInstallation(FunctionalTestCaseNotInstalled): |
---|
[1493] | 31 | |
---|
| 32 | def afterSetUp(self): |
---|
[1897] | 33 | #self.qi = self.portal.portal_quickinstaller |
---|
| 34 | #self.qi.uninstallProducts([PROJECT_NAME]) |
---|
[1493] | 35 | self.basic_auth = 'mgr:mgrpw' |
---|
| 36 | self.portal_path = '/%s' % self.portal.absolute_url(1) |
---|
| 37 | |
---|
| 38 | def testAccessPortalRootAnonymous(self): |
---|
| 39 | response = self.publish(self.portal_path) |
---|
| 40 | self.assertEqual(response.getStatus(), 200) |
---|
| 41 | |
---|
| 42 | def testAccessPortalRootAuthenticated(self): |
---|
| 43 | response = self.publish(self.portal_path, self.basic_auth) |
---|
| 44 | self.assertEqual(response.getStatus(), 200) |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | class TestInstallation(TestCase): |
---|
| 48 | |
---|
| 49 | def afterSetUp(self): |
---|
| 50 | self.properties = getToolByName(self.portal, 'portal_properties') |
---|
| 51 | |
---|
| 52 | def testAddingPropertySheet(self): |
---|
| 53 | """ Test adding property sheet to portal_properties tool """ |
---|
| 54 | self.failUnless(hasattr(self.properties.aq_base, PROPERTY_SHEET)) |
---|
| 55 | |
---|
| 56 | def testAddingPropertyFields(self): |
---|
| 57 | """ Test adding property field to portal_properties.maps_properties sheet """ |
---|
| 58 | map_sheet = self.properties[PROPERTY_SHEET] |
---|
| 59 | for key, value in PROPS.items(): |
---|
| 60 | self.failUnless(map_sheet.hasProperty(key) and list(map_sheet.getProperty(key)) == value) |
---|
| 61 | |
---|
| 62 | def test_configlet_install(self): |
---|
| 63 | configTool = getToolByName(self.portal, 'portal_controlpanel', None) |
---|
| 64 | self.assert_(PROJECT_NAME in [a.getId() for a in configTool.listActions()], 'Configlet not found') |
---|
| 65 | |
---|
| 66 | def test_skins_install(self): |
---|
| 67 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 68 | |
---|
| 69 | for skin in skinstool.getSkinSelections(): |
---|
| 70 | path = skinstool.getSkinPath(skin) |
---|
| 71 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 72 | self.assert_(PROJECT_NAME in path, 'qSEOptimizer layer not found in %s' %skin) |
---|
| 73 | |
---|
[1836] | 74 | def test_viewlets_install(self): |
---|
| 75 | VIEWLETS = ['plone.htmlhead.title', |
---|
| 76 | 'plone.resourceregistries', |
---|
| 77 | 'quintagroup.seoptimizer.seotags', |
---|
| 78 | 'quintagroup.seoptimizer.customscript'] |
---|
| 79 | request = self.app.REQUEST |
---|
| 80 | # mark request with our browser layer |
---|
| 81 | alsoProvides(request, IPloneSEOLayer) |
---|
| 82 | view = queryMultiAdapter((self.portal, request), name="plone") |
---|
| 83 | manager = queryMultiAdapter( (self.portal['front-page'], request, view), |
---|
| 84 | IViewletManager, name='plone.htmlhead') |
---|
| 85 | for p in VIEWLETS: |
---|
| 86 | self.assert_(manager.get(p) is not None, "Not registered '%s' viewlet" % p) |
---|
| 87 | |
---|
| 88 | def test_browser_layer(self): |
---|
[1897] | 89 | from plone.browserlayer import utils |
---|
[1836] | 90 | self.assert_(IPloneSEOLayer in utils.registered_layers(), |
---|
| 91 | "Not registered 'IPloneSEOLayer' browser layer") |
---|
| 92 | |
---|
| 93 | def test_jsregestry_install(self): |
---|
| 94 | jstool=getToolByName(self.portal, 'portal_javascripts') |
---|
| 95 | self.assert_(jstool.getResource("++resource++seo_custommetatags.js") is not None, |
---|
| 96 | "Not registered '++resource++seo_custommetatags.js' resource") |
---|
[1493] | 97 | |
---|
[1836] | 98 | def test_action_install(self): |
---|
| 99 | atool=getToolByName(self.portal, 'portal_actions') |
---|
| 100 | action_ids = [a.id for a in atool.listActions()] |
---|
| 101 | self.assert_("SEOProperties" in action_ids, |
---|
| 102 | "Not added 'SEOProperties' action") |
---|
[1835] | 103 | |
---|
| 104 | class TestUninstallation(TestCase): |
---|
| 105 | |
---|
| 106 | def afterSetUp(self): |
---|
| 107 | self.qi = self.portal.portal_quickinstaller |
---|
| 108 | self.qi.uninstallProducts([PROJECT_NAME]) |
---|
| 109 | |
---|
[1837] | 110 | def test_propertysheet_uninstall(self): |
---|
| 111 | properties = getToolByName(self.portal, 'portal_properties') |
---|
| 112 | self.assertEqual(hasattr(properties.aq_base, PROPERTY_SHEET), False, |
---|
| 113 | "'%s' property sheet not uninstalled" % PROPERTY_SHEET) |
---|
[1493] | 114 | |
---|
[1837] | 115 | def test_configlet_uninstall(self): |
---|
| 116 | self.assertNotEqual(self.qi.isProductInstalled(PROJECT_NAME), True, |
---|
| 117 | 'qSEOptimizer is already installed') |
---|
[1493] | 118 | |
---|
[1837] | 119 | configTool = getToolByName(self.portal, 'portal_controlpanel', None) |
---|
| 120 | self.assertEqual(PROJECT_NAME in [a.getId() for a in configTool.listActions()], False, |
---|
| 121 | 'Configlet found after uninstallation') |
---|
| 122 | |
---|
| 123 | def test_skins_uninstall(self): |
---|
| 124 | self.assertNotEqual(self.qi.isProductInstalled(PROJECT_NAME), True, |
---|
| 125 | 'qSEOptimizer is already installed') |
---|
[1493] | 126 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 127 | |
---|
| 128 | for skin in skinstool.getSkinSelections(): |
---|
| 129 | path = skinstool.getSkinPath(skin) |
---|
| 130 | path = map( string.strip, string.split( path,',' ) ) |
---|
[1837] | 131 | self.assertEqual(PROJECT_NAME in path, False, |
---|
| 132 | 'qSEOptimizer layer found in %s after uninstallation' %skin) |
---|
[1493] | 133 | |
---|
[1837] | 134 | def test_viewlets_uninstall(self): |
---|
| 135 | VIEWLETS = ['quintagroup.seoptimizer.seotags', |
---|
| 136 | 'quintagroup.seoptimizer.customscript'] |
---|
| 137 | request = self.app.REQUEST |
---|
| 138 | view = queryMultiAdapter((self.portal, request), name="plone") |
---|
| 139 | manager = queryMultiAdapter( (self.portal['front-page'], request, view), |
---|
| 140 | IViewletManager, name='plone.htmlhead') |
---|
| 141 | for p in VIEWLETS: |
---|
| 142 | self.assertEqual(manager.get(p) is None, True, |
---|
| 143 | "'%s' viewlet present after uninstallation" % p) |
---|
[1493] | 144 | |
---|
[1837] | 145 | def test_browserlayer_uninstall(self): |
---|
[1897] | 146 | from plone.browserlayer import utils |
---|
[1837] | 147 | self.assertEqual(IPloneSEOLayer in utils.registered_layers(), False, |
---|
[1897] | 148 | "Still registered 'IPloneSEOLayer' browser layer") |
---|
[1493] | 149 | |
---|
[1837] | 150 | def test_jsregestry_uninstall(self): |
---|
| 151 | jstool=getToolByName(self.portal, 'portal_javascripts') |
---|
| 152 | self.assertEqual(jstool.getResource("++resource++seo_custommetatags.js") is not None, |
---|
| 153 | False, "Not registered '++resource++seo_custommetatags.js' resource") |
---|
[1835] | 154 | |
---|
[1837] | 155 | def test_action_uninstall(self): |
---|
| 156 | atool=getToolByName(self.portal, 'portal_actions') |
---|
| 157 | action_ids = [a.id for a in atool.listActions()] |
---|
| 158 | self.assertEqual("SEOProperties" in action_ids, False, |
---|
| 159 | "Not added 'SEOProperties' action") |
---|
[1835] | 160 | |
---|
[1849] | 161 | class TestReinstallation(TestCase): |
---|
[1836] | 162 | |
---|
[1849] | 163 | def afterSetUp(self): |
---|
| 164 | self.qi = self.portal.portal_quickinstaller |
---|
| 165 | self.types_tool = getToolByName(self.portal, 'portal_types') |
---|
| 166 | self.setup_tool = getToolByName(self.portal, 'portal_setup') |
---|
| 167 | self.pprops_tool = getToolByName(self.portal, 'portal_properties') |
---|
| 168 | self.seoprops_tool = getToolByName(self.pprops_tool, 'seo_properties', None) |
---|
| 169 | # Set earlier version profile (2.0.0) for using upgrade steps |
---|
| 170 | self.setup_tool.setLastVersionForProfile('%s:default' % PROJECT_NAME, '2.0.0') |
---|
| 171 | |
---|
| 172 | def testChangeDomain(self): |
---|
| 173 | # Test changed of content type's domain from 'quintagroup.seoptimizer' to 'plone' |
---|
| 174 | for type in SEO_CONTENT: |
---|
| 175 | self.types_tool.getTypeInfo(type).i18n_domain = 'quintagroup.seoptimizer' |
---|
| 176 | self.qi.reinstallProducts([PROJECT_NAME]) |
---|
| 177 | for type in SEO_CONTENT: |
---|
| 178 | self.assertEqual(self.types_tool.getTypeInfo(type).i18n_domain, 'plone', |
---|
| 179 | "Not changed of %s content type's domain to 'plone'" % type) |
---|
| 180 | |
---|
| 181 | def testCutItemsMetatagsOrderList(self): |
---|
| 182 | # Test changed format metatags order list from "metaname accessor" to "metaname" |
---|
| 183 | value, expect_mto = ['name1 accessor1', 'name2 accessor2'], ['name1','name2'] |
---|
| 184 | self.seoprops_tool.manage_changeProperties(metatags_order=value) |
---|
| 185 | self.qi.reinstallProducts([PROJECT_NAME]) |
---|
| 186 | mto = list(self.seoprops_tool.getProperty('metatags_order')) |
---|
| 187 | mto.sort() |
---|
| 188 | self.assertEqual(mto, expect_mto, |
---|
| 189 | "Not changed format metatags order list from \"metaname accessor\" to"\ |
---|
| 190 | " \"metaname\". %s != %s" %(mto, expect_mto)) |
---|
| 191 | |
---|
| 192 | def testAddMetatagsOrderList(self): |
---|
| 193 | # Test added metatags order list if it was not there before |
---|
| 194 | self.seoprops_tool.manage_delProperties(['metatags_order']) |
---|
| 195 | self.qi.reinstallProducts([PROJECT_NAME]) |
---|
| 196 | mto = list(self.seoprops_tool.getProperty('metatags_order')) |
---|
| 197 | mto.sort() |
---|
| 198 | self.assertEqual(mto, DEFAULT_METATAGS_ORDER, |
---|
| 199 | "Not added metatags order list with default values."\ |
---|
| 200 | "%s != %s" %(mto, DEFAULT_METATAGS_ORDER)) |
---|
| 201 | |
---|
| 202 | def testMigrationActions(self): |
---|
| 203 | # Test migrated actions from portal_types action to seoproperties tool |
---|
| 204 | self.seoprops_tool.content_types_with_seoproperties = () |
---|
| 205 | |
---|
| 206 | # Add seoaction to content type for testing |
---|
| 207 | for type in CONTENTTYPES_WITH_SEOACTION: |
---|
| 208 | self.types_tool.getTypeInfo(type).addAction(id='seo_properties', |
---|
| 209 | name='SEO Properties', |
---|
| 210 | action=None, |
---|
| 211 | condition=None, |
---|
| 212 | permission=(u'Modify portal content',), |
---|
| 213 | category='object', |
---|
| 214 | visible=True, |
---|
| 215 | icon_expr=None, |
---|
| 216 | link_target=None, |
---|
| 217 | ) |
---|
| 218 | # Check presence seoaction in content type |
---|
| 219 | seoaction = [act.id for act in self.types_tool.getTypeInfo(type).listActions() |
---|
| 220 | if act.id == 'seo_properties'] |
---|
| 221 | self.assertEqual(bool(seoaction), True, |
---|
| 222 | "Not added seoaction to content type %s for testing" % type) |
---|
| 223 | |
---|
| 224 | self.qi.reinstallProducts([PROJECT_NAME]) |
---|
| 225 | |
---|
| 226 | # Check presence seoaction in content type |
---|
| 227 | for type in CONTENTTYPES_WITH_SEOACTION: |
---|
| 228 | seoaction = [act.id for act in self.types_tool.getTypeInfo(type).listActions() |
---|
| 229 | if act.id == 'seo_properties'] |
---|
| 230 | self.assertEqual(bool(seoaction), False, |
---|
| 231 | "Not removed seoaction in content type %s" % type) |
---|
| 232 | |
---|
| 233 | # Check added content type names in seo properties tool if content types have seoaction |
---|
| 234 | ctws = list(self.seoprops_tool.content_types_with_seoproperties) |
---|
| 235 | ctws.sort() |
---|
| 236 | self.assertEqual(ctws, CONTENTTYPES_WITH_SEOACTION, |
---|
| 237 | "Not added content type names in seo properties tool if content types have seoaction."\ |
---|
| 238 | " %s != %s" %(ctws, CONTENTTYPES_WITH_SEOACTION)) |
---|
| 239 | |
---|
| 240 | |
---|
[1493] | 241 | def test_suite(): |
---|
| 242 | from unittest import TestSuite, makeSuite |
---|
| 243 | suite = TestSuite() |
---|
[1835] | 244 | suite.addTest(makeSuite(TestBeforeInstallation)) |
---|
[1493] | 245 | suite.addTest(makeSuite(TestInstallation)) |
---|
[1835] | 246 | suite.addTest(makeSuite(TestUninstallation)) |
---|
[1849] | 247 | suite.addTest(makeSuite(TestReinstallation)) |
---|
[1493] | 248 | return suite |
---|