[CMF-checkins] CVS: CMF/CMFCore/tests -
test_CachingPolicyManager.py:1.11
Yvo Schubbe
schubbe at web.de
Fri Jan 2 05:04:36 EST 2004
Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv27367/CMFCore/tests
Modified Files:
test_CachingPolicyManager.py
Log Message:
- changed test to use a saver value for _epoch (Collector #107)
- some import and whitespace cleanup
=== CMF/CMFCore/tests/test_CachingPolicyManager.py 1.10 => 1.11 ===
--- CMF/CMFCore/tests/test_CachingPolicyManager.py:1.10 Thu Aug 14 19:32:07 2003
+++ CMF/CMFCore/tests/test_CachingPolicyManager.py Fri Jan 2 05:04:36 2004
@@ -1,42 +1,54 @@
+from unittest import TestCase, TestSuite, makeSuite, main
+
+import Testing
import Zope
-from App.Common import rfc1123_date
-import unittest
+try:
+ Zope.startup()
+except AttributeError:
+ # for Zope versions before 2.6.1
+ pass
+try:
+ from Interface.Verify import verifyClass
+except ImportError:
+ # for Zope versions before 2.6.0
+ from Interface import verify_class_implementation as verifyClass
+from App.Common import rfc1123_date
from DateTime.DateTime import DateTime
+from Products.CMFCore.CachingPolicyManager import CachingPolicy
+from Products.CMFCore.CachingPolicyManager import CachingPolicyManager
+from Products.CMFCore.CachingPolicyManager import createCPContext
+
ACCLARK = DateTime( '2001/01/01' )
+
class DummyContent:
__allow_access_to_unprotected_subobjects__ = 1
def __init__(self, modified ):
- self.modified = modified
+ self.modified = modified
def Type( self ):
return 'Dummy'
def modified( self ):
- return self.modified
+ return self.modified
-class CachingPolicyTests( unittest.TestCase ):
+class CachingPolicyTests(TestCase):
def setUp(self):
- self._epoch = DateTime( '1970/01/01' )
+ self._epoch = DateTime(0)
def _makePolicy( self, policy_id, **kw ):
-
- from Products.CMFCore.CachingPolicyManager import CachingPolicy
return CachingPolicy( policy_id, **kw )
def _makeContext( self, **kw ):
-
- from Products.CMFCore.CachingPolicyManager import createCPContext
- from Products.CMFCore.CachingPolicyManager import createCPContext
return createCPContext( DummyContent(self._epoch)
, 'foo_view', kw, self._epoch )
-
+
def test_empty( self ):
policy = self._makePolicy( 'empty' )
@@ -122,7 +134,7 @@
headers = policy.getHeaders( context )
self.assertEqual( len( headers ), 0 )
-
+
def test_mtimeFunc( self ):
policy = self._makePolicy( 'mtimeFunc'
@@ -134,7 +146,7 @@
self.assertEqual( headers[0][0], 'Last-modified' )
self.assertEqual( headers[0][1]
, rfc1123_date(ACCLARK.timeTime()) )
-
+
def test_mtimeFuncNone( self ):
policy = self._makePolicy( 'mtimeFuncNone'
@@ -143,7 +155,7 @@
headers = policy.getHeaders( context )
self.assertEqual( len( headers ), 0 )
-
+
def test_maxAge( self ):
policy = self._makePolicy( 'aged', max_age_secs=86400 )
@@ -159,7 +171,7 @@
, rfc1123_date((self._epoch+1).timeTime()) )
self.assertEqual( headers[2][0].lower() , 'cache-control' )
self.assertEqual( headers[2][1] , 'max-age=86400' )
-
+
def test_noCache( self ):
policy = self._makePolicy( 'noCache', no_cache=1 )
@@ -172,7 +184,7 @@
, rfc1123_date(self._epoch.timeTime()) )
self.assertEqual( headers[1][0].lower() , 'cache-control' )
self.assertEqual( headers[1][1] , 'no-cache' )
-
+
def test_noStore( self ):
policy = self._makePolicy( 'noStore', no_store=1 )
@@ -185,7 +197,7 @@
, rfc1123_date(self._epoch.timeTime()) )
self.assertEqual( headers[1][0].lower() , 'cache-control' )
self.assertEqual( headers[1][1] , 'no-store' )
-
+
def test_mustRevalidate( self ):
policy = self._makePolicy( 'mustRevalidate', must_revalidate=1 )
@@ -198,7 +210,7 @@
, rfc1123_date(self._epoch.timeTime()) )
self.assertEqual( headers[1][0].lower() , 'cache-control' )
self.assertEqual( headers[1][1] , 'must-revalidate' )
-
+
def test_combined( self ):
policy = self._makePolicy( 'noStore', no_cache=1, no_store=1 )
@@ -213,31 +225,18 @@
self.assertEqual( headers[1][1] , 'no-cache, no-store' )
-class CachingPolicyManagerTests( unittest.TestCase ):
+class CachingPolicyManagerTests(TestCase):
def setUp(self):
self._epoch = DateTime()
def _makeOne( self ):
- from Products.CMFCore.CachingPolicyManager import CachingPolicyManager
return CachingPolicyManager()
def assertEqualDelta( self, lhs, rhs, delta ):
self.failUnless( abs( lhs - rhs ) <= delta )
- def test_interface( self ):
- from Products.CMFCore.CachingPolicyManager import CachingPolicyManager
- from Products.CMFCore.interfaces.CachingPolicyManager \
- import CachingPolicyManager as ICachingPolicyManager
-
- try:
- from Interface import verify_class_implementation as verifyClass
- except ImportError:
- from Interface.Verify import verifyClass
-
- verifyClass(ICachingPolicyManager, CachingPolicyManager)
-
def test_empty( self ):
mgr = self._makeOne()
@@ -254,7 +253,7 @@
, 'xyzzy', None, None, None, None, None, None, '' )
self.assertRaises( KeyError, mgr._removePolicy, 'xyzzy' )
self.assertRaises( KeyError, mgr._reorderPolicy, 'xyzzy', -1 )
-
+
def test_addPolicy( self ):
mgr = self._makeOne()
@@ -333,7 +332,6 @@
self.assertEqual( headers[0][1]
, rfc1123_date(self._epoch.timeTime()) )
-
def test_lookupMatchBar( self ):
mgr = self._makeOneWithPolicies()
@@ -352,7 +350,6 @@
self.assertEqual( headers[2][0].lower() , 'cache-control' )
self.assertEqual( headers[2][1], 'max-age=0' )
-
def test_lookupMatchBaz( self ):
mgr = self._makeOneWithPolicies()
@@ -374,7 +371,6 @@
self.assertEqual( headers[2][0].lower() , 'cache-control' )
self.assertEqual( headers[2][1] , 'max-age=3600' )
-
def test_lookupMatchQux( self ):
mgr = self._makeOneWithPolicies()
@@ -396,11 +392,18 @@
self.assertEqual( headers[2][0].lower() , 'cache-control' )
self.assertEqual( headers[2][1] , 'max-age=86400' )
+ def test_interface(self):
+ from Products.CMFCore.interfaces.CachingPolicyManager \
+ import CachingPolicyManager as ICachingPolicyManager
+
+ verifyClass(ICachingPolicyManager, CachingPolicyManager)
+
+
def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite( CachingPolicyTests ),
- unittest.makeSuite( CachingPolicyManagerTests ),
- ))
+ return TestSuite((
+ makeSuite(CachingPolicyTests),
+ makeSuite(CachingPolicyManagerTests),
+ ))
if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
+ main(defaultTest='test_suite')
More information about the CMF-checkins
mailing list