Back to index

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

List of all members.

Public Member Functions

def setUp
def tearDown
def test_subtemplate_cpm_1
def test_subtemplate_cpm_2
def test_subtemplate_cpm_3
def test_mixed_subtemplate_cpm
def test_fireForSubtemplates
def test_fireForSubtemplates2

Public Attributes

 portal

Static Public Attributes

 layer = TraversingZCMLLayer

Detailed Description

Definition at line 890 of file test_CachingPolicyManager.py.


Member Function Documentation

Definition at line 894 of file test_CachingPolicyManager.py.

00894 
00895     def setUp(self):
00896         FSObjMaker.setUp(self)
00897         RequestTest.setUp(self)
00898 
00899         # Create a fake portal and the tools we need
00900         self.portal = DummySite(id='portal').__of__(self.root)
00901         self.portal._setObject('portal_types', DummyTool())
00902 
00903         from Products.CMFCore import CachingPolicyManager
00904         CachingPolicyManager.manage_addCachingPolicyManager(self.portal)

Definition at line 905 of file test_CachingPolicyManager.py.

00905 
00906     def tearDown(self):
00907         RequestTest.tearDown(self)
00908         FSObjMaker.tearDown(self)

Definition at line 1063 of file test_CachingPolicyManager.py.

01063 
01064     def test_fireForSubtemplates(self):
01065         # This is a FSPageTemplate that will be used as the View for 
01066         # our content objects. It doesn't matter what it returns.
01067         dv = self._makeFSPageTemplate('dummy_view', 'testPT_CPM1.zpt')
01068         self.portal._setObject('dummy_view', dv)
01069 
01070         # These are the subtemplates we use
01071         sv1 = self._makeFSPageTemplate('subview_1', 'testPT_CPM2.zpt')
01072         sv2 = self._makeFSDTMLMethod('subview_2', 'testDTML_CPM3.dtml')
01073         self.portal._setObject('subview_1', sv1)
01074         self.portal._setObject( 'subview_2', sv2)
01075 
01076         for i in (1,2,3):
01077             id = 'doc%i' % i
01078             title = 'Document %i' % i
01079             description = 'This is document %i' % i
01080             modified_date = DateTime()
01081             doc = DummyContent(id)
01082             doc.title = title
01083             doc.description = description
01084             doc.modified_date = modified_date
01085             self.portal._setObject(id, doc)
01086 
01087         cpm = self.portal.caching_policy_manager
01088 
01089         # This policy only applies to doc2.
01090         cpm.addPolicy(policy_id = 'policy_doc2',
01091                       predicate = 'python:object.getId()=="doc2"',
01092                       mtime_func = '',
01093                       max_age_secs = 200,
01094                       no_cache = 0,
01095                       no_store = 0,
01096                       must_revalidate = 0,
01097                       vary = 'doc2',
01098                       etag_func = '',
01099                       pre_check=1
01100                       )
01101 
01102         # This policy only applies to doc3. 
01103         cpm.addPolicy(policy_id = 'policy_doc3',
01104                       predicate = 'python:object.getId()=="doc3"',
01105                       mtime_func = '',
01106                       max_age_secs = 300,
01107                       no_cache = 0,
01108                       no_store = 0,
01109                       must_revalidate = 0,
01110                       vary = 'doc3',
01111                       etag_func = '',
01112                       post_check=1
01113                       )
01114 
01115         # http://www.zope.org/Collectors/CMF/456
01116         # In cases where one view (ZPT or DTML) is rendered from another
01117         # view, we want to ensure only the view requested by the visitor
01118         # will get caching rules applied.
01119         self.portal.doc1.dummy_view()
01120 
01121         # no headers should be added by the CPM if all is well
01122         headers = [x.lower() for x in self.RESPONSE.headers.keys()]
01123         self.failIf('x-cache-headers-set-by' in headers)
01124         self.failIf('vary' in headers)

Here is the call graph for this function:

Definition at line 1125 of file test_CachingPolicyManager.py.

01125 
01126     def test_fireForSubtemplates2(self):
01127         # This is a FSPageTemplate that will be used as the View for 
01128         # our content objects. It doesn't matter what it returns.
01129         dv = self._makeFSPageTemplate('dummy_view', 'testPT_CPM1.zpt')
01130         self.portal._setObject('dummy_view', dv)
01131 
01132         # These are the subtemplates we use
01133         sv1 = self._makeFSPageTemplate('subview_1', 'testPT_CPM2.zpt')
01134         sv2 = self._makeFSDTMLMethod('subview_2', 'testDTML_CPM3.dtml')
01135         self.portal._setObject('subview_1', sv1)
01136         self.portal._setObject( 'subview_2', sv2)
01137 
01138         for i in (1,2,3):
01139             id = 'doc%i' % i
01140             title = 'Document %i' % i
01141             description = 'This is document %i' % i
01142             modified_date = DateTime()
01143             doc = DummyContent(id)
01144             doc.title = title
01145             doc.description = description
01146             doc.modified_date = modified_date
01147             self.portal._setObject(id, doc)
01148 
01149         cpm = self.portal.caching_policy_manager
01150 
01151         # This policy only applies to doc1.
01152         cpm.addPolicy(policy_id = 'policy_doc1',
01153                       predicate = 'python:object.getId()=="doc1"',
01154                       mtime_func = '',
01155                       max_age_secs = 100,
01156                       no_cache = 0,
01157                       no_store = 0,
01158                       must_revalidate = 0,
01159                       vary = 'doc1',
01160                       etag_func = '',
01161                       s_max_age_secs=100
01162                       )
01163 
01164         # This policy only applies to doc2.
01165         cpm.addPolicy(policy_id = 'policy_doc2',
01166                       predicate = 'python:object.getId()=="doc2"',
01167                       mtime_func = '',
01168                       max_age_secs = 200,
01169                       no_cache = 0,
01170                       no_store = 0,
01171                       must_revalidate = 0,
01172                       vary = 'doc2',
01173                       etag_func = '',
01174                       pre_check=1
01175                       )
01176 
01177         # This policy only applies to doc3. 
01178         cpm.addPolicy(policy_id = 'policy_doc3',
01179                       predicate = 'python:object.getId()=="doc3"',
01180                       mtime_func = '',
01181                       max_age_secs = 300,
01182                       no_cache = 0,
01183                       no_store = 0,
01184                       must_revalidate = 0,
01185                       vary = 'doc3',
01186                       etag_func = '',
01187                       post_check=1
01188                       )
01189 
01190         # http://www.zope.org/Collectors/CMF/456
01191         # In cases where one view (ZPT or DTML) is rendered from another
01192         # view, we want to ensure only the view requested by the visitor
01193         # will get caching rules applied.
01194         self.portal.doc1.dummy_view()
01195 
01196         # We want to make sure the correct policy (policy_doc1) has fired
01197         # Just to be sure, change headers so they are definitely all 
01198         # lower-cased
01199         headers = {}
01200         header_info = self.RESPONSE.headers.items()
01201         [headers.__setitem__(x[0].lower(), x[1]) for x in header_info]
01202 
01203         self.failUnless(headers.get('x-cache-headers-set-by'))
01204         self.assertEquals(headers.get('vary'), 'doc1')
01205         self.assertEquals( headers.get('cache-control')
01206                          , 'max-age=100, s-maxage=100'
01207                          )
01208 

Here is the call graph for this function:

Definition at line 1024 of file test_CachingPolicyManager.py.

01024 
01025     def test_mixed_subtemplate_cpm( self ):
01026         # test a mix of zpt and dtml templates
01027         # set up site
01028         now = DateTime()
01029         portal = self.portal
01030         cpm = portal.caching_policy_manager
01031         cpm.addPolicy(policy_id = 'policy_nv1',
01032                       predicate = 'python:view=="nested_view_1"',
01033                       mtime_func = '',
01034                       max_age_secs = 100,
01035                       no_cache = 0,
01036                       no_store = 0,
01037                       must_revalidate = 0,
01038                       vary = 'doc1',
01039                       etag_func = '',
01040                       s_max_age_secs=100
01041                       )
01042 
01043         doc1 = DummyContent(id='doc1', view_id='nested_view', modified_date=now)
01044         portal._setObject('doc1', doc1)
01045         doc2 = DummyContent(id='doc2', view_id='nested_view_1', modified_date=now)
01046         portal._setObject('doc2', doc2)
01047         doc3 = DummyContent(id='doc3', view_id='nested_view_2', modified_date=now)
01048         portal._setObject('doc3', doc3)
01049 
01050         nested_view = self._makeFSPageTemplate('nested_view', 'nested_view.zpt')
01051         nested_view_1 = self._makeFSPageTemplate('nested_view_1', 'nested_view_1.zpt')
01052         nested_view_2 = self._makeFSDTMLMethod('nested_view_2', 'nested_view_2.dtml')
01053         portal._setObject('nested_view', nested_view)
01054         portal._setObject('nested_view_1', nested_view_1)
01055         portal._setObject('nested_view_2', nested_view_2)
01056 
01057         portal.doc1()
01058 
01059         # no headers should be added by the CPM if all is well
01060         headers = [x.lower() for x in self.RESPONSE.headers.keys()]
01061         self.failIf('x-cache-headers-set-by' in headers)
01062         self.failIf('vary' in headers)

Here is the call graph for this function:

Definition at line 909 of file test_CachingPolicyManager.py.

00909 
00910     def test_subtemplate_cpm_1( self ):
00911         # test that subtemplates dont call the cpm
00912         # set up site
00913         portal = self.portal
00914         now = DateTime()
00915         cpm = portal.caching_policy_manager
00916         cpm.addPolicy(policy_id = 'policy_op2',
00917                       predicate = 'python:view=="output_page_2"',
00918                       mtime_func = '',
00919                       max_age_secs = 100,
00920                       no_cache = 0,
00921                       no_store = 0,
00922                       must_revalidate = 0,
00923                       vary = 'doc1',
00924                       etag_func = '',
00925                       s_max_age_secs=100
00926                       )
00927 
00928         content = DummyContent(id='content', view_id='output_page_1')
00929         content.modified_date = now
00930         portal._setObject('content', content)
00931 
00932         output_page_1 = self._makeFSPageTemplate('output_page_1', 'output_page_1.zpt')
00933         output_page_2 = self._makeFSPageTemplate('output_page_2', 'output_page_2.zpt')
00934         portal._setObject('output_page_1', output_page_1)
00935         portal._setObject('output_page_2', output_page_2)
00936 
00937         portal.content()
00938 
00939         # no headers should be added by the CPM if all is well
00940         headers = [x.lower() for x in self.RESPONSE.headers.keys()]
00941         self.failIf('x-cache-headers-set-by' in headers)
00942         self.failIf('vary' in headers)

Here is the call graph for this function:

Definition at line 943 of file test_CachingPolicyManager.py.

00943 
00944     def test_subtemplate_cpm_2( self ):
00945         # test that calling content from a template doesnt call the cpm
00946         # just calling an FSDTMLMethod directly from another template does
00947         # not activate the bug because RESPONSE is not passed in
00948         portal = self.portal
00949         now = DateTime()
00950         cpm = portal.caching_policy_manager
00951         cpm.addPolicy(policy_id = 'policy_op4',
00952                       predicate = 'python:view=="output_page_4"',
00953                       mtime_func = '',
00954                       max_age_secs = 100,
00955                       no_cache = 0,
00956                       no_store = 0,
00957                       must_revalidate = 0,
00958                       vary = 'doc1',
00959                       etag_func = '',
00960                       s_max_age_secs=100
00961                       )
00962 
00963         content = DummyContent(id='content', view_id='output_page_3')
00964         content.modified_date = now
00965         portal._setObject('content', content)
00966         content2 = DummyContent(id='content2', view_id='output_page_4')
00967         content2.modified_date = now
00968         portal._setObject('content2', content2)
00969 
00970         output_page_3 = self._makeFSDTMLMethod('output_page_3', 'output_page_3.dtml')
00971         output_page_4 = self._makeFSDTMLMethod('output_page_4', 'output_page_4.dtml')
00972         portal._setObject('output_page_4',output_page_4)
00973         portal._setObject('output_page_3',output_page_3)
00974 
00975         # call the content
00976         portal.content()
00977 
00978         # no headers should be added by the CPM if all is well
00979         headers = [x.lower() for x in self.RESPONSE.headers.keys()]
00980         self.failIf('x-cache-headers-set-by' in headers)
00981         self.failIf('vary' in headers)

Here is the call graph for this function:

Definition at line 982 of file test_CachingPolicyManager.py.

00982 
00983     def test_subtemplate_cpm_3( self ):
00984         # test a bigger mix of zpt templates
00985         # set up site
00986         portal = self.portal
00987         now = DateTime()
00988         cpm = portal.caching_policy_manager
00989         cpm.addPolicy(policy_id = 'policy_nv1',
00990                       predicate = 'python:view=="nested_view_1"',
00991                       mtime_func = '',
00992                       max_age_secs = 100,
00993                       no_cache = 0,
00994                       no_store = 0,
00995                       must_revalidate = 0,
00996                       vary = 'doc1',
00997                       etag_func = '',
00998                       s_max_age_secs=100
00999                       )
01000 
01001         doc1 = DummyContent(id='doc1', view_id='nested_view')
01002         doc1.modified_date = now
01003         portal._setObject('doc1',doc1)
01004         doc2 = DummyContent(id='doc2', view_id='nested_view_1')
01005         doc2.modified_date = now
01006         portal._setObject('doc2',doc2)
01007         doc3 = DummyContent(id='doc3', view_id='nested_view_2')
01008         doc3.modified_date = now
01009         portal._setObject('doc3',doc3)
01010 
01011         nested_view = self._makeFSPageTemplate('nested_view', 'nested_view.zpt')
01012         nested_view_1 = self._makeFSPageTemplate('nested_view_1', 'nested_view_1.zpt')
01013         nested_view_2 = self._makeFSPageTemplate('nested_view_2', 'nested_view_2.zpt')
01014         portal._setObject('nested_view', nested_view)
01015         portal._setObject('nested_view_1', nested_view_1)
01016         portal._setObject('nested_view_2', nested_view_2)
01017 
01018         data = portal.doc1()
01019 
01020         # no headers should be added by the CPM if all is well
01021         headers = [x.lower() for x in self.RESPONSE.headers.keys()]
01022         self.failIf('x-cache-headers-set-by' in headers)
01023         self.failIf('vary' in headers)

Here is the call graph for this function:


Member Data Documentation

Definition at line 892 of file test_CachingPolicyManager.py.

Definition at line 899 of file test_CachingPolicyManager.py.


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