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

Last change on this file since 3223 was 3140, checked in by zidane, 13 years ago

fixes pylint

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