[CMF-checkins] CVS: CMF/CMFCore/tests - test_ActionsTool.py:1.2.14.3
Chris Withers
chrisw@nipltd.com
Tue, 12 Feb 2002 06:55:22 -0500
Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv8217/tests
Modified Files:
Tag: ChrisW-tracker457-branch
test_ActionsTool.py
Log Message:
All tests passing.
=== CMF/CMFCore/tests/test_ActionsTool.py 1.2.14.2 => 1.2.14.3 ===
from Products.CMFDefault.RegistrationTool import RegistrationTool
from Products.CMFDefault.MembershipTool import MembershipTool
+from AccessControl import SecurityManager
+from AccessControl.SecurityManagement import newSecurityManager
import ZPublisher.HTTPRequest
from Testing.makerequest import makerequest
+from Acquisition import Implicit
+
+class UnitTestUser( Implicit ):
+ """
+ Stubbed out manager for unit testing purposes.
+ """
+ id = 'unit_tester'
+
+ def getId( self ):
+ return self.id
+
+ getUserName = getId
+
+ def allowed( self, object, object_roles=None ):
+ return 1
+
+class UnitTestSecurityPolicy:
+ """
+ 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) :
+ return 1
class ActionsToolTests( TestCase ):
def setUp( self ):
-
get_transaction().begin()
+ self._policy = UnitTestSecurityPolicy()
+ self._oldPolicy = SecurityManager.setSecurityPolicy(self._policy)
self.connection = Zope.DB.open()
- root = self.connection.root()[ 'Application' ]
+ self.root = root = self.connection.root()[ 'Application' ]
+ newSecurityManager( None, UnitTestUser().__of__( self.root ) )
+
root = self.root = makerequest(root)
root._setObject( 'portal_actions', ActionsTool() )
@@ -24,7 +65,9 @@
self.ut = root.foo
self.tool.action_providers = ('portal_actions',)
+
def tearDown(self):
+ SecurityManager.setSecurityPolicy( self._oldPolicy )
get_transaction().abort()
self.connection.close()
@@ -55,7 +98,17 @@
root._setObject('portal_membership', MembershipTool())
root._setObject('portal_types', TypesTool())
self.tool.action_providers = ('portal_actions','portal_registration')
- tool.listFilteredActionsFor(root.portal_registration)
+ self.assertEqual(tool.listFilteredActionsFor(root.portal_registration),
+ {'workflow': [],
+ 'user': [],
+ 'object': [{'permissions': ('List folder contents',),
+ 'id': 'folderContents',
+ 'url': ' http://foo/folder_contents',
+ 'name': 'Folder contents',
+ 'visible': 1,
+ 'category': 'object'}],
+ 'folder': [],
+ 'global': []})
def test_listDictionaryActions(self):
"""
@@ -67,8 +120,17 @@
root._setObject('donkey', PortalFolder('donkey'))
root._setObject('portal_membership', MembershipTool())
root._setObject('portal_types', TypesTool())
- print tool.listFilteredActionsFor(root.donkey)
-
+ self.assertEqual(tool.listFilteredActionsFor(root.donkey),
+ {'workflow': [],
+ 'user': [],
+ 'object': [],
+ 'folder': [{'permissions': ('List folder contents',),
+ 'id': 'folderContents',
+ 'url': ' http://foo/donkey/folder_contents',
+ 'name': 'Folder contents',
+ 'visible': 1,
+ 'category': 'folder'}],
+ 'global': []})
def test_suite():
return TestSuite((