[CMF-checkins] CVS: CMF/CMFCore/tests - test_Expression.py:1.2.14.1 test_TypesTool.py:1.12.2.7
Chris Withers
chrisw@nipltd.com
Fri, 15 Feb 2002 10:41:50 -0500
Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv14406/tests
Modified Files:
Tag: ChrisW-refactor_tests-branch
test_Expression.py test_TypesTool.py
Log Message:
Done Expression
=== CMF/CMFCore/tests/test_Expression.py 1.2 => 1.2.14.1 ===
-from AccessControl.SecurityManagement import newSecurityManager
-from AccessControl.SecurityManagement import noSecurityManager
-from AccessControl import SecurityManager
-from Products.CMFCore.ActionsTool import *
-from Products.CMFCore.ActionInformation import ActionInformation
-from Products.CMFCore.PortalContent import PortalContent
-from Products.CMFCore.Expression import Expression, createExprContext
-import ZPublisher.HTTPRequest
+import Zope
+from unittest import TestSuite, makeSuite, main
+
+from Products.CMFCore.tests.base.testcase import \
+ SecurityTest
-class PermissiveSecurityPolicy:
- """
- Stub out the existing security policy for unit testing purposes.
- """
- #
- # Standard SecurityPolicy interface
- #
- def validate( self
- , accessed=None
- , container=None
- , name=None
- , value=None
- , context=None
- , roles=None
- , *args
- , **kw):
- return 1
-
- def checkPermission( self, permission, object, context) :
- if permission == 'forbidden permission':
- return 0
- return 1
-
-class UnitTestUser( Acquisition.Implicit ):
- """
- Stubbed out manager for unit testing purposes.
- """
- def getId( self ):
- return 'unit_tester'
-
- getUserName = getId
-
- def allowed( self, object, object_roles=None ):
- # for testing permissions on actions
- if object.getId() == 'actions_dummy':
- if 'Anonymous' in object_roles:
- return 1
- else:
- return 0
- return 1
-
-class DummyMembershipTool:
- def __init__(self, anon=1):
- self.anon = anon
-
- def isAnonymousUser(self):
- return self.anon
-
- def getAuthenticatedMember(self):
- return "member"
-
-class DummyContent(PortalContent, OFS.SimpleItem.Item):
- """
- """
- meta_type = 'Dummy'
- url = 'foo_url'
-
- def __init__(self, id, url=None):
- self.id = id
- self.url = url
+from Products.CMFCore.tests.base.dummy import \
+ DummyContent, DummyMembershipTool
- def absolute_url(self):
- return self.url
+from Products.CMFCore.ActionInformation import ActionInformation
+from Products.CMFCore.Expression import Expression, createExprContext
-class ExpressionTests( unittest.TestCase ):
+class ExpressionTests( SecurityTest ):
def setUp( self ):
- get_transaction().begin()
- self._policy = PermissiveSecurityPolicy()
- self._oldPolicy = SecurityManager.setSecurityPolicy(self._policy)
- self.connection = Zope.DB.open()
- root = self.root = self.connection.root()[ 'Application' ]
- newSecurityManager(None, UnitTestUser().__of__( self.root ))
- root._setObject('portal', DummyContent('portal', 'url_portal'))
- portal = self.portal = self.root.portal
- self.folder = DummyContent('foo', 'url_foo')
- self.object = DummyContent('bar', 'url_bar')
+
+ SecurityTest.setUp(self)
+ root = self.root
+ root._setObject('portal', DummyContent('portal', url='url_portal'))
+ portal = self.portal = root.portal
+ self.folder = DummyContent('foo', url='url_foo')
+ self.object = DummyContent('bar', url='url_bar')
self.ai = ActionInformation(id='view'
, title='View'
, action=Expression(
@@ -123,21 +58,10 @@
self.assertEqual(folder.id, 'foo')
self.assertEqual(folder.absolute_url(), 'url_foo')
-
-
- def tearDown( self ):
- get_transaction().abort()
- self.connection.close()
- noSecurityManager()
- SecurityManager.setSecurityPolicy(self._oldPolicy)
-
def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(ExpressionTests))
- return suite
-
-def run():
- unittest.TextTestRunner().run(test_suite())
+ return TestSuite((
+ makeSuite(ExpressionTests),
+ ))
if __name__ == '__main__':
- run()
+ main(defaultTest='test_suite')
=== CMF/CMFCore/tests/test_TypesTool.py 1.12.2.6 => 1.12.2.7 ===
-import OFS.Folder
from unittest import TestCase, TestSuite, makeSuite, main
from Products.CMFCore.TypesTool import\
@@ -15,7 +14,7 @@
from Products.CMFCore.tests.base.security import \
OmnipotentUser, UserWithRoles
from Products.CMFCore.tests.base.dummy import \
- DummyMethod, DummyContent, addDummy, DummyTypeInfo,\
+ DummyMethod, addDummy, DummyTypeInfo,\
DummyFolder, DummyFTI
from AccessControl.SecurityManagement import newSecurityManager