[Checkins] SVN: Products.CMFDefault/trunk/Products/CMFDefault/tests/test_ Tests to prove that the Last Modified date OFS provides based on p_mtime is being used in preference to those set on CachingPolicyManagers.
Matthew Wilkes
matthew at matthewwilkes.co.uk
Fri Nov 20 15:48:29 EST 2009
Log message for revision 105925:
Tests to prove that the Last Modified date OFS provides based on p_mtime is being used in preference to those set on CachingPolicyManagers.
N.B. This doesn't happen for ZCachable_get() style header setting as OFS explicitly re-runs that after setting its headers.
Changed:
U Products.CMFDefault/trunk/Products/CMFDefault/tests/test_File.py
U Products.CMFDefault/trunk/Products/CMFDefault/tests/test_Image.py
-=-
Modified: Products.CMFDefault/trunk/Products/CMFDefault/tests/test_File.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/tests/test_File.py 2009-11-20 20:46:53 UTC (rev 105924)
+++ Products.CMFDefault/trunk/Products/CMFDefault/tests/test_File.py 2009-11-20 20:48:29 UTC (rev 105925)
@@ -17,6 +17,8 @@
import unittest
import Testing
+import transaction
+import DateTime
from os.path import join as path_join
@@ -172,8 +174,38 @@
self.failUnless('bar' in headers.keys())
self.assertEqual(headers['test_path'], '/test_file')
self.RESPONSE.write = response_write
+
+ def test_caching_policy_headers_are_canonical(self):
+ """Ensure that headers set by the caching policy manager trump
+ any of the same name that from time to time may be set while
+ rendering the object."""
+ path, ref = self._extractFile()
+ self._setupCachingPolicyManager(LMDummyCachingManager())
+ file = self._makeOne( 'test_file', 'test_file.swf', file=ref )
+
+ # Cause persistent's modified time record to be set
+ self.root.foo = file
+ transaction.commit()
+ file = self.root.foo
+ # end
+
+ # index_html in OFS will set Last-modified if ._p_mtime exists
+ file.index_html(self.REQUEST, self.RESPONSE)
+
+ headers = self.RESPONSE.headers
+ self.assertEqual(headers['last-modified'],
+ "Sun, 06 Nov 1994 08:49:37 GMT")
+
+# We set up a new type of dummy caching manager that sets a bogus
+# last modified date. This should be visible in the request
+class LMDummyCachingManager(DummyCachingManager):
+
+ def getHTTPCachingHeaders( self, content, view_name,
+ keywords, time=None ):
+ return ('Last-modified', 'Sun, 06 Nov 1994 08:49:37 GMT'),
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(FileTests),
Modified: Products.CMFDefault/trunk/Products/CMFDefault/tests/test_Image.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/tests/test_Image.py 2009-11-20 20:46:53 UTC (rev 105924)
+++ Products.CMFDefault/trunk/Products/CMFDefault/tests/test_Image.py 2009-11-20 20:48:29 UTC (rev 105925)
@@ -37,6 +37,8 @@
from Products.CMFDefault import tests
from Products.CMFDefault.testing import FunctionalLayer
+from test_File import LMDummyCachingManager
+
TESTS_HOME = tests.__path__[0]
TEST_JPG = path_join(TESTS_HOME, 'TestImage.jpg')
@@ -306,7 +308,29 @@
self.failUnless('bar' in headers.keys())
self.assertEqual(headers['test_path'], '/test_image')
+ def test_caching_policy_headers_are_canonical(self):
+ """Ensure that headers set by the caching policy manager trump
+ any of the same name that from time to time may be set while
+ rendering the object."""
+ path, ref = self._extractFile()
+ self._setupCachingPolicyManager(LMDummyCachingManager())
+
+ img = self._makeOne( 'test_image', 'test_image.gif' )
+
+ # Cause persistent's modified time record to be set
+ self.root.foo = img
+ transaction.commit()
+ img = self.root.foo
+ # end
+ import pdb; pdb.set_trace( )
+ # index_html in OFS will set Last-modified if ._p_mtime exists
+ img.index_html(self.REQUEST, self.RESPONSE)
+
+ headers = self.RESPONSE.headers
+ self.assertEqual(headers['last-modified'],
+ "Sun, 06 Nov 1994 08:49:37 GMT")
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestImageElement),
More information about the checkins
mailing list