source: products/qSEOptimizer/tags/0.5.3/tests/testQSEOptimizer.py @ 1

Last change on this file since 1 was 1, checked in by myroslav, 18 years ago

Building directory structure

File size: 9.8 KB
Line 
1#
2# Test installation script
3#
4
5import os, sys, string
6if __name__ == '__main__':
7    execfile(os.path.join(sys.path[0], 'framework.py'))
8
9from Products.PloneTestCase import PloneTestCase
10from Products.CMFCore.utils import getToolByName
11from Products.CMFQuickInstallerTool.InstalledProduct import InstalledProduct
12
13try:
14    from Products.CMFCore.CMFCorePermissions import ManagePortal
15except:
16    from Products.CMFCore.permissions import ManagePortal
17
18from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager
19import re
20
21from Products.qSEOptimizer.config import *
22
23props = {'stop_words':STOP_WORDS, 'fields':FIELDS}
24
25configlets = ({'id':'qSEOptimizer',
26    'name':'Search Engine Optimizer',
27    'action':'string:${portal_url}/prefs_qseo_setup_form',
28    'condition':'',
29    'category':'Products',
30    'visible':1,
31    'appId':'qSEOptimizer',
32    'permission':ManagePortal},)
33
34PRODUCT = 'qSEOptimizer'
35qSEO_CONTENT = ['File','Document','News Item','BlogEntry']
36qSEO_FOLDER  = []
37qSEO_TYPES   = qSEO_CONTENT + qSEO_FOLDER
38
39PloneTestCase.installProduct(PRODUCT)
40PloneTestCase.setupPloneSite()
41
42
43class TestInstallation(PloneTestCase.PloneTestCase):
44
45    def afterSetUp(self):
46        self.properties = getToolByName(self.portal, 'portal_properties')
47        self.qi = self.portal.portal_quickinstaller
48        self.qi.installProduct(PRODUCT)
49
50    def testAddingPropertySheet(self):
51        """ Test adding property sheet to portal_properties tool """
52        self.failUnless(hasattr(self.properties.aq_base, PROPERTY_SHEET))
53
54    def testAddingPropertyFields(self):
55        """ Test adding property field to portal_properties.maps_properties sheet """
56        map_sheet = self.properties[PROPERTY_SHEET]
57        for key, value in props.items():
58            self.failUnless(map_sheet.hasProperty(key) and list(map_sheet.getProperty(key)) == value)
59
60    def test_configlet_install(self):
61        configTool = getToolByName(self.portal, 'portal_controlpanel', None)
62        self.assert_(PRODUCT in [a.getId() for a in configTool.listActions()], 'Configlet not found')
63
64    def test_actions_install(self):
65        portal_types = getToolByName(self.portal, 'portal_types')
66        for ptype in portal_types.objectValues():
67            action = ptype.getActionById('seo_properties', default=None )
68            if ptype.getId() in qSEO_TYPES:
69                self.assert_(action, 'Action for %s not found' % ptype.getId())
70            else:
71                self.assert_(not action, 'Action found for %s' % ptype.getId())
72
73    def test_skins_install(self):
74        skinstool=getToolByName(self.portal, 'portal_skins') 
75
76        for skin in skinstool.getSkinSelections():
77            path = skinstool.getSkinPath(skin)
78            path = map( string.strip, string.split( path,',' ) )
79            self.assert_(PRODUCT in path, 'qSEOptimizer layer not found in %s' %skin)
80
81    def test_versionedskin_install(self):
82        skinstool=getToolByName(self.portal, 'portal_skins')
83        mtool = getToolByName(self.portal, 'portal_migration')
84        plone_version = mtool.getFileSystemVersion()
85
86        for skin in skinstool.getSkinSelections():
87            path = skinstool.getSkinPath(skin)
88            path = map( string.strip, string.split( path,',' ) )
89            self.assert_(PRODUCT+'/%s' % plone_version in path, 'qSEOptimizer versioned layer not found in %s' %skin)
90
91    def test_actions_uninstall(self):
92        self.qi.uninstallProducts([PRODUCT])
93        self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed')
94        portal_types = getToolByName(self.portal, 'portal_types')
95        for ptype in portal_types.objectValues():
96            action = ptype.getActionById('seo_properties', default=None )
97            self.assert_(not action, 'Action for %s found after uninstallation' % ptype.getId())
98
99    def test_skins_uninstall(self):
100        self.qi.uninstallProducts([PRODUCT])
101        self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed')
102        skinstool=getToolByName(self.portal, 'portal_skins') 
103
104        for skin in skinstool.getSkinSelections():
105            path = skinstool.getSkinPath(skin)
106            path = map( string.strip, string.split( path,',' ) )
107            self.assert_(not PRODUCT in path, 'qSEOptimizer layer found in %s after uninstallation' %skin)
108
109    def test_versionedskin_uninstall(self):
110        self.qi.uninstallProducts([PRODUCT])
111        self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed')
112        skinstool=getToolByName(self.portal, 'portal_skins')
113        mtool = getToolByName(self.portal, 'portal_migration')
114        plone_version = mtool.getFileSystemVersion()
115
116        for skin in skinstool.getSkinSelections():
117            path = skinstool.getSkinPath(skin)
118            path = map( string.strip, string.split( path,',' ) )
119            self.assert_(not PRODUCT+'/%s' % plone_version in path, 'qSEOptimizer versioned layer found in %s after uninstallation' %skin)
120
121    def test_configlet_uninstall(self):
122        self.qi.uninstallProducts([PRODUCT])
123        self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed')
124
125        configTool = getToolByName(self.portal, 'portal_controlpanel', None)
126        self.assert_(not PRODUCT in [a.getId() for a in configTool.listActions()], 'Configlet found after uninstallation')
127
128class TestResponse(PloneTestCase.FunctionalTestCase):
129
130    def afterSetUp(self):
131        self.qi = self.portal.portal_quickinstaller
132        self.qi.installProduct(PRODUCT)
133        self.portal.changeSkin('Plone Default')
134
135        self.basic_auth = 'mgr:mgrpw'
136        self.loginAsPortalOwner()
137
138        '''Preparation for functional testing'''
139        my_doc = self.portal.invokeFactory('Document', id='my_doc')
140        my_doc = self.portal['my_doc']
141
142        my_doc.qseo_properties_edit(title='hello world', description='it is description',
143                                    keywords='my1|key2', html_comment='no comments',
144                                    robots='ALL', distribution='Global', title_override=1,
145                                    description_override=1, keywords_override=1,
146                                    html_comment_override=1, robots_override=1,
147                                    distribution_override=1)
148
149        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth))
150
151    def testTitle(self):
152        m = re.match('.*<title>\\s*hello world\\s*</title>', self.html, re.S|re.M)
153        self.assert_(m, 'Title not set in')
154
155    def testDescription(self):
156        m = re.match('.*<meta content="it is description" name="description" />', self.html, re.S|re.M)
157        self.assert_(m, 'Description not set in')
158
159    def testKeywords(self):
160        m = re.match('.*<meta content="my1|key2" name="keywords" />', self.html, re.S|re.M)
161        self.assert_(m, 'Keywords not set in')
162
163    def testRobots(self):
164        m = re.match('.*<meta content="ALL" name="robots" />', self.html, re.S|re.M)
165        self.assert_(m, 'Robots not set in')
166
167    def testDistribution(self):
168        m = re.match('.*<meta content="Global" name="distribution" />', self.html, re.S|re.M)
169        self.assert_(m, 'Distribution not set in')
170
171    def testHTMLComments(self):
172        m = re.match('.*<!--\\s*no comments\\s*-->', self.html, re.S|re.M)
173        self.assert_(m, 'Comments not set in')
174
175class TestExposeDCMetaTags(PloneTestCase.FunctionalTestCase):
176
177    def afterSetUp(self):
178        self.qi = self.portal.portal_quickinstaller
179        self.sp = self.portal.portal_properties.site_properties
180        self.qi.installProduct(PRODUCT)
181        self.portal.changeSkin('Plone Default')
182
183        self.basic_auth = 'portal_manager:secret'
184        uf = self.app.acl_users
185        uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], [])
186        user = uf.getUserById('portal_manager')
187        if not hasattr(user, 'aq_base'):
188            user = user.__of__(uf)
189        newSecurityManager(None, user)
190
191        '''Preparation for functional testing'''
192        self.my_doc = self.portal.invokeFactory('Document', id='my_doc')
193        self.my_doc = self.portal['my_doc']
194
195    def test_exposeDCMetaTags_in_configletOn(self):
196        path = self.portal.id+'/prefs_qseo_setup?exposeDCMetaTags=on'
197        self.publish(path, self.basic_auth)
198        self.assert_(self.sp.exposeDCMetaTags)
199
200    def test_exposeDCMetaTags_in_configletOff(self):
201        self.publish(self.portal.id+'/prefs_qseo_setup', self.basic_auth)
202        self.assert_(not self.sp.exposeDCMetaTags)
203
204    def test_exposeDCMetaTagsPropertyOff(self):
205        self.sp.manage_changeProperties(exposeDCMetaTags = False)
206
207        self.my_doc.qseo_properties_edit()
208        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth))
209
210        m = re.match('.*<meta content=".*?" name="DC.format" />', self.html, re.S|re.M) or re.match('.*<meta content=".*?" name="DC.distribution" />', self.html, re.S|re.M)
211        self.assert_(not m, 'DC meta tags avaliable when exposeDCMetaTags=False')
212
213    def test_exposeDCMetaTagsPropertyOn(self):
214        self.sp.manage_changeProperties(exposeDCMetaTags = True)
215
216        self.my_doc.qseo_properties_edit()
217        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth))
218
219        m = re.match('.*<meta content=".*?" name="DC.format" />', self.html, re.S|re.M) and re.match('.*<meta content=".*?" name="DC.distribution" />', self.html, re.S|re.M)
220
221        self.assert_(m, 'DC meta tags not avaliable when createManager=True')
222
223TESTS = [TestInstallation, TestResponse, TestExposeDCMetaTags]
224
225def test_suite():
226    from unittest import TestSuite, makeSuite
227    suite = TestSuite()
228    suite.addTest(makeSuite(TestInstallation))
229    suite.addTest(makeSuite(TestResponse))
230    suite.addTest(makeSuite(TestExposeDCMetaTags))
231    return suite
232
233if __name__ == '__main__':
234    framework()
235
Note: See TracBrowser for help on using the repository browser.