[3296] | 1 | # |
---|
| 2 | # Exportimport adapter tests |
---|
| 3 | # |
---|
| 4 | |
---|
| 5 | from Products.CMFPlone.tests import PloneTestCase |
---|
| 6 | from Products.CMFPlone.exportimport.tests.base import \ |
---|
| 7 | BodyAdapterTestCase |
---|
| 8 | from Products.CMFPlone.FactoryTool import FactoryTool |
---|
| 9 | from OFS.Folder import Folder |
---|
| 10 | from Products.ATContentTypes.content.folder import ATFolder |
---|
| 11 | from Products.CacheSetup.interfaces import ICacheTool |
---|
| 12 | from zope.interface import implements |
---|
| 13 | from Products.CacheSetup.content.cache_tool import CacheTool |
---|
| 14 | from Products.PageCacheManager.PageCacheManager import\ |
---|
| 15 | PageCacheManager |
---|
| 16 | try: |
---|
| 17 | from Products.CMFCore.interfaces._tools import ITypesTool |
---|
| 18 | except ImportError: |
---|
| 19 | ITypesTool = None |
---|
| 20 | |
---|
| 21 | _CACHESETTINGS_XML = """\ |
---|
| 22 | <?xml version="1.0"?> |
---|
| 23 | <cachesettings title="Cache Configuration Tool" |
---|
| 24 | contentid="portal_cache_settings" portaltype="CacheTool"> |
---|
| 25 | <field name="cacheConfig" value="zserver"/> |
---|
| 26 | <field name="domains"/> |
---|
| 27 | <field name="squidURLs" value=""/> |
---|
| 28 | <field name="gzip" value="accept-encoding"/> |
---|
| 29 | <field name="varyHeader" value="Accept-Encoding, Accept-Language"/> |
---|
| 30 | <pagecachesetting name="threshold" value="500"/> |
---|
| 31 | <pagecachesetting name="cleanup_interval" value="60"/> |
---|
| 32 | <pagecachesetting name="max_age" value="3600"/> |
---|
| 33 | <pagecachesetting name="active" value="on_always"/> |
---|
| 34 | </cachesettings> |
---|
| 35 | """ |
---|
| 36 | |
---|
| 37 | class DummyCacheTool(CacheTool): |
---|
| 38 | #schema = () |
---|
| 39 | def Title(self): |
---|
| 40 | return 'Cache Configuration Tool' |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | class DummyPortalTypesTool(Folder): |
---|
| 44 | id = 'portal_types' |
---|
| 45 | if ITypesTool: |
---|
| 46 | implements(ITypesTool) |
---|
| 47 | |
---|
| 48 | def listContentTypes(self): |
---|
| 49 | return ('Folder', 'Document') |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | class DummyPortalSquidTool(Folder): |
---|
| 53 | def manage_setSquidSettings(self, list): |
---|
| 54 | pass |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | class DummyPageCacheManager(PageCacheManager): |
---|
| 58 | pass |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | class DummyPortalMembershipTool(Folder): |
---|
| 62 | pass |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | class PortalFactoryXMLAdapterTests(BodyAdapterTestCase): |
---|
| 66 | """The actual test methods are defined in our parent class. |
---|
| 67 | We just have to set everything up. |
---|
| 68 | """ |
---|
| 69 | |
---|
| 70 | def _getTargetClass(self): |
---|
| 71 | from Products.CacheSetup.exportimport.cachefu \ |
---|
| 72 | import CacheSettingsAdapter |
---|
| 73 | return CacheSettingsAdapter |
---|
| 74 | |
---|
| 75 | def _populate(self, obj): |
---|
| 76 | # For better tests, a RuleFolder should be added to test that |
---|
| 77 | # part of the migration. Also modify the xml at the top of |
---|
| 78 | # this testingfile if you do so, of course. |
---|
| 79 | pass |
---|
| 80 | |
---|
| 81 | def _verifyImport(self, obj): |
---|
| 82 | """After applying the import step, this method is run. |
---|
| 83 | """ |
---|
| 84 | |
---|
| 85 | cache_tool = self.site.portal_cache_settings |
---|
| 86 | page_cache = self.site.CacheSetup_PageCache |
---|
| 87 | self.assertEquals(cache_tool.getCacheConfig(), |
---|
| 88 | "zserver") |
---|
| 89 | self.assertEquals(page_cache._settings['threshold'], |
---|
| 90 | 500) |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | def setUp(self): |
---|
| 94 | self.site = Folder('site') |
---|
| 95 | self.site.portal_cache_settings = DummyCacheTool( |
---|
| 96 | 'portal_cache_settings') |
---|
| 97 | self.site.portal_types = DummyPortalTypesTool() |
---|
| 98 | self.site.portal_membership = DummyPortalMembershipTool() |
---|
| 99 | self.site.portal_squid = DummyPortalSquidTool() |
---|
| 100 | self.site.CacheSetup_PageCache = DummyPageCacheManager( |
---|
| 101 | 'CacheSetup_PageCache') |
---|
| 102 | self._obj = self.site.portal_cache_settings |
---|
| 103 | self._BODY = _CACHESETTINGS_XML |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | def test_suite(): |
---|
| 107 | from unittest import TestSuite, makeSuite |
---|
| 108 | suite = TestSuite() |
---|
| 109 | suite.addTest(makeSuite(PortalFactoryXMLAdapterTests)) |
---|
| 110 | return suite |
---|