[CMF-checkins] CVS: CMF/CMFCore/tests - test_PortalFolder.py:1.21 test_TypesTool.py:1.20
Tres Seaver
tseaver@zope.com
Tue, 15 Apr 2003 12:08:33 -0400
Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv13354/CMFCore/tests
Modified Files:
test_PortalFolder.py test_TypesTool.py
Log Message:
- Land tseaver-ti_apb_redux-branch.
=== CMF/CMFCore/tests/test_PortalFolder.py 1.20 => 1.21 ===
--- CMF/CMFCore/tests/test_PortalFolder.py:1.20 Sun Aug 4 18:59:12 2002
+++ CMF/CMFCore/tests/test_PortalFolder.py Tue Apr 15 12:08:02 2003
@@ -274,7 +274,8 @@
# Now, test overridden behavior
types_tool.Folder.addAction( id = 'mkdir'
, name = 'MKDIR handler'
- , action = 'grabbed'
+ , action = 'string:grabbed'
+ , condition = ''
, permission = ''
, category = 'folder'
, visible = 0
=== CMF/CMFCore/tests/test_TypesTool.py 1.19 => 1.20 ===
--- CMF/CMFCore/tests/test_TypesTool.py:1.19 Fri Mar 14 12:25:14 2003
+++ CMF/CMFCore/tests/test_TypesTool.py Tue Apr 15 12:08:02 2003
@@ -1,5 +1,4 @@
-from unittest import TestCase, TestSuite, makeSuite, main
-
+import unittest
import Zope
try:
from Interface.Verify import verifyClass
@@ -7,28 +6,29 @@
# for Zope versions before 2.6.0
from Interface import verify_class_implementation as verifyClass
-from Products.CMFCore.TypesTool import\
- FactoryTypeInformation as FTI,\
- ScriptableTypeInformation as STI,\
- TypesTool,Unauthorized
-
-from Products.CMFCore.PortalFolder import PortalFolder
-from Products.CMFCore.utils import _getViewFor
-
-from Products.CMFCore.tests.base.testcase import \
- SecurityRequestTest
-from Products.CMFCore.tests.base.security import \
- OmnipotentUser, UserWithRoles
-from Products.CMFCore.tests.base.dummy import \
- DummyObject, addDummy, DummyTypeInfo,\
- DummyFolder, DummyFTI
-
+from Acquisition import aq_base
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
+from webdav.NullResource import NullResource
from Products.PythonScripts.standard import url_quote
-from webdav.NullResource import NullResource
-from Acquisition import aq_base
+
+from Products.CMFCore.TypesTool import FactoryTypeInformation as FTI
+from Products.CMFCore.TypesTool import ScriptableTypeInformation as STI
+from Products.CMFCore.TypesTool import TypesTool
+from Products.CMFCore.TypesTool import Unauthorized
+
+from Products.CMFCore.PortalFolder import PortalFolder
+from Products.CMFCore.utils import _getViewFor
+
+from Products.CMFCore.tests.base.testcase import SecurityRequestTest
+from Products.CMFCore.tests.base.security import OmnipotentUser
+from Products.CMFCore.tests.base.security import UserWithRoles
+from Products.CMFCore.tests.base.dummy import DummyObject
+from Products.CMFCore.tests.base.dummy import addDummy
+from Products.CMFCore.tests.base.dummy import DummyTypeInfo
+from Products.CMFCore.tests.base.dummy import DummyFolder
+from Products.CMFCore.tests.base.dummy import DummyFTI
class TypesToolTests( SecurityRequestTest ):
@@ -40,7 +40,7 @@
root._setObject( 'portal_types', TypesTool() )
tool = root.portal_types
tool._setObject( 'Dummy Content', DummyFTI )
-
+
def test_processActions( self ):
"""
Are the correct, permitted methods returned for actions?
@@ -77,7 +77,8 @@
meta_types[factype['name']]=1
# The url_quote below is necessary 'cos of the one in
# main.dtml. Could be removed once that is gone.
- self.failIf(type(aq_base(tool.unrestrictedTraverse(url_quote(factype['action'])))) is NullResource)
+ act = tool.unrestrictedTraverse(url_quote(factype['action']))
+ self.failIf(type(aq_base(act)) is NullResource)
# Check the ones we're expecting are there
self.failUnless(meta_types.has_key('Scriptable Type Information'))
@@ -93,7 +94,7 @@
verifyClass(IActionProvider, TypesTool)
-class TypeInfoTests( TestCase ):
+class TypeInfoTests( unittest.TestCase ):
def test_construction( self ):
ti = self._makeInstance( 'Foo'
@@ -135,9 +136,10 @@
def test_GlobalHide( self ):
self.tool = TypesTool()
tnf = self._makeAndSetInstance( 'Folder', filter_content_types=0)
- taf = self._makeAndSetInstance( 'Allowing Folder',
- allowed_content_types=('Hidden','Not Hidden'))
- tih = self._makeAndSetInstance( 'Hidden' ,global_allow=0)
+ taf = self._makeAndSetInstance( 'Allowing Folder'
+ , allowed_content_types=( 'Hidden'
+ ,'Not Hidden'))
+ tih = self._makeAndSetInstance( 'Hidden', global_allow=0)
tnh = self._makeAndSetInstance( 'Not Hidden')
# make sure we're normally hidden but everything else is visible
self.failIf ( tnf.allowType( 'Hidden' ) )
@@ -147,9 +149,12 @@
self.failUnless ( taf.allowType( 'Not Hidden') )
# make sure we're available in a non-content-type-filtered type
# where we have been explicitly allowed
- taf2 = self._makeAndSetInstance( 'Allowing Folder2',
- allowed_content_types=('Hidden','Not Hidden'),
- filter_content_types=0)
+ taf2 = self._makeAndSetInstance( 'Allowing Folder2'
+ , allowed_content_types=( 'Hidden'
+ , 'Not Hidden'
+ )
+ , filter_content_types=0
+ )
self.failUnless ( taf2.allowType( 'Hidden' ) )
self.failUnless ( taf2.allowType( 'Not Hidden') )
@@ -164,60 +169,53 @@
ACTION_LIST = \
( { 'id' : 'view'
, 'name' : 'View'
- , 'action' : 'foo_view'
+ , 'action' : 'string:foo_view'
, 'permissions' : ( 'View', )
, 'category' : 'object'
, 'visible' : 1
}
, { 'name' : 'Edit' # Note: No ID passed
- , 'action' : 'foo_edit'
+ , 'action' : 'string:foo_edit'
, 'permissions' : ( 'Modify', )
, 'category' : 'object'
, 'visible' : 1
}
, { 'name' : 'Object Properties' # Note: No ID passed
- , 'action' : 'foo_properties'
+ , 'action' : 'string:foo_properties'
, 'permissions' : ( 'Modify', )
, 'category' : 'object'
, 'visible' : 1
}
, { 'id' : 'slot'
- , 'action' : 'foo_slot'
+ , 'action' : 'string:foo_slot'
, 'category' : 'object'
, 'visible' : 0
}
)
- def _ripActionValues( self, key, actions ):
- return filter( None, map( lambda x, key=key: x.get( key, None )
- , actions
- ) )
-
def test_listActions( self ):
ti = self._makeInstance( 'Foo' )
- self.failIf( ti.getActions() )
+ self.failIf( ti.listActions() )
ti = self._makeInstance( 'Foo', actions=self.ACTION_LIST )
- actions = ti.getActions()
+ actions = ti.listActions()
self.failUnless( actions )
- ids = self._ripActionValues( 'id', actions )
+ ids = [ x.getId() for x in actions ]
self.failUnless( 'view' in ids )
self.failUnless( 'edit' in ids )
self.failUnless( 'objectproperties' in ids )
self.failUnless( 'slot' in ids )
- names = self._ripActionValues( 'name', actions )
+ names = [ x.Title() for x in actions ]
self.failUnless( 'View' in names )
self.failUnless( 'Edit' in names )
self.failUnless( 'Object Properties' in names )
self.failIf( 'slot' in names )
- self.failIf( 'Slot' in names )
+ self.failUnless( 'Slot' in names )
- visible = filter( None, map( lambda x:
- x.get( 'visible', 0 ) and x['id']
- , actions ) )
+ visible = [ x.getId() for x in actions if x.getVisibility() ]
self.failUnless( 'view' in visible )
self.failUnless( 'edit' in visible )
self.failUnless( 'objectproperties' in visible )
@@ -248,6 +246,37 @@
action = ti.getActionById( 'slot' )
self.assertEqual( action, 'foo_slot' )
+ def test__convertActions_from_dict( self ):
+
+ from Products.CMFCore.ActionInformation import ActionInformation
+
+ ti = self._makeInstance( 'Foo' )
+ ti._actions = ( { 'id' : 'bar'
+ , 'name' : 'Bar'
+ , 'action' : 'bar_action'
+ , 'permissions' : ( 'Bar permission', )
+ , 'category' : 'baz'
+ , 'visible' : 0
+ }
+ ,
+ )
+
+ actions = ti.listActions()
+ self.assertEqual( len( actions ), 1 )
+
+ action = actions[0]
+
+ self.failUnless( isinstance( action, ActionInformation ) )
+ self.assertEqual( action.getId(), 'bar' )
+ self.assertEqual( action.Title(), 'Bar' )
+ self.assertEqual( action.getActionExpression(), 'string:bar_action' )
+ self.assertEqual( action.getCondition(), '' )
+ self.assertEqual( action.getPermissions(), ( 'Bar permission', ) )
+ self.assertEqual( action.getCategory(), 'baz' )
+ self.assertEqual( action.getVisibility(), 0 )
+
+ self.failUnless( isinstance( ti._actions[0], ActionInformation ) )
+
class FTIDataTests( TypeInfoTests ):
@@ -297,7 +326,7 @@
verifyClass(ITypeInformation, STI)
-class FTIConstructionTests( TestCase ):
+class FTIConstructionTests( unittest.TestCase ):
def setUp( self ):
noSecurityManager()
@@ -341,7 +370,7 @@
self.failIf( ti.isConstructionAllowed( folder ) )
-class FTIConstructionTests_w_Roles( TestCase ):
+class FTIConstructionTests_w_Roles( unittest.TestCase ):
def tearDown( self ):
noSecurityManager()
@@ -435,13 +464,13 @@
def test_suite():
- return TestSuite((
- makeSuite(TypesToolTests),
- makeSuite(FTIDataTests),
- makeSuite(STIDataTests),
- makeSuite(FTIConstructionTests),
- makeSuite(FTIConstructionTests_w_Roles),
+ return unittest.TestSuite((
+ unittest.makeSuite(TypesToolTests),
+ unittest.makeSuite(FTIDataTests),
+ unittest.makeSuite(STIDataTests),
+ unittest.makeSuite(FTIConstructionTests),
+ unittest.makeSuite(FTIConstructionTests_w_Roles),
))
if __name__ == '__main__':
- main(defaultTest='test_suite')
+ unittest.main(defaultTest='test_suite')