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

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

Remove config module from tests, move all constants into testInstallation and testResponce modules

File size: 11.3 KB
Line 
1#
2# Test product's installation
3#
4import string
5from zope.interface import alsoProvides
6from zope.component import queryMultiAdapter
7from zope.publisher.browser import TestRequest
8from zope.viewlet.interfaces import IViewletManager
9from plone.browserlayer import utils
10from quintagroup.seoptimizer.browser.interfaces import IPloneSEOLayer
11
12from base import *
13
14PROPS = {'stop_words': STOP_WORDS,
15         'fields': ['seo_title', 'seo_description', 'seo_keywords']}
16
17DEFAULT_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']
23DEFAULT_METATAGS_ORDER.sort()
24
25SEO_CONTENT = ['File', 'Document', 'News Item']
26CONTENTTYPES_WITH_SEOACTION = ['File', 'Document', 'News Item', 'Folder', 'Event']
27CONTENTTYPES_WITH_SEOACTION.sort()
28
29
30class TestBeforeInstallation(FunctionalTestCase):
31
32    def afterSetUp(self):
33        self.qi = self.portal.portal_quickinstaller
34        self.qi.uninstallProducts([PROJECT_NAME])
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
47class 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
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):
89        self.assert_(IPloneSEOLayer in utils.registered_layers(),
90                     "Not registered 'IPloneSEOLayer' browser layer")
91   
92    def test_jsregestry_install(self):
93        jstool=getToolByName(self.portal, 'portal_javascripts')
94        self.assert_(jstool.getResource("++resource++seo_custommetatags.js") is not None,
95                     "Not registered '++resource++seo_custommetatags.js' resource")
96
97    def test_action_install(self):
98        atool=getToolByName(self.portal, 'portal_actions')
99        action_ids = [a.id for a in atool.listActions()]
100        self.assert_("SEOProperties" in action_ids,
101                     "Not added 'SEOProperties' action")
102
103class TestUninstallation(TestCase):
104
105    def afterSetUp(self):
106        self.qi = self.portal.portal_quickinstaller
107        self.qi.uninstallProducts([PROJECT_NAME])
108
109    def test_propertysheet_uninstall(self):
110        properties = getToolByName(self.portal, 'portal_properties')
111        self.assertEqual(hasattr(properties.aq_base, PROPERTY_SHEET), False,
112            "'%s' property sheet not uninstalled" % PROPERTY_SHEET)
113
114    def test_configlet_uninstall(self):
115        self.assertNotEqual(self.qi.isProductInstalled(PROJECT_NAME), True,
116            'qSEOptimizer is already installed')
117
118        configTool = getToolByName(self.portal, 'portal_controlpanel', None)
119        self.assertEqual(PROJECT_NAME in [a.getId() for a in configTool.listActions()], False,
120            'Configlet found after uninstallation')
121
122    def test_skins_uninstall(self):
123        self.assertNotEqual(self.qi.isProductInstalled(PROJECT_NAME), True,
124            'qSEOptimizer is already installed')
125        skinstool=getToolByName(self.portal, 'portal_skins')
126
127        for skin in skinstool.getSkinSelections():
128            path = skinstool.getSkinPath(skin)
129            path = map( string.strip, string.split( path,',' ) )
130            self.assertEqual(PROJECT_NAME in path, False,
131                'qSEOptimizer layer found in %s after uninstallation' %skin)
132
133    def test_viewlets_uninstall(self):
134        VIEWLETS = ['quintagroup.seoptimizer.seotags',
135                    'quintagroup.seoptimizer.customscript']
136        request = self.app.REQUEST
137        view = queryMultiAdapter((self.portal, request), name="plone")
138        manager = queryMultiAdapter( (self.portal['front-page'], request, view),
139                                     IViewletManager, name='plone.htmlhead')
140        for p in VIEWLETS:
141            self.assertEqual(manager.get(p) is None, True,
142                "'%s' viewlet present after uninstallation" % p)
143
144    def test_browserlayer_uninstall(self):
145        self.assertEqual(IPloneSEOLayer in utils.registered_layers(), False,
146            "Not registered 'IPloneSEOLayer' browser layer")
147
148    def test_jsregestry_uninstall(self):
149        jstool=getToolByName(self.portal, 'portal_javascripts')
150        self.assertEqual(jstool.getResource("++resource++seo_custommetatags.js") is not None,
151            False, "Not registered '++resource++seo_custommetatags.js' resource")
152
153    def test_action_uninstall(self):
154        atool=getToolByName(self.portal, 'portal_actions')
155        action_ids = [a.id for a in atool.listActions()]
156        self.assertEqual("SEOProperties" in action_ids, False,
157            "Not added 'SEOProperties' action")
158
159class TestReinstallation(TestCase):
160
161    def afterSetUp(self):
162        self.qi = self.portal.portal_quickinstaller
163        self.types_tool = getToolByName(self.portal, 'portal_types')
164        self.setup_tool = getToolByName(self.portal, 'portal_setup')
165        self.pprops_tool = getToolByName(self.portal, 'portal_properties')
166        self.seoprops_tool = getToolByName(self.pprops_tool, 'seo_properties', None)
167        # Set earlier version profile (2.0.0) for using upgrade steps
168        self.setup_tool.setLastVersionForProfile('%s:default' % PROJECT_NAME, '2.0.0')
169
170    def testChangeDomain(self):
171        # Test changed of content type's domain from 'quintagroup.seoptimizer' to 'plone'
172        for type in SEO_CONTENT:
173            self.types_tool.getTypeInfo(type).i18n_domain = 'quintagroup.seoptimizer'
174        self.qi.reinstallProducts([PROJECT_NAME])
175        for type in SEO_CONTENT:
176            self.assertEqual(self.types_tool.getTypeInfo(type).i18n_domain, 'plone',
177                "Not changed of %s content type's domain to 'plone'" % type)
178
179    def testCutItemsMetatagsOrderList(self):
180        # Test changed format metatags order list from "metaname accessor" to "metaname"
181        value, expect_mto = ['name1 accessor1', 'name2 accessor2'], ['name1','name2']
182        self.seoprops_tool.manage_changeProperties(metatags_order=value)
183        self.qi.reinstallProducts([PROJECT_NAME])
184        mto = list(self.seoprops_tool.getProperty('metatags_order'))
185        mto.sort()
186        self.assertEqual(mto, expect_mto,
187                    "Not changed format metatags order list from \"metaname accessor\" to"\
188                    " \"metaname\". %s != %s" %(mto, expect_mto))
189
190    def testAddMetatagsOrderList(self):
191        # Test added metatags order list if it was not there before
192        self.seoprops_tool.manage_delProperties(['metatags_order'])
193        self.qi.reinstallProducts([PROJECT_NAME])
194        mto = list(self.seoprops_tool.getProperty('metatags_order'))
195        mto.sort()
196        self.assertEqual(mto, DEFAULT_METATAGS_ORDER,
197                    "Not added metatags order list with default values."\
198                    "%s != %s" %(mto, DEFAULT_METATAGS_ORDER))
199
200    def testMigrationActions(self):
201        # Test migrated actions from portal_types action to seoproperties tool
202        self.seoprops_tool.content_types_with_seoproperties = ()
203
204        # Add seoaction to content type for testing
205        for type in CONTENTTYPES_WITH_SEOACTION:
206            self.types_tool.getTypeInfo(type).addAction(id='seo_properties',
207                                                   name='SEO Properties',
208                                                   action=None,
209                                                   condition=None,
210                                                   permission=(u'Modify portal content',),
211                                                   category='object',
212                                                   visible=True,
213                                                   icon_expr=None,
214                                                   link_target=None,
215                                                  )
216            # Check presence seoaction in content type
217            seoaction = [act.id for act in self.types_tool.getTypeInfo(type).listActions()
218                                          if act.id == 'seo_properties']
219            self.assertEqual(bool(seoaction), True,
220                    "Not added seoaction to content type %s for testing" % type)
221
222        self.qi.reinstallProducts([PROJECT_NAME])
223
224        # Check presence seoaction in content type
225        for type in CONTENTTYPES_WITH_SEOACTION:
226            seoaction = [act.id for act in self.types_tool.getTypeInfo(type).listActions()
227                                          if act.id == 'seo_properties']
228            self.assertEqual(bool(seoaction), False,
229                "Not removed seoaction in content type %s" % type)
230
231        # Check added content type names in seo properties tool if content types have seoaction
232        ctws = list(self.seoprops_tool.content_types_with_seoproperties)
233        ctws.sort()
234        self.assertEqual(ctws, CONTENTTYPES_WITH_SEOACTION,
235            "Not added content type names in seo properties tool if content types have seoaction."\
236            " %s != %s" %(ctws, CONTENTTYPES_WITH_SEOACTION))
237
238
239def test_suite():
240    from unittest import TestSuite, makeSuite
241    suite = TestSuite()
242    suite.addTest(makeSuite(TestBeforeInstallation))
243    suite.addTest(makeSuite(TestInstallation))
244    suite.addTest(makeSuite(TestUninstallation))
245    suite.addTest(makeSuite(TestReinstallation))
246    return suite
Note: See TracBrowser for help on using the repository browser.