[CMF-checkins] SVN: CMF/branches/1.5/C - CMFCore.FSDTMLMethod:
Cache headers from the Caching Policy Manager
Jens Vagelpohl
jens at dataflake.org
Tue Aug 16 19:05:29 EDT 2005
Log message for revision 37975:
- CMFCore.FSDTMLMethod: Cache headers from the Caching Policy Manager
never got set for FS DTML Methods due to the way PortalContent's
__call__ method called the template.
(http://www.zope.org/Collectors/CMF/374)
Changed:
U CMF/branches/1.5/CHANGES.txt
U CMF/branches/1.5/CMFCore/FSDTMLMethod.py
A CMF/branches/1.5/CMFCore/tests/fake_skins/fake_skin/testDTML.dtml
A CMF/branches/1.5/CMFCore/tests/fake_skins/fake_skin/testDTML.dtml.metadata
A CMF/branches/1.5/CMFCore/tests/test_FSDTMLMethod.py
-=-
Modified: CMF/branches/1.5/CHANGES.txt
===================================================================
--- CMF/branches/1.5/CHANGES.txt 2005-08-16 23:04:21 UTC (rev 37974)
+++ CMF/branches/1.5/CHANGES.txt 2005-08-16 23:05:29 UTC (rev 37975)
@@ -2,6 +2,11 @@
Bug Fixes
+ - CMFCore.FSDTMLMethod: Cache headers from the Caching Policy Manager
+ never got set for FS DTML Methods due to the way PortalContent's
+ __call__ method called the template.
+ (http://www.zope.org/Collectors/CMF/374)
+
- CMFCore.FSImage and FSFile: Unlike the current behavior of Zope itself,
FSImage and FSFile would set a content-length response header for 304
(not modified) responses, which should not be done according to
Modified: CMF/branches/1.5/CMFCore/FSDTMLMethod.py
===================================================================
--- CMF/branches/1.5/CMFCore/FSDTMLMethod.py 2005-08-16 23:04:21 UTC (rev 37974)
+++ CMF/branches/1.5/CMFCore/FSDTMLMethod.py 2005-08-16 23:05:29 UTC (rev 37975)
@@ -110,6 +110,11 @@
"""Render the document given a client object, REQUEST mapping,
Response, and key word arguments."""
+ # If a RESPONSE is not passed in, try to access it through the
+ # REQUEST.
+ if RESPONSE is None and REQUEST != {}:
+ RESPONSE = getattr(REQUEST, 'RESPONSE', None)
+
self._updateFromFS()
if not self._cache_namespace_keys:
Added: CMF/branches/1.5/CMFCore/tests/fake_skins/fake_skin/testDTML.dtml
===================================================================
--- CMF/branches/1.5/CMFCore/tests/fake_skins/fake_skin/testDTML.dtml 2005-08-16 23:04:21 UTC (rev 37974)
+++ CMF/branches/1.5/CMFCore/tests/fake_skins/fake_skin/testDTML.dtml 2005-08-16 23:05:29 UTC (rev 37975)
@@ -0,0 +1 @@
+<dtml-var expr="REQUEST.get('SERVER_NAME')">
Property changes on: CMF/branches/1.5/CMFCore/tests/fake_skins/fake_skin/testDTML.dtml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: CMF/branches/1.5/CMFCore/tests/fake_skins/fake_skin/testDTML.dtml.metadata
===================================================================
--- CMF/branches/1.5/CMFCore/tests/fake_skins/fake_skin/testDTML.dtml.metadata 2005-08-16 23:04:21 UTC (rev 37974)
+++ CMF/branches/1.5/CMFCore/tests/fake_skins/fake_skin/testDTML.dtml.metadata 2005-08-16 23:05:29 UTC (rev 37975)
@@ -0,0 +1,2 @@
+[default]
+title=Zope Pope
Property changes on: CMF/branches/1.5/CMFCore/tests/fake_skins/fake_skin/testDTML.dtml.metadata
___________________________________________________________________
Name: svn:eol-style
+ native
Added: CMF/branches/1.5/CMFCore/tests/test_FSDTMLMethod.py
===================================================================
--- CMF/branches/1.5/CMFCore/tests/test_FSDTMLMethod.py 2005-08-16 23:04:21 UTC (rev 37974)
+++ CMF/branches/1.5/CMFCore/tests/test_FSDTMLMethod.py 2005-08-16 23:05:29 UTC (rev 37975)
@@ -0,0 +1,130 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" Unit tests for FSDTMLMethod module.
+
+$Id: test_FSDTMLMethod.py 37061 2005-06-15 14:17:41Z tseaver $
+"""
+from unittest import TestSuite, makeSuite, main
+import Testing
+try:
+ import Zope2
+except ImportError: # BBB: for Zope 2.7
+ import Zope as Zope2
+Zope2.startup()
+
+from os.path import join as path_join
+
+from OFS.Folder import Folder
+from Products.PageTemplates.TALES import Undefined
+from Products.StandardCacheManagers import RAMCacheManager
+
+from Products.CMFCore.FSDTMLMethod import FSDTMLMethod
+from Products.CMFCore.FSMetadata import FSMetadata
+from Products.CMFCore.tests.base.dummy import DummyCachingManager
+from Products.CMFCore.tests.base.testcase import FSDVTest
+from Products.CMFCore.tests.base.testcase import RequestTest
+from Products.CMFCore.tests.base.testcase import SecurityTest
+
+
+class FSDTMLMaker(FSDVTest):
+
+ def _makeOne( self, id, filename ):
+ path = path_join(self.skin_path_name, filename)
+ metadata = FSMetadata(path)
+ metadata.read()
+ return FSDTMLMethod( id, path, properties=metadata.getProperties() )
+
+
+class FSDTMLMethodTests( RequestTest, FSDTMLMaker ):
+
+ def setUp(self):
+ FSDTMLMaker.setUp(self)
+ RequestTest.setUp(self)
+
+ def tearDown(self):
+ RequestTest.tearDown(self)
+ FSDTMLMaker.tearDown(self)
+
+ def test_Call( self ):
+ script = self._makeOne( 'testDTML', 'testDTML.dtml' )
+ script = script.__of__(self.root)
+ self.assertEqual(script(self.root, self.REQUEST), 'foo\n')
+
+ def test_caching( self ):
+ # Test HTTP caching headers.
+ self.root.caching_policy_manager = DummyCachingManager()
+ original_len = len( self.RESPONSE.headers )
+ script = self._makeOne('testDTML', 'testDTML.dtml')
+ script = script.__of__(self.root)
+ script(self.root, self.REQUEST)
+ self.failUnless( len( self.RESPONSE.headers ) >= original_len + 2 )
+ self.failUnless( 'foo' in self.RESPONSE.headers.keys() )
+ self.failUnless( 'bar' in self.RESPONSE.headers.keys() )
+
+
+class FSDTMLMethodCustomizationTests( SecurityTest, FSDTMLMaker ):
+
+ def setUp( self ):
+ FSDTMLMaker.setUp(self)
+ SecurityTest.setUp( self )
+
+ self.root._setObject( 'portal_skins', Folder( 'portal_skins' ) )
+ self.skins = self.root.portal_skins
+
+ self.skins._setObject( 'custom', Folder( 'custom' ) )
+ self.custom = self.skins.custom
+
+ self.skins._setObject( 'fsdir', Folder( 'fsdir' ) )
+ self.fsdir = self.skins.fsdir
+
+ self.fsdir._setObject( 'testDTML'
+ , self._makeOne( 'testDTML', 'testDTML.dtml' ) )
+
+ self.fsDTML = self.fsdir.testDTML
+
+ def test_customize( self ):
+
+ self.fsDTML.manage_doCustomize( folder_path='custom' )
+
+ self.assertEqual( len( self.custom.objectIds() ), 1 )
+ self.failUnless( 'testDTML' in self.custom.objectIds() )
+
+ def test_customize_caching(self):
+ # Test to ensure that cache manager associations survive customizing
+ cache_id = 'gofast'
+ RAMCacheManager.manage_addRAMCacheManager( self.root
+ , cache_id
+ , REQUEST=None
+ )
+ self.fsDTML.ZCacheable_setManagerId(cache_id, REQUEST=None)
+
+ self.assertEqual(self.fsDTML.ZCacheable_getManagerId(), cache_id)
+
+ self.fsDTML.manage_doCustomize(folder_path='custom')
+ custom_pt = self.custom.testDTML
+
+ self.assertEqual(custom_pt.ZCacheable_getManagerId(), cache_id)
+
+ def tearDown(self):
+ SecurityTest.tearDown(self)
+ FSDTMLMaker.tearDown(self)
+
+
+def test_suite():
+ return TestSuite((
+ makeSuite(FSDTMLMethodTests),
+ makeSuite(FSDTMLMethodCustomizationTests),
+ ))
+
+if __name__ == '__main__':
+ main(defaultTest='test_suite')
Property changes on: CMF/branches/1.5/CMFCore/tests/test_FSDTMLMethod.py
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the CMF-checkins
mailing list