Back to index

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

List of all members.

Public Member Functions

def setUp
def tearDown
def testUnconditionalGET
def testConditionalGETNoETag
def testConditionalGETETag
def testConditionalGETDisabled

Public Attributes

 portal
 auth_header

Static Public Attributes

 layer = FunctionalZCMLLayer

Private Member Functions

def _cleanup

Detailed Description

Definition at line 641 of file test_CachingPolicyManager.py.


Member Function Documentation

Definition at line 725 of file test_CachingPolicyManager.py.

00725 
00726     def _cleanup(self):
00727         # Clean up request and response
00728         req = self.portal.REQUEST
00729 
00730         for header in ( 'IF_MODIFIED_SINCE'
00731                       , 'HTTP_AUTHORIZATION'
00732                       , 'IF_NONE_MATCH'
00733                       ):
00734             if req.environ.get(header, None) is not None:
00735                 del req.environ[header]
00736 
00737         req.RESPONSE.setStatus(200)

Here is the caller graph for this function:

Definition at line 645 of file test_CachingPolicyManager.py.

00645 
00646     def setUp(self):
00647         from Products.CMFCore import CachingPolicyManager
00648 
00649         RequestTest.setUp(self)
00650         FSDVTest.setUp(self)
00651 
00652         now = DateTime()
00653 
00654         # Create a fake portal and the tools we need
00655         self.portal = DummySite(id='portal').__of__(self.root)
00656         self.portal._setObject('portal_types', DummyTool())
00657 
00658         # This is a FSPageTemplate that will be used as the View for
00659         # our content objects. It doesn't matter what it returns.
00660         path = os.path.join(self.skin_path_name, 'testPT2.pt')
00661         self.portal._setObject('dummy_view', FSPageTemplate('dummy_view', path))
00662 
00663         uf = self.root.acl_users
00664         password = 'secret'
00665         uf.userFolderAddUser(portal_owner, password, ['Manager'], [])
00666         user = uf.getUserById(portal_owner)
00667         if not hasattr(user, 'aq_base'):
00668             user = user.__of__(uf)
00669         newSecurityManager(None, user)
00670         owner_auth = '%s:%s' % (portal_owner, password)
00671         self.auth_header = "Basic %s" % base64.encodestring(owner_auth)
00672 
00673         self.portal._setObject('doc1', DummyContent('doc1'))
00674         self.portal._setObject('doc2', DummyContent('doc2'))
00675         self.portal._setObject('doc3', DummyContent('doc3'))
00676         self.portal.doc1.modified_date = now
00677         self.portal.doc2.modified_date = now
00678         self.portal.doc3.modified_date = now
00679 
00680         CachingPolicyManager.manage_addCachingPolicyManager(self.portal)
00681         cpm = self.portal.caching_policy_manager
00682 
00683         # This policy only applies to doc1. It will not emit any ETag header
00684         # but it enables If-modified-since handling.
00685         cpm.addPolicy(policy_id = 'policy_no_etag',
00686                       predicate = 'python:object.getId()=="doc1"',
00687                       mtime_func = '',
00688                       max_age_secs = 0,
00689                       no_cache = 0,
00690                       no_store = 0,
00691                       must_revalidate = 0,
00692                       vary = '',
00693                       etag_func = '',
00694                       enable_304s = 1)
00695 
00696         # This policy only applies to doc2. It will emit an ETag with
00697         # the constant value "abc" and also enable if-modified-since handling.
00698         cpm.addPolicy(policy_id = 'policy_etag',
00699                       predicate = 'python:object.getId()=="doc2"',
00700                       mtime_func = '',
00701                       max_age_secs = 0,
00702                       no_cache = 0,
00703                       no_store = 0,
00704                       must_revalidate = 0,
00705                       vary = '',
00706                       etag_func = 'string:abc',
00707                       enable_304s = 1)
00708 
00709         # This policy only applies to doc3. Etags with constant values of
00710         # "abc" are emitted, but if-modified-since handling is turned off.
00711         cpm.addPolicy(policy_id = 'policy_disabled',
00712                       predicate = 'python:object.getId()=="doc3"',
00713                       mtime_func = '',
00714                       max_age_secs = 0,
00715                       no_cache = 0,
00716                       no_store = 0,
00717                       must_revalidate = 0,
00718                       vary = '',
00719                       etag_func = 'string:abc',
00720                       enable_304s = 0)

Definition at line 721 of file test_CachingPolicyManager.py.

00721 
00722     def tearDown(self):
00723         RequestTest.tearDown(self)
00724         FSDVTest.tearDown(self)

Definition at line 856 of file test_CachingPolicyManager.py.

00856 
00857     def testConditionalGETDisabled(self):
00858         yesterday = DateTime() - 1
00859         doc3 = self.portal.doc3
00860         request = doc3.REQUEST
00861         response = request.RESPONSE
00862 
00863         # Our policy disables any 304-handling, so even though the ETag matches
00864         # the policy, we will get the full rendering.
00865         request.environ['IF_NONE_MATCH'] = '"abc"'
00866         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00867         doc3()
00868         self.assertEqual(response.getStatus(), 200)
00869         self._cleanup()
00870 
00871         # Now both the ETag and the modified condition would trigger a 304
00872         # response *if* 304-handling was enabled. It is not in our policy, so
00873         # we get the full rendering again.
00874         request.environ['IF_MODIFIED_SINCE'] = rfc1123_date(doc3.modified_date)
00875         request.environ['IF_NONE_MATCH'] = '"abc"'
00876         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00877         doc3()
00878         self.assertEqual(response.getStatus(), 200)
00879         self._cleanup()

Here is the call graph for this function:

Definition at line 786 of file test_CachingPolicyManager.py.

00786 
00787     def testConditionalGETETag(self):
00788         yesterday = DateTime() - 1
00789         doc2 = self.portal.doc2
00790         request = doc2.REQUEST
00791         response = request.RESPONSE
00792 
00793         # Has doc2 been modified since yesterday? Yes it has, so we get the
00794         # full rendering.
00795         request.environ['IF_MODIFIED_SINCE'] = rfc1123_date(yesterday)
00796         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00797         doc2()
00798         self.assertEqual(response.getStatus(), 200)
00799         self._cleanup()
00800 
00801         # If doc2 has not been modified since its creation (which it hasn't),
00802         # we would get a 304 here. However, the policy for doc2 also expects
00803         # to get an ETag in the request, which we are not setting here. So
00804         # the policy fails and we get a full rendering.
00805         request.environ['IF_MODIFIED_SINCE'] = rfc1123_date(doc2.modified_date)
00806         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00807         doc2()
00808         self.assertEqual(response.getStatus(), 200)
00809         self._cleanup()
00810 
00811         # Now we are setting an ETag in our request, but an ETag that does not
00812         # match the policy's expected value. The policy fails and we get the
00813         # full rendering.
00814         request.environ['IF_NONE_MATCH'] = '"123"'
00815         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00816         doc2()
00817         self.assertEqual(response.getStatus(), 200)
00818         self._cleanup()
00819 
00820         # Here we provide the correct and matching ETag value, and we don't
00821         # specify any if-modified-since condition. This is enough for our
00822         # policy to trigger 304.
00823         request.environ['IF_NONE_MATCH'] = '"abc"'
00824         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00825         doc2()
00826         self.assertEqual(response.getStatus(), 304)
00827         self._cleanup()
00828 
00829         # We specify an ETag and a modification time condition that dooes not
00830         # match, so we get the full rendering
00831         request.environ['IF_MODIFIED_SINCE'] = rfc1123_date(doc2.modified_date)
00832         request.environ['IF_NONE_MATCH'] = '"123"'
00833         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00834         doc2()
00835         self.assertEqual(response.getStatus(), 200)
00836         self._cleanup()
00837 
00838         # We hand in a matching modified time condition which is supposed to
00839         # trigger full rendering. This will lead the ETag condition to be
00840         # overrridden.
00841         request.environ['IF_MODIFIED_SINCE'] = rfc1123_date(yesterday)
00842         request.environ['IF_NONE_MATCH'] = '"abc"'
00843         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00844         doc2()
00845         self.assertEqual(response.getStatus(), 200)
00846         self._cleanup()
00847 
00848         # Now we pass an ETag that matches the policy and a modified time
00849         # condition that is not fulfilled. It is safe to serve a 304.
00850         request.environ['IF_MODIFIED_SINCE'] = rfc1123_date(doc2.modified_date)
00851         request.environ['IF_NONE_MATCH'] = '"abc"'
00852         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00853         doc2()
00854         self.assertEqual(response.getStatus(), 304)
00855         self._cleanup()

Here is the call graph for this function:

Definition at line 747 of file test_CachingPolicyManager.py.

00747 
00748     def testConditionalGETNoETag(self):
00749         yesterday = DateTime() - 1
00750         doc1 = self.portal.doc1
00751         request = doc1.REQUEST
00752         response = request.RESPONSE
00753 
00754         # If doc1 has beeen modified since yesterday (which it has), we want
00755         # the full rendering.
00756         request.environ['IF_MODIFIED_SINCE'] = rfc1123_date(yesterday)
00757         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00758         doc1()
00759         self.assertEqual(response.getStatus(), 200)
00760         self._cleanup()
00761 
00762         # If doc1 has been modified since its creation (which it hasn't), we
00763         # want the full rendering. This must return a 304 response.
00764         request.environ['IF_MODIFIED_SINCE'] = rfc1123_date(doc1.modified_date)
00765         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00766         doc1()
00767         self.assertEqual(response.getStatus(), 304)
00768         self._cleanup()
00769 
00770         # ETag handling is not enabled in the policy for doc1, so asking for
00771         # one will not produce any matches. We get the full rendering.
00772         request.environ['IF_NONE_MATCH'] = '"123"'
00773         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00774         doc1()
00775         self.assertEqual(response.getStatus(), 200)
00776         self._cleanup()
00777 
00778         # We are asking for an ETag as well as modifications after doc2 has
00779         # been created. Both won't match and wwe get the full rendering.
00780         request.environ['IF_NONE_MATCH'] = '"123"'
00781         request.environ['IF_MODIFIED_SINCE'] = rfc1123_date(doc1.modified_date)
00782         request.environ['HTTP_AUTHORIZATION'] = self.auth_header
00783         doc1()
00784         self.assertEqual(response.getStatus(), 200)
00785         self._cleanup()

Here is the call graph for this function:

Definition at line 738 of file test_CachingPolicyManager.py.

00738 
00739     def testUnconditionalGET(self):
00740         # In this case the Request does not specify any if-modified-since
00741         # value to take into account, thereby completely circumventing any
00742         # if-modified-since handling. This must not produce a response status
00743         # of 304, regardless of any other headers.
00744         self.portal.doc1()
00745         response = self.portal.REQUEST.RESPONSE
00746         self.assertEqual(response.getStatus(), 200)


Member Data Documentation

Definition at line 670 of file test_CachingPolicyManager.py.

Definition at line 643 of file test_CachingPolicyManager.py.

Definition at line 654 of file test_CachingPolicyManager.py.


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