[CMF-checkins] CVS: CMF/CMFCore/tests - test_PortalFolder.py:1.10.4.1 test_TypesTool.py:1.2.4.1 test_all.py:1.4.2.1

seb seb@jamkit.com
Thu, 18 Oct 2001 05:52:58 -0400


Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv9412/Products/CMFCore/tests

Modified Files:
      Tag: seb-defaultActionRefactor-branch
	test_PortalFolder.py test_TypesTool.py test_all.py 
Log Message:
Refactored getDefaultView into CMFCore.utils._getView; can now specify a view to get by name.  
Added new TypesTool unit test.


=== CMF/CMFCore/tests/test_PortalFolder.py 1.10 => 1.10.4.1 ===
         assert has_path( catalog._catalog, '/test/folder/sub/foo' )
 
-        #import pdb; pdb.set_trace()
         folder.manage_renameObject( id='sub', new_id='new_sub' )
         assert 'foo' in catalog.uniqueValuesFor( 'id' )
         assert len( catalog ) == 1


=== CMF/CMFCore/tests/test_TypesTool.py 1.2 => 1.2.4.1 ===
 import unittest
 import OFS.Folder, OFS.SimpleItem
+import Acquisition
+from AccessControl.SecurityManagement import newSecurityManager
 from AccessControl import SecurityManager
 from Products.CMFCore.TypesTool import *
 from Products.CMFCore.PortalContent import PortalContent
 from Products.CMFCore.CMFCorePermissions import AddPortalContent
 from Products.CMFCore.CMFCorePermissions import ModifyPortalContent
 from Products.CMFCore.PortalFolder import *
+from Products.CMFCore import utils
 import ZPublisher.HTTPRequest
 
 class UnitTestSecurityPolicy:
@@ -21,8 +24,36 @@
         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 DummyMethod:
+    def __init__(self, name):
+        self.name = name
+    def __str__(self):
+        return self.name
+    def __call__(self):
+        return self.name
+
 class DummyContent( PortalContent, OFS.SimpleItem.Item ):
     """
     """
@@ -44,6 +75,7 @@
         SecurityManager.setSecurityPolicy(self._policy)
         self.connection = Zope.DB.open()
         root = self.root = self.connection.root()[ 'Application' ]
+        newSecurityManager( None, UnitTestUser().__of__( self.root ) )
 
         env = { 'SERVER_NAME' : 'http://localhost'
               , 'SERVER_PORT' : '80'
@@ -58,29 +90,62 @@
         tool._setObject( 'Dummy'
                        , FTI( 'Dummy'
                             , meta_type=DummyContent.meta_type
-                            , product='OFSP'
-                            , factory='addDTMLDocument'
-                            )
-                       )
+                            , product='CMFDefault'
+                            , factory='addDocument'
+                            , actions= ( { 'name'          : 'View'
+                                           , 'action'        : 'view'
+                                           , 'permissions'   : ('View', ) },
+                                         { 'name'          : 'View2'
+                                           , 'action'        : 'view2'
+                                           , 'permissions'   : ('View', ) },
+                                         { 'name'          : 'Edit'
+                                           , 'action'        : 'edit'
+                                           , 'permissions'   : ('forbidden permission',)
+                                           }
+                                         )
+                              )
+                         )
     
     def tearDown( self ):
         get_transaction().abort()
         self.connection.close()
 
-    def test_otherFolderTypes( self ):
+    def off_test_otherFolderTypes( self ):
         """
             Does 'invokeFactory' work when invoked from non-PortalFolder?
+            Currently tests a bug which hasn't been fixed (remove 'off_'
+            from name to activate)            
         """
         self.root._setObject( 'portal', PortalFolder( 'portal', '' ) )
         portal = self.root.portal
         portal._setObject( 'normal', OFS.Folder.Folder( 'normal', '' ) )
         normal = portal.normal
-
         normal.invokeFactory( 'Dummy', 'dummy' )
         assert 'dummy' not in portal.objectIds()
         assert 'dummy' in normal.objectIds()
 
+    def test_processActions( self ):
+        """
+        Are the correct, permitted methods returned for actions?
+        """
+        self.root._setObject( 'portal', PortalFolder( 'portal', '' ) )
+        portal = self.root.portal
+        portal.invokeFactory( 'Dummy', 'actions_dummy' )
+        dummy = portal._getOb( 'actions_dummy' )
 
+        # so we can traverse to it:
+        dummy.view = DummyMethod("view")
+        dummy.view2 = DummyMethod("view2")
+        dummy.edit = DummyMethod("edit")
+
+        default_view = dummy()
+        custom_view = utils._getViewFor( dummy, view='view2' )()
+        unpermitted_view = utils._getViewFor( dummy, view='edit' )()
+
+        assert default_view == 'view'
+        assert custom_view == 'view2'
+        assert unpermitted_view != 'edit'
+        assert unpermitted_view == 'view'
 
 def test_suite():
     suite = unittest.TestSuite()


=== CMF/CMFCore/tests/test_all.py 1.4 => 1.4.2.1 ===
 from Products.CMFCore.tests import test_ContentTypeRegistry
 from Products.CMFCore.tests import test_PortalFolder
+from Products.CMFCore.tests import test_TypesTool
 
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest( test_ContentTypeRegistry.test_suite() )
     suite.addTest( test_PortalFolder.test_suite() )
+    suite.addTest( test_TypesTool.test_suite() )
     return suite
 
 def run():