source: products/quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testInstallation.py @ 1849

Last change on this file since 1849 was 1849, checked in by liebster, 14 years ago

Add test migration

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