1 | import unittest |
---|
2 | |
---|
3 | from base import CacheFuTestCase |
---|
4 | |
---|
5 | from Products.CMFCore.utils import getToolByName |
---|
6 | import Products.CacheSetup.config as config |
---|
7 | |
---|
8 | # util for making content in a container |
---|
9 | def makeContent(container, id, portal_type, title=None): |
---|
10 | container.invokeFactory(id=id, type_name=portal_type) |
---|
11 | o = getattr(container, id) |
---|
12 | if title is not None: |
---|
13 | o.setTitle(title) |
---|
14 | return o |
---|
15 | |
---|
16 | |
---|
17 | # This is the test case. You will have to add test_<methods> to your |
---|
18 | # class inorder to assert things about your Product. |
---|
19 | class CacheManagerTest(CacheFuTestCase): |
---|
20 | USER1 = 'user1' |
---|
21 | |
---|
22 | def afterSetUp(self): |
---|
23 | CacheFuTestCase.afterSetUp(self) |
---|
24 | |
---|
25 | # Add a couple of users |
---|
26 | self.portal.acl_users._doAddUser('manager', 'secret', ['Manager'], []) |
---|
27 | self.portal.acl_users._doAddUser(self.USER1, 'secret', ['Member'], []) |
---|
28 | self.login('manager') |
---|
29 | |
---|
30 | self.portal.portal_quickinstaller.installProducts(['CacheSetup']) |
---|
31 | |
---|
32 | # We have added a skin so we need to rebuild the skin object |
---|
33 | # (since the object is cached in the current request) |
---|
34 | self._refreshSkinData() |
---|
35 | |
---|
36 | # cacheConfig deprecated |
---|
37 | # |
---|
38 | #def test_set_domains(self): |
---|
39 | # pcs = self.portal.portal_cache_settings |
---|
40 | # pcs.setCacheConfig('squid') |
---|
41 | # pcs.setDomains('\nfoo.com\n\nhttp://www.bar.com\nhttps://bar.com\nwww.foo.com:8080') |
---|
42 | # self.assertEqual(pcs.getDomains(), ('http://foo.com:80','http://www.bar.com:80','https://bar.com:443','http://www.foo.com:8080')) |
---|
43 | # pcs.setCacheConfig('squid_behind_apache') |
---|
44 | # pcs.setDomains('\nfoo.com\n\nhttp://www.bar.com\nhttps://bar.com\nwww.foo.com:8080') |
---|
45 | # self.assertEqual(pcs.getDomains(), ('http://foo.com:80','http://www.bar.com:80','https://bar.com:443','http://www.foo.com:8080')) |
---|
46 | |
---|
47 | #def test_squid_urls(self): |
---|
48 | # pcs = self.portal.portal_cache_settings |
---|
49 | # squid_tool = self.portal.portal_squid |
---|
50 | # |
---|
51 | # pcs.setCacheConfig('squid_behind_apache') |
---|
52 | # pcs.setSquidURLs(['http://localhost:3128']) |
---|
53 | # self.assertEqual(pcs.getSquidURLs(), ('http://localhost:3128',)) |
---|
54 | # self.assertEqual(squid_tool.getSquidURLs(), 'http://localhost:3128') |
---|
55 | # |
---|
56 | # pcs.setSquidURLs(['http://localhost:3128','http://someotherhost:3128']) |
---|
57 | # self.assertEqual(pcs.getSquidURLs(), ('http://localhost:3128','http://someotherhost:3128')) |
---|
58 | # self.assertEqual(squid_tool.getSquidURLs(), 'http://localhost:3128\nhttp://someotherhost:3128') |
---|
59 | |
---|
60 | def test_vary_header(self): |
---|
61 | pcs = self.portal.portal_cache_settings |
---|
62 | |
---|
63 | pcs.setVaryHeader('foobar') |
---|
64 | self.assertEqual(pcs.getVaryHeader(), 'foobar') |
---|
65 | |
---|
66 | #for header_set in pcs.getHeaderSets().objectValues(): |
---|
67 | # self.assertEqual(header_set.getVary(), 'foobar') |
---|
68 | |
---|
69 | |
---|
70 | #def test_cache_config(self): |
---|
71 | # pcs = self.portal.portal_cache_settings |
---|
72 | # self.assertEqual(pcs.getCacheConfig(), 'zserver') |
---|
73 | # rules = pcs.getRules() |
---|
74 | # rule = getattr(rules, 'plone-content-types') |
---|
75 | # self.assertEqual(rule.getHeaderSetIdAnon(), 'cache-in-memory') |
---|
76 | # |
---|
77 | # pcs.setCacheConfig('apache') |
---|
78 | # self.assertEqual(rule.getHeaderSetIdAnon(), 'cache-in-memory') |
---|
79 | # |
---|
80 | # pcs.setCacheConfig('squid') |
---|
81 | # self.assertEqual(rule.getHeaderSetIdAnon(), 'cache-in-proxy-1-hour') |
---|
82 | # |
---|
83 | # pcs.setCacheConfig('squid_behind_apache') |
---|
84 | # self.assertEqual(rule.getHeaderSetIdAnon(), 'cache-in-proxy-1-hour') |
---|
85 | # |
---|
86 | # pcs.setCacheConfig('zserver') |
---|
87 | # self.assertEqual(rule.getHeaderSetIdAnon(), 'cache-in-memory') |
---|
88 | |
---|
89 | def test_suite(): |
---|
90 | suite = unittest.TestSuite() |
---|
91 | suite.addTest(unittest.makeSuite(CacheManagerTest)) |
---|
92 | return suite |
---|