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

Last change on this file since 2201 was 2201, checked in by crchemist, 14 years ago

fix test

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            "Not added 'SEOProperties' action")
142
143class TestReinstallation(TestCase):
144
145    def afterSetUp(self):
146        self.qi = self.portal.portal_quickinstaller
147        self.types_tool = getToolByName(self.portal, 'portal_types')
148        self.setup_tool = getToolByName(self.portal, 'portal_setup')
149        self.pprops_tool = getToolByName(self.portal, 'portal_properties')
150        self.seoprops_tool = getToolByName(self.pprops_tool, 'seo_properties', None)
151        # Set earlier version profile (2.0.0) for using upgrade steps
152        self.setup_tool.setLastVersionForProfile('%s:default' % PROJECT_NAME, '2.0.0')
153
154    def testChangeDomain(self):
155        # Test changed of content type's domain from 'quintagroup.seoptimizer' to 'plone'
156        for type in SEO_CONTENT:
157            self.types_tool.getTypeInfo(type).i18n_domain = 'quintagroup.seoptimizer'
158        self.qi.reinstallProducts([PROJECT_NAME])
159        for type in SEO_CONTENT:
160            self.assertEqual(self.types_tool.getTypeInfo(type).i18n_domain, 'plone',
161                "Not changed of %s content type's domain to 'plone'" % type)
162
163    def testCutItemsMetatagsOrderList(self):
164        # Test changed format metatags order list from "metaname accessor" to "metaname"
165        value, expect_mto = ['name1 accessor1', 'name2 accessor2'], ['name1','name2']
166        self.seoprops_tool.manage_changeProperties(metatags_order=value)
167        self.qi.reinstallProducts([PROJECT_NAME])
168        mto = list(self.seoprops_tool.getProperty('metatags_order'))
169        mto.sort()
170        self.assertEqual(mto, expect_mto,
171                    "Not changed format metatags order list from \"metaname accessor\" to"\
172                    " \"metaname\". %s != %s" %(mto, expect_mto))
173
174    def testAddMetatagsOrderList(self):
175        # Test added metatags order list if it was not there before
176        self.seoprops_tool.manage_delProperties(['metatags_order'])
177        self.qi.reinstallProducts([PROJECT_NAME])
178        mto = list(self.seoprops_tool.getProperty('metatags_order'))
179        mto.sort()
180        self.assertEqual(mto, DEFAULT_METATAGS_ORDER,
181                    "Not added metatags order list with default values."\
182                    "%s != %s" %(mto, DEFAULT_METATAGS_ORDER))
183
184    def testMigrationActions(self):
185        # Test migrated actions from portal_types action to seoproperties tool
186        self.seoprops_tool.content_types_with_seoproperties = ()
187
188        # Add seoaction to content type for testing
189        for type in CONTENTTYPES_WITH_SEOACTION:
190            self.types_tool.getTypeInfo(type).addAction(id='seo_properties',
191                                                   name='SEO Properties',
192                                                   action=None,
193                                                   condition=None,
194                                                   permission=(u'Modify portal content',),
195                                                   category='object',
196                                                  )
197            # Check presence seoaction in content type
198            seoaction = [act.id for act in self.types_tool.getTypeInfo(type).listActions()
199                                          if act.id == 'seo_properties']
200            self.assertEqual(bool(seoaction), True,
201                    "Not added seoaction to content type %s for testing" % type)
202
203        self.qi.reinstallProducts([PROJECT_NAME])
204
205        # Check presence seoaction in content type
206        for type in CONTENTTYPES_WITH_SEOACTION:
207            seoaction = [act.id for act in self.types_tool.getTypeInfo(type).listActions()
208                                          if act.id == 'seo_properties']
209            self.assertEqual(bool(seoaction), False,
210                "Not removed seoaction in content type %s" % type)
211
212        # Check added content type names in seo properties tool if content types have seoaction
213        ctws = list(self.seoprops_tool.content_types_with_seoproperties)
214        ctws.sort()
215        self.assertEqual(ctws, CONTENTTYPES_WITH_SEOACTION,
216            "Not added content type names in seo properties tool if content types have seoaction."\
217            " %s != %s" %(ctws, CONTENTTYPES_WITH_SEOACTION))
218
219    def testRemoveSkin(self):
220        # Test remove layers
221        layer = 'quintagroup.seoptimizer'
222        skinstool = getToolByName(self.portal, 'portal_skins')
223        for skin in skinstool.getSkinSelections():
224            paths  = ','.join((skinstool.getSkinPath(skin), layer))
225            skinstool.addSkinSelection(skin, paths)
226        self.qi.reinstallProducts([PROJECT_NAME])
227        for skin in skinstool.getSkinSelections():
228            path = skinstool.getSkinPath(skin)
229            path = map(string.strip, string.split(path, ','))
230            self.assertEqual(layer in path, False,
231                '%s layer found in %s after uninstallation' %(layer, skin))
232
233    def testMigrateCanonical(self):
234        """ Test Migrate qSEO_canonical property into PROPERTY_LINK
235            for all portal objects, which use SEO
236        """
237        doc = self.portal.get('front-page')
238        doc.manage_addProperty('qSEO_canonical', 'val', 'string')
239        value = doc.getProperty('qSEO_canonical')
240        assert doc.getProperty('qSEO_canonical') == 'val' 
241
242        self.qi.reinstallProducts([PROJECT_NAME])
243        value = doc.getProperty(PROPERTY_LINK)
244        has_prop = bool(doc.hasProperty('qSEO_canonical'))
245        self.assertEqual(has_prop, False, "Property 'qSEO_canonical' is not deleted.")
246        self.assertEqual(value == 'val', True,
247                "Property not migrated from 'qSEO_canonical' to '%s'." % PROPERTY_LINK)
248
249def test_suite():
250    from unittest import TestSuite, makeSuite
251    suite = TestSuite()
252    suite.addTest(makeSuite(TestBeforeInstallation))
253    suite.addTest(makeSuite(TestInstallation))
254    suite.addTest(makeSuite(TestUninstallation))
255    suite.addTest(makeSuite(TestReinstallation))
256    return suite
Note: See TracBrowser for help on using the repository browser.