[CMF-checkins] CVS: CMF/CMFCore/tests - test_CachingPolicyManager.py:1.3.2.1

Tres Seaver tseaver@zope.com
Thu, 4 Apr 2002 16:28:12 -0500


Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv19097/tests

Modified Files:
      Tag: CMF-1_3-branch
	test_CachingPolicyManager.py 
Log Message:
 - Merge Andrew's fixes for CPM emitting improper dates.

=== CMF/CMFCore/tests/test_CachingPolicyManager.py 1.3 => 1.3.2.1 ===
+from App.Common import rfc1123_date
 import unittest
 
 from DateTime.DateTime import DateTime
 
-EPOCH = DateTime( '1970/01/01' )
 ACCLARK = DateTime( '2001/01/01' )
 
 class DummyContent:
 
     __allow_access_to_unprotected_subobjects__ = 1
 
+    def __init__(self, EPOCH):
+        self.modified = EPOCH
+
     def Type( self ):
         return 'Dummy'
 
     def modified( self ):
-        return EPOCH
+        return self.modified 
 
 
 class CachingPolicyTests( unittest.TestCase ):
 
+    def setUp(self):
+        self.EPOCH = DateTime()
+
     def _makePolicy( self, policy_id, **kw ):
 
         from Products.CMFCore.CachingPolicyManager import CachingPolicy
@@ -28,7 +34,7 @@
 
         from Products.CMFCore.CachingPolicyManager import createCPContext
         from Products.CMFCore.CachingPolicyManager import createCPContext
-        return createCPContext( DummyContent(), 'foo_view', kw )
+        return createCPContext( DummyContent(self.EPOCH), 'foo_view', kw )
         
     def test_interface( self ):
         from Products.CMFCore.interfaces.CachingPolicyManager \
@@ -47,7 +53,7 @@
 
         self.assertEqual( len( headers ), 1 )
         self.assertEqual( headers[0][0] , 'Last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
 
     def test_noPassPredicate( self ):
 
@@ -66,7 +72,7 @@
 
         self.assertEqual( len( headers ), 1 )
         self.assertEqual( headers[0][0] , 'Last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
 
     def test_typePredicateMiss( self ):
 
@@ -86,7 +92,7 @@
 
         self.assertEqual( len( headers ), 1 )
         self.assertEqual( headers[0][0] , 'Last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
 
     def test_viewPredicateMiss( self ):
 
@@ -106,7 +112,7 @@
 
         self.assertEqual( len( headers ), 1 )
         self.assertEqual( headers[0][0] , 'Last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
 
     def test_kwPredicateMiss( self ):
 
@@ -130,7 +136,7 @@
 
         self.assertEqual( len( headers ), 1 )
         self.assertEqual( headers[0][0] , 'Last-modified' )
-        self.assertEqual( headers[0][1] , ACCLARK.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(ACCLARK.timeTime()) )
         
     def test_mtimeFuncNone( self ):
 
@@ -149,9 +155,9 @@
 
         self.assertEqual( len( headers ), 3 )
         self.assertEqual( headers[0][0].lower() , 'last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
         self.assertEqual( headers[1][0].lower() , 'expires' )
-        self.assertEqual( headers[1][1] , (EPOCH+1).rfc822() )
+        self.assertEqual( headers[1][1] , rfc1123_date((self.EPOCH+1).timeTime()) )
         self.assertEqual( headers[2][0].lower() , 'cache-control' )
         self.assertEqual( headers[2][1] , 'max-age=86400' )
         
@@ -163,7 +169,7 @@
 
         self.assertEqual( len( headers ), 2 )
         self.assertEqual( headers[0][0].lower() , 'last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
         self.assertEqual( headers[1][0].lower() , 'cache-control' )
         self.assertEqual( headers[1][1] , 'no-cache' )
         
@@ -175,7 +181,7 @@
 
         self.assertEqual( len( headers ), 2 )
         self.assertEqual( headers[0][0].lower() , 'last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
         self.assertEqual( headers[1][0].lower() , 'cache-control' )
         self.assertEqual( headers[1][1] , 'no-store' )
         
@@ -187,7 +193,7 @@
 
         self.assertEqual( len( headers ), 2 )
         self.assertEqual( headers[0][0].lower() , 'last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
         self.assertEqual( headers[1][0].lower() , 'cache-control' )
         self.assertEqual( headers[1][1] , 'must-revalidate' )
         
@@ -199,13 +205,15 @@
 
         self.assertEqual( len( headers ), 2 )
         self.assertEqual( headers[0][0].lower() , 'last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
         self.assertEqual( headers[1][0].lower() , 'cache-control' )
         self.assertEqual( headers[1][1] , 'no-cache, no-store' )
 
 
 class CachingPolicyManagerTests( unittest.TestCase ):
 
+    def setUp(self):
+        self.EPOCH = DateTime()
     def _makeOne( self ):
         from Products.CMFCore.CachingPolicyManager import CachingPolicyManager
         return CachingPolicyManager()
@@ -225,7 +233,7 @@
         mgr = self._makeOne()
 
         self.assertEqual( len( mgr.listPolicies() ), 0 )
-        headers = mgr.getHTTPCachingHeaders( content=DummyContent()
+        headers = mgr.getHTTPCachingHeaders( content=DummyContent(self.EPOCH)
                                            , view_method='foo_view'
                                            , keywords={}
                                            )
@@ -240,15 +248,15 @@
 
         mgr = self._makeOne()
         mgr._addPolicy( 'first', 'python:1', None, 0, 0, 0, 0 )
-        headers = mgr.getHTTPCachingHeaders( content=DummyContent()
+        headers = mgr.getHTTPCachingHeaders( content=DummyContent(self.EPOCH)
                                            , view_method='foo_view'
                                            , keywords={}
                                            )
         self.assertEqual( len( headers ), 3 )
         self.assertEqual( headers[0][0].lower() , 'last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
         self.assertEqual( headers[1][0].lower() , 'expires' )
-        self.assertEqual( headers[1][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[1][1] , rfc1123_date(self.EPOCH.timeTime()) )
         self.assertEqual( headers[2][0].lower() , 'cache-control' )
         self.assertEqual( headers[2][1] , 'max-age=0' )
 
@@ -291,7 +299,7 @@
     def test_lookupNoMatch( self ):
 
         mgr = self._makeOneWithPolicies()
-        headers = mgr.getHTTPCachingHeaders( content=DummyContent()
+        headers = mgr.getHTTPCachingHeaders( content=DummyContent(self.EPOCH)
                                            , view_method='foo_view'
                                            , keywords={}
                                            )
@@ -300,27 +308,27 @@
     def test_lookupMatchFoo( self ):
 
         mgr = self._makeOneWithPolicies()
-        headers = mgr.getHTTPCachingHeaders( content=DummyContent()
+        headers = mgr.getHTTPCachingHeaders( content=DummyContent(self.EPOCH)
                                            , view_method='foo_view'
                                            , keywords={ 'foo' : 1 }
                                            )
         self.assertEqual( len( headers ), 1 )
         self.assertEqual( headers[0][0].lower() , 'last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
 
 
     def test_lookupMatchBar( self ):
 
         mgr = self._makeOneWithPolicies()
-        headers = mgr.getHTTPCachingHeaders( content=DummyContent()
+        headers = mgr.getHTTPCachingHeaders( content=DummyContent(self.EPOCH)
                                            , view_method='foo_view'
                                            , keywords={ 'bar' : 1 }
                                            )
         self.assertEqual( len( headers ), 3 )
         self.assertEqual( headers[0][0].lower() , 'last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
         self.assertEqual( headers[1][0].lower() , 'expires' )
-        self.assertEqual( headers[1][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[1][1] , rfc1123_date(self.EPOCH.timeTime()) )
         self.assertEqual( headers[2][0].lower() , 'cache-control' )
         self.assertEqual( headers[2][1] , 'max-age=0' )
 
@@ -328,15 +336,15 @@
     def test_lookupMatchBaz( self ):
 
         mgr = self._makeOneWithPolicies()
-        headers = mgr.getHTTPCachingHeaders( content=DummyContent()
+        headers = mgr.getHTTPCachingHeaders( content=DummyContent(self.EPOCH)
                                            , view_method='foo_view'
                                            , keywords={ 'baz' : 1 }
                                            )
         self.assertEqual( len( headers ), 3 )
         self.assertEqual( headers[0][0].lower() , 'last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
         self.assertEqual( headers[1][0].lower() , 'expires' )
-        self.assertEqual( headers[1][1] , (EPOCH+(1.0/24.0)).rfc822() )
+        self.assertEqual( headers[1][1] , rfc1123_date((self.EPOCH+(1.0/24.0)).timeTime()) )
         self.assertEqual( headers[2][0].lower() , 'cache-control' )
         self.assertEqual( headers[2][1] , 'max-age=3600' )
 
@@ -344,15 +352,15 @@
     def test_lookupMatchQux( self ):
 
         mgr = self._makeOneWithPolicies()
-        headers = mgr.getHTTPCachingHeaders( content=DummyContent()
+        headers = mgr.getHTTPCachingHeaders( content=DummyContent(self.EPOCH)
                                            , view_method='foo_view'
                                            , keywords={ 'qux' : 1 }
                                            )
         self.assertEqual( len( headers ), 3 )
         self.assertEqual( headers[0][0].lower() , 'last-modified' )
-        self.assertEqual( headers[0][1] , EPOCH.rfc822() )
+        self.assertEqual( headers[0][1] , rfc1123_date(self.EPOCH.timeTime()) )
         self.assertEqual( headers[1][0].lower() , 'expires' )
-        self.assertEqual( headers[1][1] , (EPOCH+1).rfc822() )
+        self.assertEqual( headers[1][1] , rfc1123_date((self.EPOCH+1).timeTime()) )
         self.assertEqual( headers[2][0].lower() , 'cache-control' )
         self.assertEqual( headers[2][1] , 'max-age=86400' )