source: products/vendor/Products.CacheSetup/current/Products/CacheSetup/tests/test_install.py @ 3296

Last change on this file since 3296 was 3296, checked in by fenix, 12 years ago

Load Products.CacheSetup?-1.2.1 into vendor/Products.CacheSetup?/current.

  • Property svn:eol-style set to native
File size: 9.3 KB
Line 
1from base import CacheFuTestCase
2
3from Interface.Verify import verifyObject
4from Products.Archetypes.public import listTypes
5from Products.CMFCore.utils  import getToolByName
6
7from Products.CacheSetup.config import *
8from Products.CacheSetup.interfaces import ICacheTool
9
10# util for making content in a container
11def makeContent(container, id, portal_type, title=None):
12    container.invokeFactory(id=id, type_name=portal_type)
13    o = getattr(container, id)
14    if title is not None:
15        o.setTitle(title)
16    return o
17
18
19# This is the test case. You will have to add test_<methods> to your
20# class inorder to assert things about your Product.
21class CacheManagerTest(CacheFuTestCase):
22    USER1 = 'user1'
23   
24    def afterSetUp(self):
25        CacheFuTestCase.afterSetUp(self)
26       
27        # Add a couple of users
28        self.portal.acl_users._doAddUser('manager', 'secret', ['Manager'], [])
29        self.portal.acl_users._doAddUser(self.USER1, 'secret', ['Member'], [])
30        self.login('manager')
31
32    def test_install(self):
33        cpm = self.portal.caching_policy_manager
34        cpm.addPolicy('foo', 'python:0', '', 1, 1, 0, 1, 'foo', '')
35        original_class = cpm.__class__
36        installed_types = [typeinfo['name'] for typeinfo in listTypes(PROJECT_NAME)]
37        # before installation the new types are not in the types factory
38        portal_factory = getToolByName(self, 'portal_factory')
39        self.assertEqual(set(installed_types).issubset(set(portal_factory.getFactoryTypes())), False)
40        self.portal.portal_quickinstaller.installProducts(['CacheSetup'])
41        self.portal.portal_quickinstaller.installProducts(['CacheSetup'])
42        # now the new types are in the types factory
43        self.assertEqual(set(installed_types).issubset(set(portal_factory.getFactoryTypes())), True)
44        cpm = self.portal.caching_policy_manager
45        self.assertNotEqual(cpm.__class__, original_class)
46        #self.failIf('caching_policy_manager' in self.portal.objectIds())
47       
48        self.portal.portal_quickinstaller.uninstallProducts(['CacheSetup'])
49        # now the new types are gone again
50        self.assertEqual(set(installed_types).issubset(set(portal_factory.getFactoryTypes())), False)
51        cpm = self.portal.caching_policy_manager
52        self.assertEqual(cpm.__class__, original_class)
53        lp = cpm.listPolicies()
54        self.assertEqual(len(lp), 1)
55        (id, p) = lp[0]
56        self.assertEqual(id, 'foo')
57        self.assertEqual(p.getPredicate(), 'python:0')
58
59class TestInstall(CacheFuTestCase):
60    """ ensure product is properly installed """
61
62    def afterSetUp(self):
63        self.types = self.portal.portal_types
64        self.skins = self.portal.portal_skins
65        self.factory = self.portal.portal_factory
66        self.tool = self.portal.portal_cache_settings
67        self.setRoles(['Manager', 'Member'])
68        self.tool.setEnabled(True)
69        self.metaTypes = ('CacheTool','ContentCacheRule',
70                          'TemplateCacheRule','PolicyHTTPCacheManagerCacheRule',
71                          'RuleFolder','HeaderSet','HeaderSetFolder')
72
73    def testTypesInstalled(self):
74        for t in self.metaTypes:
75            self.failUnless(t in self.types.objectIds(),
76                            '%s content type not installed' % t)
77
78    def testPortalFactorySetup(self):
79        for t in self.metaTypes:
80            self.failUnless(t in self.factory.getFactoryTypes(),
81                            '%s content type not in Portal Factory' % t)
82
83    def testSkinLayersInstalled(self):
84        self.failUnless('cache_setup' in self.skins.objectIds())
85
86    def testDependenciesInstalled(self):
87        # Zope products; not sure about this
88        #self.dependencies = ('PageCacheManager','PolicyHTTPCacheManager')
89
90        # Plone products
91        self.dependencies = ('CMFSquidTool',)
92        self.qitool = self.portal.portal_quickinstaller
93        installed = [p['id'] for p in self.qitool.listInstalledProducts()]
94        for p in self.dependencies:
95            self.failUnless(p in installed,
96                            '%s not installed' % p)
97
98    def testWorkflowSetup(self):
99        """ test if no workflow is associated with CacheFu's content types """
100        self.workflow = self.portal.portal_workflow
101        for t in self.metaTypes:
102            self.failUnless(self.workflow.getChainForPortalType(t) is ())
103
104    def testToolInstalled(self):
105        self.failUnless(getattr(self.portal, CACHE_TOOL_ID, None) is not None)
106
107    def testToolInterface(self):
108        t = self.tool
109        self.failUnless(ICacheTool.providedBy(t))
110        self.failUnless(verifyObject(ICacheTool, t))
111
112    def testToolNames(self):
113        t = self.tool
114        self.failUnlessEqual(t.meta_type, 'CacheTool')
115        self.failUnlessEqual(t.getId(), CACHE_TOOL_ID)
116        self.failUnlessEqual(t.title, 'Cache Configuration Tool')
117        self.failUnlessEqual(t.plone_tool, True)
118
119    # too specific... these policies will change
120    def testHeaderSetsInstalled(self):
121        return
122        self.headers = ('no-cache','cache-in-memory',
123                        'cache-with-etag','cache-with-last-modified',
124                        'cache-in-proxy-1-hour','cache-in-proxy-24-hours',
125                        'cache-in-browser-1-hour','cache-in-browser-24-hours',
126                        'cache-in-browser-forever')
127        installed = self.tool.getHeaderSets().objectIds()
128        for h in self.headers:
129            self.failUnless(h in installed,
130                            '%s header set not installed' % h)
131
132    # too specific... these policies will change
133    def testCacheRulesInstalled(self):
134        return
135        self.rules = ('httpcache','plone-content-types',
136                      'plone-containers','plone-templates',
137                      'resource-registries','downloads','dtml-css')
138        installed = self.tool.getRules().objectIds()
139        for r in self.rules:
140            self.failUnless(r in installed,
141                            '%s rule not installed' % r)
142
143    def _testCachingPolicyManagerRemoved(self):
144        self.fail('not yet implemented...')
145
146    def testSquidToolSetup(self):
147        squidtool = self.portal.portal_squid
148        expression = 'python:object.%s.getUrlsToPurge(object)' % CACHE_TOOL_ID
149        self.failUnlessEqual(squidtool.getUrlExpression(), expression)
150
151    def _testPolicyHTTPCaches(self):
152        self.fail('not yet implemented...')
153
154    def testResourceRegistrySetup(self):
155        cache = getattr(self.portal, RR_CACHE_ID, None)
156        self.failUnless(cache is not None)
157        settings = cache.getSettings()
158        self.failUnlessEqual(cache.title, 'Cache for saved ResourceRegistry files')
159        self.failUnlessEqual(settings['max_age'], 86400)
160        self.failUnlessEqual(settings['request_vars'], ('URL',))
161        self.csstool = self.portal.portal_css
162        self.failUnlessEqual(self.csstool.ZCacheable_getManagerId(), RR_CACHE_ID)
163        self.failUnless(self.csstool.ZCacheable_enabled())
164        self.jstool = self.portal.portal_javascripts
165        self.failUnlessEqual(self.jstool.ZCacheable_getManagerId(), RR_CACHE_ID)
166        self.failUnless(self.jstool.ZCacheable_enabled())
167
168    def _testSiteProperties(self):
169        self.fail('not yet implemented...')
170
171    def testConfigletInstalled(self):
172        self.controlpanel = self.portal.portal_controlpanel
173        installed = [a.getAction(self)['title'] for a in self.controlpanel.listActions()]
174        self.failUnless('Cache Configuration Tool' in installed)
175
176class TestUninstall(CacheFuTestCase):
177    """ ensure product is properly uninstalled """
178
179    def afterSetUp(self):
180        """ uninstall requieres 'Manager' role """
181        self.setRoles(['Manager', 'Member'])
182        self.portal.portal_cache_settings.setEnabled(True)
183        self.qitool = self.portal.portal_quickinstaller
184        self.qitool.uninstallProducts(products=[PROJECT_NAME])
185
186    def testProductUninstalled(self):
187        self.failIf(self.qitool.isProductInstalled(PROJECT_NAME))
188
189    def testToolUninstalled(self):
190        self.failIf(getattr(self.portal, CACHE_TOOL_ID, None) is not None)
191
192    def testSquidToolUninstalled(self):
193        """ uninstalling the product now also removes CMFSquidTool """
194        self.failIf(getattr(self.portal, 'portal_squid', None) is not None)
195
196    def testResourceRegistryRestore(self):
197        cache = getattr(self.portal, RR_CACHE_ID, None)
198        self.failIf(cache is not None)
199        self.csstool = self.portal.portal_css
200        #self.assertEqual(self.csstool.ZCacheable_getManagerId(), '---')
201        self.failIf(self.csstool.ZCacheable_getManagerId() is not None)
202        self.failIf(self.csstool.ZCacheable_enabled())
203        self.jstool = self.portal.portal_javascripts
204        self.failIf(self.jstool.ZCacheable_getManagerId() is not None)
205        self.failIf(self.jstool.ZCacheable_enabled())
206
207    def testConfigletsUninstalled(self):
208        self.configlets = ('Cache Configuration Tool',)
209        self.controlpanel = self.portal.portal_controlpanel
210        installed = [a.getAction(self)['title'] for a in self.controlpanel.listActions()]
211        for c in self.configlets:
212            self.failIf(c in installed,
213                            '%s configlet installed' % c)
214
215def test_suite():
216    from unittest import TestSuite, makeSuite
217    suite = TestSuite()
218    #suite.addTest(makeSuite(CacheManagerTest))
219    suite.addTest(makeSuite(TestInstall))
220    suite.addTest(makeSuite(TestUninstall))
221    return suite
Note: See TracBrowser for help on using the repository browser.