[CMF-checkins] SVN: CMF/branches/jens_tools_as_utilities/CMF -
converted caching policy manager to utility usage
Jens Vagelpohl
jens at dataflake.org
Wed Nov 22 06:40:38 EST 2006
Log message for revision 71262:
- converted caching policy manager to utility usage
Changed:
U CMF/branches/jens_tools_as_utilities/CMFCore/CachingPolicyManager.py
U CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/actions.py
U CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/cachingpolicymgr.py
U CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_cachingpolicymgr.py
U CMF/branches/jens_tools_as_utilities/CMFCore/testing.py
U CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_CachingPolicyManager.py
U CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSDTMLMethod.py
U CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSPageTemplate.py
U CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSReSTMethod.py
U CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSSTXMethod.py
U CMF/branches/jens_tools_as_utilities/CMFCore/utils.py
U CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_File.py
U CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Image.py
-=-
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/CachingPolicyManager.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/CachingPolicyManager.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/CachingPolicyManager.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -43,6 +43,7 @@
from utils import _setCacheHeaders
from utils import _ViewEmulator
from utils import getToolByName
+from utils import registerToolInterface
# This is lame :(
# This listing is used to decide whether to wrap an object inside a "fake view"
@@ -876,8 +877,8 @@
InitializeClass( CachingPolicyManager )
+registerToolInterface('caching_policy_manager', ICachingPolicyManager)
-
def handleCachingPolicyManagerEvent(ob, event):
""" Event subscriber for (un)registering a CPM as CacheManager
"""
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/actions.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/actions.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/actions.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -35,6 +35,7 @@
from zope.component import adapts
from zope.component import getUtility
from zope.component import getSiteManager
+from zope.component.interfaces import ComponentLookupError
_SPECIAL_PROVIDERS = ('portal_actions', 'portal_types', 'portal_workflow')
@@ -257,8 +258,9 @@
"""Export actions tool.
"""
sm = getSiteManager(context.getSite())
- tool = sm.getUtility(IActionsTool)
- if tool is None:
+ try:
+ tool = sm.getUtility(IActionsTool)
+ except ComponentLookupError:
logger = context.getLogger('actions')
logger.info('Nothing to export.')
return
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/cachingpolicymgr.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/cachingpolicymgr.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/cachingpolicymgr.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -16,7 +16,10 @@
"""
from zope.component import adapts
+from zope.component import getUtility
+from zope.component import getSiteManager
from zope.component import queryMultiAdapter
+from zope.component.interfaces import ComponentLookupError
from Products.GenericSetup.interfaces import INode
from Products.GenericSetup.interfaces import ISetupEnviron
@@ -27,7 +30,6 @@
from Products.CMFCore.interfaces import ICachingPolicy
from Products.CMFCore.interfaces import ICachingPolicyManager
-from Products.CMFCore.utils import getToolByName
class CachingPolicyNodeAdapter(NodeAdapterBase):
@@ -172,17 +174,18 @@
def importCachingPolicyManager(context):
"""Import caching policy manager settings from an XML file.
"""
- site = context.getSite()
- tool = getToolByName(site, 'caching_policy_manager')
+ sm = getSiteManager(context.getSite())
+ tool = sm.getUtility(ICachingPolicyManager)
importObjects(tool, '', context)
def exportCachingPolicyManager(context):
"""Export caching policy manager settings as an XML file.
"""
- site = context.getSite()
- tool = getToolByName(site, 'caching_policy_manager', None)
- if tool is None:
+ sm = getSiteManager(context.getSite())
+ try:
+ tool = sm.getUtility(ICachingPolicyManager)
+ except ComponentLookupError:
logger = context.getLogger('cachingpolicies')
logger.info('Nothing to export.')
return
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_cachingpolicymgr.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_cachingpolicymgr.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_cachingpolicymgr.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -26,8 +26,11 @@
from Products.GenericSetup.tests.common import DummyExportContext
from Products.GenericSetup.tests.common import DummyImportContext
+from Products.CMFCore.interfaces._tools import ICachingPolicyManager
from Products.CMFCore.testing import ExportImportZCMLLayer
+from zope.component import getSiteManager
+
_CP_XML = """\
<caching-policy name="foo_policy" enable_304s="False" etag_func=""
last_modified="True" max_age_secs="0" mtime_func="object/modified"
@@ -128,6 +131,9 @@
mgr = CachingPolicyManager()
site._setObject( mgr.getId(), mgr )
+ sm = getSiteManager(site)
+ sm.registerUtility(site.caching_policy_manager, ICachingPolicyManager)
+
if with_policy:
mgr.addPolicy( policy_id=self.POLICY_ID
, predicate=self.PREDICATE
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/testing.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/testing.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/testing.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -144,6 +144,7 @@
zcml.load_config('meta.zcml', Products.Five)
zcml.load_config('traversing.zcml', Products.Five)
+ setHooks()
@classmethod
def tearDown(cls):
@@ -161,6 +162,7 @@
i18n._fallback_translation_service = _FallbackTranslationService()
zcml.load_config('testing.zcml', Products.CMFCore)
+ setHooks()
@classmethod
def tearDown(cls):
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_CachingPolicyManager.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_CachingPolicyManager.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_CachingPolicyManager.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -28,6 +28,9 @@
from DateTime.DateTime import DateTime
from OFS.Cache import Cacheable
+from zope.app.component.hooks import setHooks
+from zope.component import getSiteManager
+
from Products.CMFCore.FSPageTemplate import FSPageTemplate
from Products.CMFCore.FSDTMLMethod import FSDTMLMethod
from Products.CMFCore.testing import FunctionalZCMLLayer
@@ -38,6 +41,7 @@
from Products.CMFCore.tests.base.dummy import DummyUserFolder
from Products.CMFCore.tests.base.testcase import FSDVTest
from Products.CMFCore.tests.base.testcase import RequestTest
+from Products.CMFCore.interfaces._tools import ICachingPolicyManager
ACCLARK = DateTime( '2001/01/01' )
portal_owner = 'portal_owner'
@@ -680,6 +684,9 @@
CachingPolicyManager.manage_addCachingPolicyManager(self.portal)
cpm = self.portal.caching_policy_manager
+ sm = getSiteManager(self.portal)
+ sm.registerUtility(cpm, ICachingPolicyManager)
+
# This policy only applies to doc1. It will not emit any ETag header
# but it enables If-modified-since handling.
cpm.addPolicy(policy_id = 'policy_no_etag',
@@ -903,6 +910,11 @@
from Products.CMFCore import CachingPolicyManager
CachingPolicyManager.manage_addCachingPolicyManager(self.portal)
+ sm = getSiteManager(self.portal)
+ sm.registerUtility( self.portal.caching_policy_manager
+ , ICachingPolicyManager
+ )
+
def tearDown(self):
RequestTest.tearDown(self)
FSObjMaker.tearDown(self)
@@ -1223,6 +1235,9 @@
CachingPolicyManager.manage_addCachingPolicyManager(self.portal)
cpm = self.portal.caching_policy_manager
+ sm = getSiteManager(self.portal)
+ sm.registerUtility(cpm, ICachingPolicyManager)
+
# This policy only applies to doc1. It will not emit any ETag header
# but it enables If-modified-since handling.
cpm.addPolicy(policy_id = 'policy_1',
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSDTMLMethod.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSDTMLMethod.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSDTMLMethod.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -26,6 +26,7 @@
from Products.CMFCore.FSDTMLMethod import FSDTMLMethod
from Products.CMFCore.FSMetadata import FSMetadata
+from Products.CMFCore.interfaces._tools import ICachingPolicyManager
from Products.CMFCore.tests.base.dummy import DummyCachingManager
from Products.CMFCore.tests.base.dummy import DummyCachingManagerWithPolicy
from Products.CMFCore.tests.base.testcase import FSDVTest
@@ -33,7 +34,10 @@
from Products.CMFCore.tests.base.testcase import SecurityTest
from Products.CMFCore.tests.base.dummy import DummyContent
+from zope.app.component.hooks import setHooks
+from zope.component import getSiteManager
+
class FSDTMLMaker(FSDVTest):
def _makeOne( self, id, filename ):
@@ -48,11 +52,19 @@
def setUp(self):
FSDTMLMaker.setUp(self)
RequestTest.setUp(self)
+ setHooks()
def tearDown(self):
RequestTest.tearDown(self)
FSDTMLMaker.tearDown(self)
+ def _setupCachingPolicyManager(self, cpm_object):
+ self.root.caching_policy_manager = cpm_object
+ sm = getSiteManager(self.root)
+ sm.registerUtility( self.root.caching_policy_manager
+ , ICachingPolicyManager
+ )
+
def test_Call( self ):
script = self._makeOne( 'testDTML', 'testDTML.dtml' )
script = script.__of__(self.app)
@@ -60,7 +72,7 @@
def test_caching( self ):
# Test HTTP caching headers.
- self.root.caching_policy_manager = DummyCachingManager()
+ self._setupCachingPolicyManager(DummyCachingManager())
original_len = len( self.RESPONSE.headers )
script = self._makeOne('testDTML', 'testDTML.dtml')
script = script.__of__(self.root)
@@ -87,7 +99,7 @@
from webdav.common import rfc1123_date
mod_time = DateTime()
- self.root.caching_policy_manager = DummyCachingManagerWithPolicy()
+ self._setupCachingPolicyManager(DummyCachingManagerWithPolicy())
content = DummyContent(id='content')
content.modified_date = mod_time
content = content.__of__(self.root)
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSPageTemplate.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSPageTemplate.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSPageTemplate.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -23,10 +23,14 @@
from OFS.Folder import Folder
from Products.StandardCacheManagers import RAMCacheManager
+
+from zope.app.component.hooks import setHooks
+from zope.component import getSiteManager
from zope.tales.tales import Undefined
from Products.CMFCore.FSPageTemplate import FSPageTemplate
from Products.CMFCore.FSMetadata import FSMetadata
+from Products.CMFCore.interfaces._tools import ICachingPolicyManager
from Products.CMFCore.testing import TraversingZCMLLayer
from Products.CMFCore.tests.base.dummy import DummyCachingManager
from Products.CMFCore.tests.base.testcase import FSDVTest
@@ -55,6 +59,13 @@
RequestTest.tearDown(self)
FSPTMaker.tearDown(self)
+ def _setupCachingPolicyManager(self, cpm_object):
+ self.root.caching_policy_manager = cpm_object
+ sm = getSiteManager(self.root)
+ sm.registerUtility( self.root.caching_policy_manager
+ , ICachingPolicyManager
+ )
+
def test_Call( self ):
script = self._makeOne( 'testPT', 'testPT.pt' )
script = script.__of__(self.app)
@@ -105,7 +116,7 @@
def test_caching( self ):
# Test HTTP caching headers.
- self.root.caching_policy_manager = DummyCachingManager()
+ self._setupCachingPolicyManager(DummyCachingManager())
original_len = len( self.RESPONSE.headers )
script = self._makeOne('testPT', 'testPT.pt')
script = script.__of__(self.root)
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSReSTMethod.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSReSTMethod.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSReSTMethod.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -18,12 +18,13 @@
import os
import re
-from zope.component.testing import PlacelessSetup
+from zope.component import getSiteManager
+from Products.CMFCore.interfaces._tools import ICachingPolicyManager
+from Products.CMFCore.testing import TraversingZCMLLayer
from Products.CMFCore.tests.base.testcase import FSDVTest
from Products.CMFCore.tests.base.testcase import RequestTest
from Products.CMFCore.tests.base.testcase import SecurityTest
-from Products.CMFCore.tests.base.utils import _setUpDefaultTraversable
class FSReSTMaker(FSDVTest):
@@ -75,22 +76,21 @@
return ' '.join(WS.split(text.rstrip()))
-class FSReSTMethodTests(RequestTest, FSReSTMaker, PlacelessSetup):
+class FSReSTMethodTests(RequestTest, FSReSTMaker):
+ layer = TraversingZCMLLayer
+
def setUp(self):
RequestTest.setUp(self)
FSReSTMaker.setUp(self)
- PlacelessSetup.setUp(self)
def tearDown(self):
- PlacelessSetup.tearDown(self)
FSReSTMaker.tearDown(self)
RequestTest.tearDown(self)
def test___call__( self ):
script = self._makeOne( 'testReST', 'testReST.rst' )
script = script.__of__(self.app)
- _setUpDefaultTraversable()
self.assertEqual(_normalize_whitespace(script(self.REQUEST)),
_normalize_whitespace(_EXPECTED_HTML))
@@ -98,10 +98,15 @@
# Test HTTP caching headers.
from Products.CMFCore.tests.base.dummy import DummyCachingManager
self.root.caching_policy_manager = DummyCachingManager()
+
+ sm = getSiteManager(self.root)
+ sm.registerUtility( self.root.caching_policy_manager
+ , ICachingPolicyManager
+ )
+
original_len = len( self.RESPONSE.headers )
script = self._makeOne('testReST', 'testReST.rst')
script = script.__of__(self.root)
- _setUpDefaultTraversable()
script(self.REQUEST, self.RESPONSE)
self.failUnless( len( self.RESPONSE.headers ) >= original_len + 2 )
self.failUnless( 'foo' in self.RESPONSE.headers.keys() )
@@ -129,6 +134,12 @@
mod_time = DateTime()
self.root.caching_policy_manager = DummyCachingManagerWithPolicy()
+
+ sm = getSiteManager(self.root)
+ sm.registerUtility( self.root.caching_policy_manager
+ , ICachingPolicyManager
+ )
+
script = self._makeOne('testReST', 'testReST.rst')
script = script.__of__(self.root)
self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
@@ -146,16 +157,12 @@
,
)
-class FSReSTMethodCustomizationTests(SecurityTest,
- FSReSTMaker,
- PlacelessSetup,
- ):
+class FSReSTMethodCustomizationTests(SecurityTest, FSReSTMaker):
def setUp( self ):
from OFS.Folder import Folder
SecurityTest.setUp( self )
FSReSTMaker.setUp(self)
- PlacelessSetup.setUp(self)
self.root._setObject( 'portal_skins', Folder( 'portal_skins' ) )
self.skins = self.root.portal_skins
@@ -172,7 +179,6 @@
self.fsReST = self.fsdir.testReST
def tearDown( self ):
- PlacelessSetup.tearDown(self)
FSReSTMaker.tearDown( self )
SecurityTest.tearDown( self )
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSSTXMethod.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSSTXMethod.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_FSSTXMethod.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -18,8 +18,10 @@
import os
import re
-from zope.component.testing import PlacelessSetup
+from zope.component import getSiteManager
+from Products.CMFCore.interfaces._tools import ICachingPolicyManager
+from Products.CMFCore.testing import TraversingZCMLLayer
from Products.CMFCore.tests.base.testcase import FSDVTest
from Products.CMFCore.tests.base.testcase import RequestTest
from Products.CMFCore.tests.base.testcase import SecurityTest
@@ -93,17 +95,16 @@
class FSSTXMethodTests(RequestTest,
FSSTXMaker,
_TemplateSwitcher,
- PlacelessSetup,
):
+ layer = TraversingZCMLLayer
+
def setUp(self):
_TemplateSwitcher.setUp(self)
FSSTXMaker.setUp(self)
RequestTest.setUp(self)
- PlacelessSetup.setUp(self)
def tearDown(self):
- PlacelessSetup.tearDown(self)
RequestTest.tearDown(self)
FSSTXMaker.tearDown(self)
_TemplateSwitcher.tearDown(self)
@@ -128,6 +129,12 @@
from Products.CMFCore.tests.base.dummy import DummyCachingManager
self._setWhichTemplate('DTML')
self.root.caching_policy_manager = DummyCachingManager()
+
+ sm = getSiteManager(self.root)
+ sm.registerUtility( self.root.caching_policy_manager
+ , ICachingPolicyManager
+ )
+
original_len = len( self.RESPONSE.headers )
script = self._makeOne('testSTX', 'testSTX.stx')
script = script.__of__(self.root)
@@ -158,6 +165,12 @@
mod_time = DateTime()
self.root.caching_policy_manager = DummyCachingManagerWithPolicy()
+
+ sm = getSiteManager(self.root)
+ sm.registerUtility( self.root.caching_policy_manager
+ , ICachingPolicyManager
+ )
+
script = self._makeOne('testSTX', 'testSTX.stx')
script = script.__of__(self.root)
self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
@@ -178,7 +191,6 @@
class FSSTXMethodCustomizationTests(SecurityTest,
FSSTXMaker,
_TemplateSwitcher,
- PlacelessSetup,
):
def setUp( self ):
@@ -186,7 +198,6 @@
FSSTXMaker.setUp(self)
SecurityTest.setUp( self )
_TemplateSwitcher.setUp( self )
- PlacelessSetup.setUp(self)
self.root._setObject( 'portal_skins', Folder( 'portal_skins' ) )
self.skins = self.root.portal_skins
@@ -203,7 +214,6 @@
self.fsSTX = self.fsdir.testSTX
def tearDown( self ):
- PlacelessSetup.tearDown(self)
_TemplateSwitcher.tearDown( self )
FSSTXMaker.tearDown( self )
SecurityTest.tearDown( self )
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/utils.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/utils.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/utils.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -52,6 +52,7 @@
from exceptions import AccessControl_Unauthorized
from exceptions import NotFound
+from interfaces._tools import ICachingPolicyManager
SUBTEMPLATE = '__SUBTEMPLATE__'
@@ -331,8 +332,9 @@
# not a conditional GET
return False
- manager = getToolByName(obj, 'caching_policy_manager', None)
- if manager is None:
+ try:
+ manager = getUtility(ICachingPolicyManager)
+ except ComponentLookupError:
return False
ret = manager.getModTimeAndETag(aq_parent(obj), obj.getId(), extra_context)
@@ -412,23 +414,26 @@
delattr(REQUEST, SUBTEMPLATE)
content = aq_parent(obj)
- manager = getToolByName(obj, 'caching_policy_manager', None)
- if manager is not None:
- view_name = obj.getId()
- headers = manager.getHTTPCachingHeaders(
- content, view_name, extra_context
- )
- RESPONSE = REQUEST['RESPONSE']
- for key, value in headers:
- if key == 'ETag':
- RESPONSE.setHeader(key, value, literal=1)
- else:
- RESPONSE.setHeader(key, value)
- if headers:
- RESPONSE.setHeader('X-Cache-Headers-Set-By',
- 'CachingPolicyManager: %s' %
- '/'.join(manager.getPhysicalPath()))
+ try:
+ manager = getUtility(ICachingPolicyManager)
+ except ComponentLookupError:
+ return
+ view_name = obj.getId()
+ headers = manager.getHTTPCachingHeaders(
+ content, view_name, extra_context
+ )
+ RESPONSE = REQUEST['RESPONSE']
+ for key, value in headers:
+ if key == 'ETag':
+ RESPONSE.setHeader(key, value, literal=1)
+ else:
+ RESPONSE.setHeader(key, value)
+ if headers:
+ RESPONSE.setHeader('X-Cache-Headers-Set-By',
+ 'CachingPolicyManager: %s' %
+ '/'.join(manager.getPhysicalPath()))
+
class _ViewEmulator(Implicit):
"""Auxiliary class used to adapt FSFile and FSImage
for caching_policy_manager
Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_File.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_File.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_File.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -20,6 +20,10 @@
from os.path import join as path_join
+from zope.app.component.hooks import setHooks
+from zope.component import getSiteManager
+
+from Products.CMFCore.interfaces._tools import ICachingPolicyManager
from Products.CMFCore.testing import ConformsToContent
from Products.CMFCore.tests.base.dummy import DummyCachingManagerWithPolicy
from Products.CMFCore.tests.base.dummy import DummyCachingManager
@@ -75,6 +79,10 @@
class CachingTests(RequestTest):
+ def setUp(self):
+ RequestTest.setUp(self)
+ setHooks()
+
def _getTargetClass(self):
from Products.CMFDefault.File import File
@@ -93,8 +101,15 @@
return TEST_SWF, data
+ def _setupCachingPolicyManager(self, cpm_object):
+ self.root.caching_policy_manager = cpm_object
+ sm = getSiteManager(self.root)
+ sm.registerUtility( self.root.caching_policy_manager
+ , ICachingPolicyManager
+ )
+
def test_index_html_with_304_from_cpm( self ):
- self.root.caching_policy_manager = DummyCachingManagerWithPolicy()
+ self._setupCachingPolicyManager(DummyCachingManagerWithPolicy())
path, ref = self._extractFile()
from webdav.common import rfc1123_date
@@ -116,7 +131,7 @@
def test_index_html_200_with_cpm( self ):
# should behave the same as without cpm installed
- self.root.caching_policy_manager = DummyCachingManager()
+ self._setupCachingPolicyManager(DummyCachingManager())
path, ref = self._extractFile()
from webdav.common import rfc1123_date
@@ -139,7 +154,7 @@
, rfc1123_date( mod_time ) )
def test_caching( self ):
- self.root.caching_policy_manager = DummyCachingManager()
+ self._setupCachingPolicyManager(DummyCachingManager())
original_len = len(self.RESPONSE.headers)
file = self._makeOne('test_file', 'test_file.swf')
file = file.__of__(self.root)
Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Image.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Image.py 2006-11-22 11:33:21 UTC (rev 71261)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Image.py 2006-11-22 11:40:37 UTC (rev 71262)
@@ -21,10 +21,14 @@
from os.path import join as path_join
from cStringIO import StringIO
+from zope.app.component.hooks import setHooks
+from zope.component import getSiteManager
+
import transaction
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.User import UnrestrictedUser
+from Products.CMFCore.interfaces._tools import ICachingPolicyManager
from Products.CMFCore.testing import ConformsToContent
from Products.CMFCore.tests.base.dummy import DummyCachingManager
from Products.CMFCore.tests.base.dummy import DummyCachingManagerWithPolicy
@@ -174,6 +178,10 @@
class TestCaching(RequestTest):
+ def setUp(self):
+ RequestTest.setUp(self)
+ setHooks()
+
def _extractFile( self ):
f = open( TEST_JPG, 'rb' )
@@ -192,8 +200,15 @@
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)
+ def _setupCachingPolicyManager(self, cpm_object):
+ self.root.caching_policy_manager = cpm_object
+ sm = getSiteManager(self.root)
+ sm.registerUtility( self.root.caching_policy_manager
+ , ICachingPolicyManager
+ )
+
def test_index_html_with_304_from_cpm( self ):
- self.root.caching_policy_manager = DummyCachingManagerWithPolicy()
+ self._setupCachingPolicyManager(DummyCachingManagerWithPolicy())
path, ref = self._extractFile()
from webdav.common import rfc1123_date
@@ -214,7 +229,7 @@
self.assertEqual( self.RESPONSE.getStatus(), 304 )
def test_caching( self ):
- self.root.caching_policy_manager = DummyCachingManager()
+ self._setupCachingPolicyManager(DummyCachingManager())
original_len = len(self.RESPONSE.headers)
image = self._makeOne('test_image', 'test_image.jpg')
image = image.__of__(self.root)
@@ -226,7 +241,7 @@
self.assertEqual(headers['test_path'], '/test_image')
def test_index_html_200_with_cpm( self ):
- self.root.caching_policy_manager = DummyCachingManagerWithPolicy()
+ self._setupCachingPolicyManager(DummyCachingManagerWithPolicy())
path, ref = self._extractFile()
from webdav.common import rfc1123_date
@@ -252,7 +267,7 @@
def test_index_html_with_304_and_caching( self ):
# See collector #355
- self.root.caching_policy_manager = DummyCachingManager()
+ self._setupCachingPolicyManager(DummyCachingManager())
original_len = len(self.RESPONSE.headers)
path, ref = self._extractFile()
More information about the CMF-checkins
mailing list