[CMF-checkins] CVS: CMF/CMFCore/tests - test_ActionsTool.py:1.3
Chris Withers
chrisw@nipltd.com
Tue, 12 Feb 2002 07:26:26 -0500
Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv15646/CMFCore/tests
Modified Files:
test_ActionsTool.py
Log Message:
Fix for Tracker #457
=== CMF/CMFCore/tests/test_ActionsTool.py 1.2 => 1.3 ===
-from Products.CMFCore.ActionsTool import *
-from Products.CMFDefault.URLTool import *
+import Zope
+from unittest import TestCase,TestSuite,makeSuite,main
+from Products.CMFCore.ActionsTool import ActionsTool
+from Products.CMFCore.TypesTool import TypesTool
+from Products.CMFCore.PortalFolder import PortalFolder
+from Products.CMFDefault.URLTool import URLTool
+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 ActionsToolTests( unittest.TestCase ):
+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.root = self.connection.root()[ 'Application' ]
-
- env = { 'SERVER_NAME' : 'http://localhost'
- , 'SERVER_PORT' : '80'
- }
- root.REQUEST = ZPublisher.HTTPRequest.HTTPRequest( None, env, None )
+ self.root = root = self.connection.root()[ 'Application' ]
+ newSecurityManager( None, UnitTestUser().__of__( self.root ) )
+
+ root = self.root = makerequest(root)
root._setObject( 'portal_actions', ActionsTool() )
root._setObject('foo', URLTool() )
@@ -21,6 +65,12 @@
self.ut = root.foo
self.tool.action_providers = ('portal_actions',)
+
+ def tearDown(self):
+ SecurityManager.setSecurityPolicy( self._oldPolicy )
+ get_transaction().abort()
+ self.connection.close()
+
def test_actionProviders(self):
tool = self.tool
self.assertEqual(tool.listActionProviders(), ('portal_actions',))
@@ -37,17 +87,58 @@
self.assertEqual(tool.listActionProviders(),
('portal_actions',))
- def tearDown( self ):
- get_transaction().abort()
- self.connection.close()
+ def test_listActionInformationActions(self):
+ """
+ Check that listFilteredActionsFor works for objects
+ that return ActionInformation objects
+ """
+ root = self.root
+ tool = self.tool
+ root._setObject('portal_registration', RegistrationTool())
+ root._setObject('portal_membership', MembershipTool())
+ root._setObject('portal_types', TypesTool())
+ self.tool.action_providers = ('portal_actions','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):
+ """
+ Check that listFilteredActionsFor works for objects
+ that return dictionaries
+ """
+ root = self.root
+ tool = self.tool
+ root._setObject('donkey', PortalFolder('donkey'))
+ root._setObject('portal_membership', MembershipTool())
+ root._setObject('portal_types', TypesTool())
+ 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():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(ActionsToolTests))
- return suite
+ return TestSuite((
+ makeSuite(ActionsToolTests),
+ ))
def run():
- unittest.TextTestRunner().run(test_suite())
+ main(defaultTest='test_suite')
if __name__ == '__main__':
run()