[CMF-checkins] SVN: CMF/trunk/CMFCore/ - added ICachingPolicy
Yvo Schubbe
y.2005- at wcm-solutions.de
Fri Nov 11 04:06:06 EST 2005
Log message for revision 40047:
- added ICachingPolicy
- some cleanup
Changed:
U CMF/trunk/CMFCore/CachingPolicyManager.py
U CMF/trunk/CMFCore/ContentTypeRegistry.py
U CMF/trunk/CMFCore/interfaces/_tools.py
U CMF/trunk/CMFCore/tests/test_CachingPolicyManager.py
-=-
Modified: CMF/trunk/CMFCore/CachingPolicyManager.py
===================================================================
--- CMF/trunk/CMFCore/CachingPolicyManager.py 2005-11-11 08:24:47 UTC (rev 40046)
+++ CMF/trunk/CMFCore/CachingPolicyManager.py 2005-11-11 09:06:05 UTC (rev 40047)
@@ -29,6 +29,7 @@
from permissions import ManagePortal
from permissions import View
from Expression import Expression
+from interfaces import ICachingPolicy
from interfaces import ICachingPolicyManager
from interfaces.CachingPolicyManager \
import CachingPolicyManager as z2ICachingPolicyManager
@@ -153,6 +154,8 @@
"""
+ implements(ICachingPolicy)
+
def __init__( self
, policy_id
, predicate=''
@@ -430,15 +433,9 @@
security.declarePublic( 'listPolicies' )
def listPolicies( self ):
+ """List '(id, (policy, typeObjectName))' tuples for all policies.
"""
- Return a sequence of tuples,
- '( policy_id, ( policy, typeObjectName ) )'
- for all policies in the registry
- """
- result = []
- for policy_id in self._policy_ids:
- result.append( ( policy_id, self._policies[ policy_id ] ) )
- return tuple( result )
+ return tuple([ (id, self._policies[id]) for id in self._policy_ids ])
security.declareProtected( ManagePortal, 'addPolicy' )
def addPolicy( self
Modified: CMF/trunk/CMFCore/ContentTypeRegistry.py
===================================================================
--- CMF/trunk/CMFCore/ContentTypeRegistry.py 2005-11-11 08:24:47 UTC (rev 40046)
+++ CMF/trunk/CMFCore/ContentTypeRegistry.py 2005-11-11 09:06:05 UTC (rev 40047)
@@ -457,15 +457,10 @@
security.declarePublic( 'listPredicates' )
def listPredicates( self ):
+ """List '(id, (predicate, typeObjectName))' tuples for all predicates.
"""
- Return a sequence of tuples,
- '( id, ( predicate, typeObjectName ) )'
- for all predicates in the registry
- """
- result = []
- for predicate_id in self.predicate_ids:
- result.append( ( predicate_id, self.predicates[ predicate_id ] ) )
- return tuple( result )
+ return tuple([ (id, self.predicates[id])
+ for id in self.predicate_ids ])
security.declarePublic( 'getTypeObjectName' )
def getTypeObjectName( self, predicate_id ):
Modified: CMF/trunk/CMFCore/interfaces/_tools.py
===================================================================
--- CMF/trunk/CMFCore/interfaces/_tools.py 2005-11-11 08:24:47 UTC (rev 40046)
+++ CMF/trunk/CMFCore/interfaces/_tools.py 2005-11-11 09:06:05 UTC (rev 40047)
@@ -225,6 +225,92 @@
#
# Caching policy tool interfaces
#
+class ICachingPolicy(Interface):
+
+ def getPolicyId():
+ """
+ """
+
+ def getPredicate():
+ """
+ """
+
+ def getMTimeFunc():
+ """
+ """
+
+ def getMaxAgeSecs():
+ """
+ """
+
+ def getSMaxAgeSecs():
+ """
+ """
+
+ def getNoCache():
+ """
+ """
+
+ def getNoStore():
+ """
+ """
+
+ def getMustRevalidate():
+ """
+ """
+
+ def getProxyRevalidate():
+ """
+ """
+
+ def getPublic():
+ """
+ """
+
+ def getPrivate():
+ """
+ """
+
+ def getNoTransform():
+ """
+ """
+
+ def getVary():
+ """
+ """
+
+ def getETagFunc():
+ """
+ """
+
+ def getEnable304s():
+ """
+ """
+
+ def getLastModified():
+ """Should we set the last modified header?
+ """
+
+ def getPreCheck():
+ """
+ """
+
+ def getPostCheck():
+ """
+ """
+
+ def testPredicate(expr_context):
+ """Does this request match our predicate?
+ """
+
+ def getHeaders(expr_context):
+ """Does this request match our predicate?
+
+ If so, return a sequence of caching headers as (key, value) tuples.
+ Otherwise, return an empty sequence.
+ """
+
+
class ICachingPolicyManager(Interface):
""" Compute HTTP cache headers for skin methods.
Modified: CMF/trunk/CMFCore/tests/test_CachingPolicyManager.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_CachingPolicyManager.py 2005-11-11 08:24:47 UTC (rev 40046)
+++ CMF/trunk/CMFCore/tests/test_CachingPolicyManager.py 2005-11-11 09:06:05 UTC (rev 40047)
@@ -14,27 +14,25 @@
$Id$
"""
+
+import unittest
+import Testing
+
import base64
import os
-from unittest import TestCase, TestSuite, makeSuite, main
-import Testing
-import Zope2
-Zope2.startup()
-
+from AccessControl.SecurityManagement import newSecurityManager
from App.Common import rfc1123_date
from DateTime.DateTime import DateTime
-from AccessControl.SecurityManagement import newSecurityManager
+from Products.CMFCore.FSPageTemplate import FSPageTemplate
+from Products.CMFCore.tests.base.dummy import DummyContent
+from Products.CMFCore.tests.base.dummy import DummySite
+from Products.CMFCore.tests.base.dummy import DummyTool
+from Products.CMFCore.tests.base.dummy import DummyUserFolder
+from Products.CMFCore.tests.base.testcase import FSDVTest
from Products.CMFCore.tests.base.testcase import RequestTest
-from Products.CMFCore.tests.base.testcase import FSDVTest
from Products.CMFCore.tests.test_FSPageTemplate import FSPTMaker
-from Products.CMFCore.tests.base.dummy import DummySite
-from Products.CMFCore.tests.base.dummy import DummyUserFolder
-from Products.CMFCore.tests.base.dummy import DummyContent
-from Products.CMFCore.tests.base.dummy import DummyTool
-from Products.CMFCore.FSPageTemplate import FSPageTemplate
-from Products.CMFCore import CachingPolicyManager
ACCLARK = DateTime( '2001/01/01' )
@@ -55,7 +53,7 @@
return self.modified
-class CachingPolicyTests(TestCase):
+class CachingPolicyTests(unittest.TestCase):
def setUp(self):
self._epoch = DateTime(0)
@@ -70,6 +68,13 @@
return createCPContext( DummyContent2(self._epoch)
, 'foo_view', kw, self._epoch )
+ def test_z3interfaces(self):
+ from zope.interface.verify import verifyClass
+ from Products.CMFCore.CachingPolicyManager import CachingPolicy
+ from Products.CMFCore.interfaces import ICachingPolicy
+
+ verifyClass(ICachingPolicy, CachingPolicy)
+
def test_empty( self ):
policy = self._makePolicy( 'empty' )
context = self._makeContext()
@@ -381,7 +386,7 @@
self.assertEqual( headers[2][1] , 'no-cache, no-store' )
-class CachingPolicyManagerTests(TestCase):
+class CachingPolicyManagerTests(unittest.TestCase):
def _makeOne(self, *args, **kw):
from Products.CMFCore.CachingPolicyManager import CachingPolicyManager
@@ -422,15 +427,17 @@
)
self.assertEqual( len( headers ), 0 )
- self.assertRaises( KeyError, mgr._updatePolicy
- , 'xyzzy', None, None, None, None, None, None, '', '', None, None, None, None, None )
+ self.assertRaises( KeyError, mgr._updatePolicy,
+ 'xyzzy', None, None, None, None, None, None, '',
+ '', None, None, None, None, None )
self.assertRaises( KeyError, mgr._removePolicy, 'xyzzy' )
self.assertRaises( KeyError, mgr._reorderPolicy, 'xyzzy', -1 )
def test_addAndUpdatePolicy( self ):
mgr = self._makeOne()
- mgr.addPolicy( 'first', 'python:1', 'mtime', 1, 0, 1, 0, 'vary', 'etag', None, 2, 1, 0, 1, 0, 1, 0, 2, 3 )
+ mgr.addPolicy('first', 'python:1', 'mtime', 1, 0, 1, 0, 'vary',
+ 'etag', None, 2, 1, 0, 1, 0, 1, 0, 2, 3)
p = mgr._policies['first']
self.assertEqual(p.getPolicyId(), 'first')
self.assertEqual(p.getPredicate(), 'python:1')
@@ -451,7 +458,8 @@
self.assertEqual(p.getPreCheck(), 2)
self.assertEqual(p.getPostCheck(), 3)
- mgr.updatePolicy( 'first', 'python:0', 'mtime2', 2, 1, 0, 1, 'vary2', 'etag2', None, 1, 0, 1, 0, 1, 0, 1, 3, 2 )
+ mgr.updatePolicy('first', 'python:0', 'mtime2', 2, 1, 0, 1, 'vary2',
+ 'etag2', None, 1, 0, 1, 0, 1, 0, 1, 3, 2)
p = mgr._policies['first']
self.assertEqual(p.getPolicyId(), 'first')
self.assertEqual(p.getPredicate(), 'python:0')
@@ -595,6 +603,8 @@
class CachingPolicyManager304Tests(RequestTest, FSDVTest):
def setUp(self):
+ from Products.CMFCore import CachingPolicyManager
+
RequestTest.setUp(self)
FSDVTest.setUp(self)
@@ -668,12 +678,10 @@
etag_func = 'string:abc',
enable_304s = 0)
-
def tearDown(self):
RequestTest.tearDown(self)
FSDVTest.tearDown(self)
-
def _cleanup(self):
# Clean up request and response
req = self.portal.REQUEST
@@ -687,7 +695,6 @@
req.RESPONSE.setStatus(200)
-
def testUnconditionalGET(self):
# In this case the Request does not specify any if-modified-since
# value to take into account, thereby completely circumventing any
@@ -697,7 +704,6 @@
response = self.portal.REQUEST.RESPONSE
self.assertEqual(response.getStatus(), 200)
-
def testConditionalGETNoETag(self):
yesterday = DateTime() - 1
doc1 = self.portal.doc1
@@ -737,7 +743,6 @@
self.assertEqual(response.getStatus(), 200)
self._cleanup()
-
def testConditionalGETETag(self):
yesterday = DateTime() - 1
doc2 = self.portal.doc2
@@ -807,7 +812,6 @@
doc2()
self.assertEqual(response.getStatus(), 304)
self._cleanup()
-
def testConditionalGETDisabled(self):
yesterday = DateTime() - 1
@@ -835,12 +839,11 @@
def test_suite():
- return TestSuite((
- makeSuite(CachingPolicyTests),
- makeSuite(CachingPolicyManagerTests),
- makeSuite(CachingPolicyManager304Tests),
+ return unittest.TestSuite((
+ unittest.makeSuite(CachingPolicyTests),
+ unittest.makeSuite(CachingPolicyManagerTests),
+ unittest.makeSuite(CachingPolicyManager304Tests),
))
if __name__ == '__main__':
- main(defaultTest='test_suite')
-
+ unittest.main(defaultTest='test_suite')
More information about the CMF-checkins
mailing list