Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
CMFCore.tests.test_CachingPolicyManager.OFSCacheTests Class Reference
Inheritance diagram for CMFCore.tests.test_CachingPolicyManager.OFSCacheTests:
Inheritance graph
[legend]
Collaboration diagram for CMFCore.tests.test_CachingPolicyManager.OFSCacheTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def setUp
def test_empty
def test_no_association
def test_unsuitable_association
def test_suitable_association
def test_with_view

Public Attributes

 portal

Static Public Attributes

 layer = FunctionalZCMLLayer

Detailed Description

Definition at line 1209 of file test_CachingPolicyManager.py.


Member Function Documentation

Definition at line 1213 of file test_CachingPolicyManager.py.

01213 
01214     def setUp(self):
01215         from Products.CMFCore import CachingPolicyManager
01216 
01217         RequestTest.setUp(self)
01218 
01219         # Create a fake portal and the tools we need
01220         self.portal = DummySite(id='portal').__of__(self.root)
01221         self.portal._setObject('doc1', CacheableDummyContent('doc1'))
01222         self.portal._setObject('doc2', CacheableDummyContent('doc2'))
01223         CachingPolicyManager.manage_addCachingPolicyManager(self.portal)
01224         cpm = self.portal.caching_policy_manager
01225 
01226         # This policy only applies to doc1. It will not emit any ETag header
01227         # but it enables If-modified-since handling.
01228         cpm.addPolicy(policy_id = 'policy_1',
01229                       predicate = 'python:object.getId()=="doc1"',
01230                       mtime_func = '',
01231                       max_age_secs = 100,
01232                       no_cache = 0,
01233                       no_store = 0,
01234                       must_revalidate = 0,
01235                       vary = 'doc1',
01236                       etag_func = '',
01237                       enable_304s = 0)

Definition at line 1238 of file test_CachingPolicyManager.py.

01238 
01239     def test_empty(self):
01240 
01241         from Products.CMFCore.CachingPolicyManager import CPMCache
01242 
01243         cpm = self.portal.caching_policy_manager
01244         doc1 = self.portal.doc1
01245         self.failUnless(cpm._isCacheManager)
01246         self.failUnless(isinstance(cpm.ZCacheManager_getCache(), CPMCache))
01247         self.assertEquals( doc1.ZCacheable_getManagerIds()
01248                          , ({'id':cpm.getId(), 'title':''},)
01249                          )

Definition at line 1250 of file test_CachingPolicyManager.py.

01250 
01251     def test_no_association(self):
01252         # Render an item that would match the CPM policy, but don't 
01253         # associate it with the CPM.
01254         self.portal.doc1()
01255 
01256         # no headers should be added by the CPM if all is well
01257         headers = [x.lower() for x in self.RESPONSE.headers.keys()]
01258         self.failIf('x-cache-headers-set-by' in headers)
01259         self.failIf('vary' in headers)

Definition at line 1274 of file test_CachingPolicyManager.py.

01274 
01275     def test_suitable_association(self):
01276         # Render a content item that will trigger the CPM
01277         cpm = self.portal.caching_policy_manager
01278         doc1 = self.portal.doc1
01279         doc1.ZCacheable_setManagerId(cpm.getId())
01280 
01281         doc1()
01282 
01283         # Policy "policy_1" should have triggered
01284         # Just to be sure, change headers so they are definitely all 
01285         # lower-cased
01286         headers = {}
01287         header_info = self.RESPONSE.headers.items()
01288         [headers.__setitem__(x[0].lower(), x[1]) for x in header_info]
01289 
01290         self.failUnless(headers.get('x-cache-headers-set-by'))
01291         self.assertEquals(headers.get('vary'), 'doc1')
01292         self.assertEquals( headers.get('cache-control')
01293                          , 'max-age=100'
01294                          )

Definition at line 1260 of file test_CachingPolicyManager.py.

01260 
01261     def test_unsuitable_association(self):
01262         # Render an item that is associated with the CPM, but that does not
01263         # match any policy.
01264         cpm = self.portal.caching_policy_manager
01265         doc2 = self.portal.doc2
01266         doc2.ZCacheable_setManagerId(cpm.getId())
01267 
01268         doc2()
01269 
01270         # no headers should be added by the CPM if all is well
01271         headers = [x.lower() for x in self.RESPONSE.headers.keys()]
01272         self.failIf('x-cache-headers-set-by' in headers)
01273         self.failIf('vary' in headers)

Definition at line 1295 of file test_CachingPolicyManager.py.

01295 
01296     def test_with_view(self):
01297         # Render a view for a content item that will trigger the CPM
01298         cpm = self.portal.caching_policy_manager
01299         self.portal._setObject('a_view', DummyView(id='a_view'))
01300         self.portal.a_view.ZCacheable_setManagerId(cpm.getId())
01301         doc1 = self.portal.doc1
01302 
01303         doc1.a_view()
01304 
01305         # Policy "policy_1" should have triggered
01306         # Just to be sure, change headers so they are definitely all 
01307         # lower-cased
01308         headers = {}
01309         header_info = self.RESPONSE.headers.items()
01310         [headers.__setitem__(x[0].lower(), x[1]) for x in header_info]
01311 
01312         self.failUnless(headers.get('x-cache-headers-set-by'))
01313         self.assertEquals(headers.get('vary'), 'doc1')
01314         self.assertEquals( headers.get('cache-control')
01315                          , 'max-age=100'
01316                          )
01317 


Member Data Documentation

Definition at line 1211 of file test_CachingPolicyManager.py.

Definition at line 1219 of file test_CachingPolicyManager.py.


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