Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
CMFCore.tests.test_CachingPolicyManager.CachingPolicyManagerTests Class Reference

List of all members.

Public Member Functions

def setUp
def assertEqualDelta
def test_z2interfaces
def test_z3interfaces
def test_empty
def test_addAndUpdatePolicy
def test_reorder
def test_lookupNoMatch
def test_lookupMatchFoo
def test_lookupMatchBar
def test_lookupMatchBaz
def test_lookupMatchQux

Static Public Attributes

 layer = TraversingZCMLLayer

Private Member Functions

def _makeOne
def _makeOneWithPolicies

Private Attributes

 _epoch

Detailed Description

Definition at line 426 of file test_CachingPolicyManager.py.


Member Function Documentation

Definition at line 430 of file test_CachingPolicyManager.py.

00430 
00431     def _makeOne(self, *args, **kw):
00432         from Products.CMFCore.CachingPolicyManager import CachingPolicyManager
00433 
00434         return CachingPolicyManager(*args, **kw)

Definition at line 540 of file test_CachingPolicyManager.py.

00540 
00541     def _makeOneWithPolicies( self ):
00542 
00543         mgr = self._makeOne()
00544 
00545         policy_tuples = ( ( 'foo', None  )
00546                         , ( 'bar', 0     )
00547                         , ( 'baz', 3600  )
00548                         , ( 'qux', 86400 )
00549                         )
00550 
00551         for policy_id, max_age_secs in policy_tuples:
00552             mgr._addPolicy( policy_id
00553                           , 'python:"%s" in keywords.keys()' % policy_id
00554                           , None, max_age_secs, 0, 0, 0, '', '' )
00555 
00556         return mgr

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 438 of file test_CachingPolicyManager.py.

00438 
00439     def assertEqualDelta( self, lhs, rhs, delta ):
00440         self.failUnless( abs( lhs - rhs ) <= delta )

Here is the caller graph for this function:

Definition at line 435 of file test_CachingPolicyManager.py.

00435 
00436     def setUp(self):
00437         self._epoch = DateTime()

Definition at line 474 of file test_CachingPolicyManager.py.

00474 
00475     def test_addAndUpdatePolicy( self ):
00476 
00477         mgr = self._makeOne()
00478         mgr.addPolicy('first', 'python:1', 'mtime', 1, 0, 1, 0, 'vary',
00479                       'etag', None, 2, 1, 0, 1, 0, 1, 0, 2, 3)
00480         p = mgr._policies['first']
00481         self.assertEqual(p.getPolicyId(), 'first')
00482         self.assertEqual(p.getPredicate(), 'python:1')
00483         self.assertEqual(p.getMTimeFunc(), 'mtime')
00484         self.assertEqual(p.getMaxAgeSecs(), 1)
00485         self.assertEqual(p.getNoCache(), 0)
00486         self.assertEqual(p.getNoStore(), 1)
00487         self.assertEqual(p.getMustRevalidate(), 0)
00488         self.assertEqual(p.getVary(), 'vary')
00489         self.assertEqual(p.getETagFunc(), 'etag')
00490         self.assertEqual(p.getSMaxAgeSecs(), 2)
00491         self.assertEqual(p.getProxyRevalidate(), 1)
00492         self.assertEqual(p.getPublic(), 0)
00493         self.assertEqual(p.getPrivate(), 1)
00494         self.assertEqual(p.getNoTransform(), 0)
00495         self.assertEqual(p.getEnable304s(), 1)
00496         self.assertEqual(p.getLastModified(), 0)
00497         self.assertEqual(p.getPreCheck(), 2)
00498         self.assertEqual(p.getPostCheck(), 3)
00499 
00500         mgr.updatePolicy('first', 'python:0', 'mtime2', 2, 1, 0, 1, 'vary2',
00501                          'etag2', None, 1, 0, 1, 0, 1, 0, 1, 3, 2)
00502         p = mgr._policies['first']
00503         self.assertEqual(p.getPolicyId(), 'first')
00504         self.assertEqual(p.getPredicate(), 'python:0')
00505         self.assertEqual(p.getMTimeFunc(), 'mtime2')
00506         self.assertEqual(p.getMaxAgeSecs(), 2)
00507         self.assertEqual(p.getNoCache(), 1)
00508         self.assertEqual(p.getNoStore(), 0)
00509         self.assertEqual(p.getMustRevalidate(), 1)
00510         self.assertEqual(p.getVary(), 'vary2')
00511         self.assertEqual(p.getETagFunc(), 'etag2')
00512         self.assertEqual(p.getSMaxAgeSecs(), 1)
00513         self.assertEqual(p.getProxyRevalidate(), 0)
00514         self.assertEqual(p.getPublic(), 1)
00515         self.assertEqual(p.getPrivate(), 0)
00516         self.assertEqual(p.getNoTransform(), 1)
00517         self.assertEqual(p.getEnable304s(), 0)
00518         self.assertEqual(p.getLastModified(), 1)
00519         self.assertEqual(p.getPreCheck(), 3)
00520         self.assertEqual(p.getPostCheck(), 2)

Here is the call graph for this function:

Definition at line 456 of file test_CachingPolicyManager.py.

00456 
00457     def test_empty( self ):
00458 
00459         mgr = self._makeOne()
00460 
00461         self.assertEqual( len( mgr.listPolicies() ), 0 )
00462         headers = mgr.getHTTPCachingHeaders( content=DummyContent2(self._epoch)
00463                                            , view_method='foo_view'
00464                                            , keywords={}
00465                                            , time=self._epoch
00466                                            )
00467         self.assertEqual( len( headers ), 0 )
00468 
00469         self.assertRaises( KeyError, mgr._updatePolicy,
00470                            'xyzzy', None, None, None, None, None, None, '',
00471                            '', None, None, None, None, None )
00472         self.assertRaises( KeyError, mgr._removePolicy, 'xyzzy' )
00473         self.assertRaises( KeyError, mgr._reorderPolicy, 'xyzzy', -1 )

Here is the call graph for this function:

Definition at line 580 of file test_CachingPolicyManager.py.

00580 
00581     def test_lookupMatchBar( self ):
00582 
00583         mgr = self._makeOneWithPolicies()
00584         headers = mgr.getHTTPCachingHeaders( content=DummyContent2(self._epoch)
00585                                            , view_method='foo_view'
00586                                            , keywords={ 'bar' : 1 }
00587                                            , time=self._epoch
00588                                            )
00589         self.assertEqual( len( headers ), 3 )
00590         self.assertEqual( headers[0][0].lower() , 'last-modified' )
00591         self.assertEqual( headers[0][1]
00592                         , rfc1123_date(self._epoch.timeTime()) )
00593         self.assertEqual( headers[1][0].lower() , 'expires' )
00594         self.assertEqual( headers[1][1]
00595                         , rfc1123_date(self._epoch.timeTime()) )
00596         self.assertEqual( headers[2][0].lower() , 'cache-control' )
00597         self.assertEqual( headers[2][1], 'max-age=0' )

Here is the call graph for this function:

Definition at line 598 of file test_CachingPolicyManager.py.

00598 
00599     def test_lookupMatchBaz( self ):
00600 
00601         mgr = self._makeOneWithPolicies()
00602         headers = mgr.getHTTPCachingHeaders( content=DummyContent2(self._epoch)
00603                                            , view_method='foo_view'
00604                                            , keywords={ 'baz' : 1 }
00605                                            , time=self._epoch
00606                                            )
00607         self.assertEqual( len( headers ), 3 )
00608         self.assertEqual( headers[0][0].lower() , 'last-modified' )
00609         self.assertEqual( headers[0][1]
00610                         , rfc1123_date(self._epoch.timeTime()) )
00611         self.assertEqual( headers[1][0].lower() , 'expires' )
00612 
00613         exp_time = DateTime( headers[1][1] )
00614         target = self._epoch + ( 1.0 / 24.0 )
00615         self.assertEqualDelta( exp_time, target, 0.01 )
00616 
00617         self.assertEqual( headers[2][0].lower() , 'cache-control' )
00618         self.assertEqual( headers[2][1] , 'max-age=3600' )

Here is the call graph for this function:

Definition at line 567 of file test_CachingPolicyManager.py.

00567 
00568     def test_lookupMatchFoo( self ):
00569 
00570         mgr = self._makeOneWithPolicies()
00571         headers = mgr.getHTTPCachingHeaders( content=DummyContent2(self._epoch)
00572                                            , view_method='foo_view'
00573                                            , keywords={ 'foo' : 1 }
00574                                            , time=self._epoch
00575                                            )
00576         self.assertEqual( len( headers ), 1 )
00577         self.assertEqual( headers[0][0].lower(), 'last-modified' )
00578         self.assertEqual( headers[0][1]
00579                         , rfc1123_date(self._epoch.timeTime()) )

Here is the call graph for this function:

Definition at line 619 of file test_CachingPolicyManager.py.

00619 
00620     def test_lookupMatchQux( self ):
00621 
00622         mgr = self._makeOneWithPolicies()
00623         headers = mgr.getHTTPCachingHeaders( content=DummyContent2(self._epoch)
00624                                            , view_method='foo_view'
00625                                            , keywords={ 'qux' : 1 }
00626                                            , time=self._epoch
00627                                            )
00628         self.assertEqual( len( headers ), 3 )
00629         self.assertEqual( headers[0][0].lower() , 'last-modified' )
00630         self.assertEqual( headers[0][1]
00631                         , rfc1123_date(self._epoch.timeTime()) )
00632         self.assertEqual( headers[1][0].lower() , 'expires' )
00633 
00634         exp_time = DateTime( headers[1][1] )
00635         target = self._epoch + 1.0
00636         self.assertEqualDelta( exp_time, target, 0.01 )
00637 
00638         self.assertEqual( headers[2][0].lower() , 'cache-control' )
00639         self.assertEqual( headers[2][1] , 'max-age=86400' )
00640 

Here is the call graph for this function:

Definition at line 557 of file test_CachingPolicyManager.py.

00557 
00558     def test_lookupNoMatch( self ):
00559 
00560         mgr = self._makeOneWithPolicies()
00561         headers = mgr.getHTTPCachingHeaders( content=DummyContent2(self._epoch)
00562                                            , view_method='foo_view'
00563                                            , keywords={}
00564                                            , time=self._epoch
00565                                            )
00566         self.assertEqual( len( headers ), 0 )

Here is the call graph for this function:

Definition at line 521 of file test_CachingPolicyManager.py.

00521 
00522     def test_reorder( self ):
00523 
00524         mgr = self._makeOne()
00525 
00526         policy_ids = ( 'foo', 'bar', 'baz', 'qux' )
00527 
00528         for policy_id in policy_ids:
00529             mgr._addPolicy( policy_id
00530                           , 'python:"%s" in keywords.keys()' % policy_id
00531                           , None, 0, 0, 0, 0, '', '' )
00532 
00533         ids = tuple( map( lambda x: x[0], mgr.listPolicies() ) )
00534         self.assertEqual( ids, policy_ids )
00535 
00536         mgr._reorderPolicy( 'bar', 3 )
00537 
00538         ids = tuple( map( lambda x: x[0], mgr.listPolicies() ) )
00539         self.assertEqual( ids, ( 'foo', 'baz', 'qux', 'bar' ) )

Here is the call graph for this function:

Definition at line 441 of file test_CachingPolicyManager.py.

00441 
00442     def test_z2interfaces(self):
00443         from Interface.Verify import verifyClass
00444         from Products.CMFCore.CachingPolicyManager import CachingPolicyManager
00445         from Products.CMFCore.interfaces.CachingPolicyManager \
00446                 import CachingPolicyManager as ICachingPolicyManager
00447 
00448         verifyClass(ICachingPolicyManager, CachingPolicyManager)

Definition at line 449 of file test_CachingPolicyManager.py.

00449 
00450     def test_z3interfaces(self):
00451         from zope.interface.verify import verifyClass
00452         from Products.CMFCore.CachingPolicyManager import CachingPolicyManager
00453         from Products.CMFCore.interfaces import ICachingPolicyManager
00454 
00455         verifyClass(ICachingPolicyManager, CachingPolicyManager)


Member Data Documentation

Definition at line 436 of file test_CachingPolicyManager.py.

Definition at line 428 of file test_CachingPolicyManager.py.


The documentation for this class was generated from the following file: