source: products/quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testInstallation.py @ 2247

Last change on this file since 2247 was 2244, checked in by mylan, 14 years ago

Clarify exception comment for test uninstallation

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