1 | # |
---|
2 | # Test product's installation |
---|
3 | # |
---|
4 | import string |
---|
5 | from base import getToolByName, FunctionalTestCase, TestCase, newSecurityManager |
---|
6 | from config import * |
---|
7 | |
---|
8 | |
---|
9 | class TestBeforeInstall(FunctionalTestCase): |
---|
10 | |
---|
11 | def afterSetUp(self): |
---|
12 | self.basic_auth = 'mgr:mgrpw' |
---|
13 | self.portal_path = '/%s' % self.portal.absolute_url(1) |
---|
14 | |
---|
15 | def testAccessPortalRootAnonymous(self): |
---|
16 | response = self.publish(self.portal_path) |
---|
17 | self.assertEqual(response.getStatus(), 200) |
---|
18 | |
---|
19 | def testAccessPortalRootAuthenticated(self): |
---|
20 | response = self.publish(self.portal_path, self.basic_auth) |
---|
21 | self.assertEqual(response.getStatus(), 200) |
---|
22 | |
---|
23 | |
---|
24 | class TestInstallation(TestCase): |
---|
25 | |
---|
26 | def afterSetUp(self): |
---|
27 | self.properties = getToolByName(self.portal, 'portal_properties') |
---|
28 | self.qi = self.portal.portal_quickinstaller |
---|
29 | self.qi.installProduct(PROJECT_NAME) |
---|
30 | |
---|
31 | def testAddingPropertySheet(self): |
---|
32 | """ Test adding property sheet to portal_properties tool """ |
---|
33 | self.failUnless(hasattr(self.properties.aq_base, PROPERTY_SHEET)) |
---|
34 | |
---|
35 | def testAddingPropertyFields(self): |
---|
36 | """ Test adding property field to portal_properties.maps_properties sheet """ |
---|
37 | map_sheet = self.properties[PROPERTY_SHEET] |
---|
38 | for key, value in PROPS.items(): |
---|
39 | self.failUnless(map_sheet.hasProperty(key) and list(map_sheet.getProperty(key)) == value) |
---|
40 | |
---|
41 | def test_configlet_install(self): |
---|
42 | configTool = getToolByName(self.portal, 'portal_controlpanel', None) |
---|
43 | self.assert_(PROJECT_NAME in [a.getId() for a in configTool.listActions()], 'Configlet not found') |
---|
44 | |
---|
45 | def test_actions_install(self): |
---|
46 | portal_types = getToolByName(self.portal, 'portal_types') |
---|
47 | for ptype in portal_types.objectValues(): |
---|
48 | try: |
---|
49 | #for Plone-2.5 and higher |
---|
50 | acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions()) |
---|
51 | action = acts and acts[0] or None |
---|
52 | except AttributeError: |
---|
53 | action = ptype.getActionById('seo_properties', default=None ) |
---|
54 | |
---|
55 | if ptype.getId() in qSEO_TYPES: |
---|
56 | self.assert_(action, 'Action for %s not found' % ptype.getId()) |
---|
57 | else: |
---|
58 | self.assert_(not action, 'Action found for %s' % ptype.getId()) |
---|
59 | |
---|
60 | def test_skins_install(self): |
---|
61 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
62 | |
---|
63 | for skin in skinstool.getSkinSelections(): |
---|
64 | path = skinstool.getSkinPath(skin) |
---|
65 | path = map( string.strip, string.split( path,',' ) ) |
---|
66 | self.assert_(PROJECT_NAME in path, 'qSEOptimizer layer not found in %s' %skin) |
---|
67 | |
---|
68 | def test_versionedskin_install(self): |
---|
69 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
70 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
71 | plone_version = mtool.getFileSystemVersion() |
---|
72 | if plone_version < "3": |
---|
73 | for skin in skinstool.getSkinSelections(): |
---|
74 | path = skinstool.getSkinPath(skin) |
---|
75 | path = map( string.strip, string.split( path,',' ) ) |
---|
76 | self.assert_(PROJECT_NAME+'/%s' % plone_version in path, 'qSEOptimizer versioned layer not found in %s' %skin) |
---|
77 | |
---|
78 | def test_actions_uninstall(self): |
---|
79 | self.qi.uninstallProducts([PROJECT_NAME]) |
---|
80 | self.assertNotEqual(self.qi.isProductInstalled(PROJECT_NAME), True,'qSEOptimizer is already installed') |
---|
81 | portal_types = getToolByName(self.portal, 'portal_types') |
---|
82 | for ptype in portal_types.objectValues(): |
---|
83 | try: |
---|
84 | #for Plone-2.5 and higher |
---|
85 | acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions()) |
---|
86 | action = acts and acts[0] or None |
---|
87 | except AttributeError: |
---|
88 | action = ptype.getActionById('seo_properties', default=None ) |
---|
89 | |
---|
90 | self.assert_(not action, 'Action for %s found after uninstallation' % ptype.getId()) |
---|
91 | |
---|
92 | def test_skins_uninstall(self): |
---|
93 | self.qi.uninstallProducts([PROJECT_NAME]) |
---|
94 | self.assertNotEqual(self.qi.isProductInstalled(PROJECT_NAME), True,'qSEOptimizer is already installed') |
---|
95 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
96 | |
---|
97 | for skin in skinstool.getSkinSelections(): |
---|
98 | path = skinstool.getSkinPath(skin) |
---|
99 | path = map( string.strip, string.split( path,',' ) ) |
---|
100 | self.assert_(not PROJECT_NAME in path, 'qSEOptimizer layer found in %s after uninstallation' %skin) |
---|
101 | |
---|
102 | def test_versionedskin_uninstall(self): |
---|
103 | self.qi.uninstallProducts([PROJECT_NAME]) |
---|
104 | self.assertNotEqual(self.qi.isProductInstalled(PROJECT_NAME), True,'qSEOptimizer is already installed') |
---|
105 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
106 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
107 | plone_version = mtool.getFileSystemVersion() |
---|
108 | |
---|
109 | for skin in skinstool.getSkinSelections(): |
---|
110 | path = skinstool.getSkinPath(skin) |
---|
111 | path = map( string.strip, string.split( path,',' ) ) |
---|
112 | self.assert_(not PROJECT_NAME+'/%s' % plone_version in path, 'qSEOptimizer versioned layer found in %s after uninstallation' %skin) |
---|
113 | |
---|
114 | def test_configlet_uninstall(self): |
---|
115 | self.qi.uninstallProducts([PROJECT_NAME]) |
---|
116 | self.assertNotEqual(self.qi.isProductInstalled(PROJECT_NAME), True,'qSEOptimizer is already installed') |
---|
117 | |
---|
118 | configTool = getToolByName(self.portal, 'portal_controlpanel', None) |
---|
119 | self.assert_(not PROJECT_NAME in [a.getId() for a in configTool.listActions()], 'Configlet found after uninstallation') |
---|
120 | |
---|
121 | def test_suite(): |
---|
122 | from unittest import TestSuite, makeSuite |
---|
123 | suite = TestSuite() |
---|
124 | suite.addTest(makeSuite(TestBeforeInstall)) |
---|
125 | suite.addTest(makeSuite(TestInstallation)) |
---|
126 | return suite |
---|