[CMF-checkins] CVS: CMF/CMFCore/tests - test_ActionInformation.py:1.6 test_ActionProviderBase.py:1.9 test_ActionsTool.py:1.9 test_Expression.py:1.4

Yvo Schubbe cvs-admin at zope.org
Thu Nov 27 10:06:51 EST 2003


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

Modified Files:
	test_ActionInformation.py test_ActionProviderBase.py 
	test_ActionsTool.py test_Expression.py 
Log Message:
Merged yuppie-listActionInfos-branch:
- refactored listFilteredActionsFor()
- added listActionInfos() and getActionInfo() to Action providers
- added helper methods getOAI() and getExprContext()


=== CMF/CMFCore/tests/test_ActionInformation.py 1.5 => 1.6 ===
--- CMF/CMFCore/tests/test_ActionInformation.py:1.5	Fri May  9 17:40:23 2003
+++ CMF/CMFCore/tests/test_ActionInformation.py	Thu Nov 27 10:06:50 2003
@@ -7,17 +7,16 @@
     # for Zope versions before 2.6.1
     pass
 
-from Products.CMFCore.tests.base.testcase import \
-     TransactionalTest
-
-from Products.CMFCore.tests.base.dummy import \
-     DummyContent, DummyTool as DummyMembershipTool
-
 from Products.CMFCore.ActionInformation import ActionInformation
-from Products.CMFCore.Expression import Expression, createExprContext
+from Products.CMFCore.Expression import createExprContext
+from Products.CMFCore.Expression import Expression
+from Products.CMFCore.tests.base.dummy import DummyContent
+from Products.CMFCore.tests.base.dummy import DummyTool as DummyMembershipTool
+from Products.CMFCore.tests.base.testcase import TransactionalTest
+
 
 class ActionInformationTests(TransactionalTest):
-    
+
     def setUp( self ):
 
         TransactionalTest.setUp( self )
@@ -58,11 +57,11 @@
         self.assertEqual(ai.getVisibility(), 0)
         self.assertEqual(ai.getCategory(), 'global')
         self.assertEqual(ai.getPermissions(), ())
-    
+
     def test_Condition(self):
-        portal = self.portal 
+        portal = self.portal
         folder = self.folder
-        object = self.object 
+        object = self.object
         ai = ActionInformation(id='view'
                              , title='View'
                              , action=Expression(
@@ -73,7 +72,8 @@
                              , visible=1)
         ec = createExprContext(folder, portal, object)
         self.failIf(ai.testCondition(ec))
-        
+
+
 def test_suite():
     return TestSuite((
         makeSuite(ActionInformationTests),


=== CMF/CMFCore/tests/test_ActionProviderBase.py 1.8 => 1.9 ===
--- CMF/CMFCore/tests/test_ActionProviderBase.py:1.8	Mon Jan  6 15:40:27 2003
+++ CMF/CMFCore/tests/test_ActionProviderBase.py	Thu Nov 27 10:06:50 2003
@@ -1,12 +1,20 @@
-import unittest
+from unittest import TestCase, TestSuite, makeSuite, main
+
 import Zope
 try:
+    Zope.startup()
+except AttributeError:
+    # for Zope versions before 2.6.1
+    pass
+try:
     from Interface.Verify import verifyClass
 except ImportError:
     # for Zope versions before 2.6.0
     from Interface import verify_class_implementation as verifyClass
 
+from Products.CMFCore.tests.base.dummy import DummySite
 from Products.CMFCore.tests.base.dummy import DummyTool
+from Products.CMFCore.tests.base.testcase import SecurityRequestTest
 
 #
 #   We have to import these here to make the "ugly sharing" test case go.
@@ -14,7 +22,8 @@
 from Products.CMFCore.ActionProviderBase import ActionProviderBase
 from Products.CMFCore.ActionInformation import ActionInformation
 
-class DummyProvider( ActionProviderBase ):
+
+class DummyProvider(ActionProviderBase, DummyTool):
 
     _actions = ( ActionInformation( id='an_id'
                                   , title='A Title'
@@ -25,6 +34,7 @@
                                   , visible=0
                                   ), )
 
+
 class DummyAction:
 
     def __init__( self, value ):
@@ -40,8 +50,15 @@
               or 0
                )
 
-class ActionProviderBaseTests(unittest.TestCase):
+
+class ActionProviderBaseTests(SecurityRequestTest):
     
+    def setUp( self ):
+        SecurityRequestTest.setUp(self)
+        self.site = DummySite('site').__of__(self.root)
+        utool = self.site._setObject( 'portal_url', DummyTool() )
+        mtool = self.site._setObject( 'portal_membership', DummyTool() )
+
     def _makeProvider( self, dummy=0 ):
 
         klass = dummy and DummyProvider or ActionProviderBase
@@ -66,7 +83,6 @@
 
     def test_changeActions( self ):
 
-
         apb = DummyTool()
         old_actions = list( apb._actions )
 
@@ -147,16 +163,41 @@
         self.failIf( one_ids == another_ids )
         self.assertEqual( old_ids, another_ids )
 
+    def test_listActionInfos(self):
+        wanted = [{'permissions': '', 'id': 'an_id', 'url': '',
+                   'name': 'A Title', 'visible': 0, 'category': 'object'}]
+
+        apb = self.site._setObject( 'portal_apb', self._makeProvider(1) )
+        rval = apb.listActionInfos()
+        self.assertEqual( rval, [] )
+        rval = apb.listActionInfos(check_visibility=0)
+        self.assertEqual( rval, wanted )
+        rval = apb.listActionInfos('foo/another_id', check_visibility=0)
+        self.assertEqual( rval, [] )
+
+    def test_getActionInfo(self):
+        wanted = {'permissions': '', 'id': 'an_id', 'url': '',
+                  'name': 'A Title', 'visible': 0, 'category': 'object'}
+
+        apb = self.site._setObject( 'portal_apb', self._makeProvider(1) )
+        rval = apb.getActionInfo( ('object/an_id',) )
+        self.assertEqual( rval, wanted )
+        rval = apb.getActionInfo('object/an_id')
+        self.assertEqual( rval, wanted )
+        rval = apb.getActionInfo('object/an_id', check_visibility=1)
+        self.assertEqual( rval, None )
+
     def test_interface(self):
         from Products.CMFCore.interfaces.portal_actions \
                 import ActionProvider as IActionProvider
 
         verifyClass(IActionProvider, ActionProviderBase)
 
+
 def test_suite():
-    return unittest.TestSuite((
-        unittest.makeSuite(ActionProviderBaseTests),
+    return TestSuite((
+        makeSuite(ActionProviderBaseTests),
         ))
 
 if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')
+    main(defaultTest='test_suite')


=== CMF/CMFCore/tests/test_ActionsTool.py 1.8 => 1.9 ===
--- CMF/CMFCore/tests/test_ActionsTool.py:1.8	Mon Jan  6 15:40:36 2003
+++ CMF/CMFCore/tests/test_ActionsTool.py	Thu Nov 27 10:06:50 2003
@@ -1,7 +1,12 @@
-from unittest import TestCase, TestSuite, makeSuite, main
+from unittest import TestSuite, makeSuite, main
 
 import Zope
 try:
+    Zope.startup()
+except AttributeError:
+    # for Zope versions before 2.6.1
+    pass
+try:
     from Interface.Verify import verifyClass
 except ImportError:
     # for Zope versions before 2.6.0
@@ -19,20 +24,20 @@
 from Products.CMFCore.RegistrationTool import RegistrationTool
 from Products.CMFCore.MembershipTool import MembershipTool
 
+
 class ActionsToolTests( SecurityRequestTest ):
 
     def setUp( self ):
-        
+
         SecurityRequestTest.setUp(self)
-        
+
         root = self.root
         root._setObject( 'portal_actions', ActionsTool() )
-        root._setObject('foo', URLTool() )
-        root._setObject('bar', URLTool() )
+        root._setObject( 'portal_url', URLTool() )
+        root._setObject( 'foo', URLTool() )
         root._setObject('portal_membership', MembershipTool())
         root._setObject('portal_types', TypesTool())
         self.tool = root.portal_actions
-        self.ut = root.foo
         self.tool.action_providers = ('portal_actions',)
 
     def test_actionProviders(self):
@@ -44,10 +49,10 @@
         tool.addActionProvider('foo')
         self.assertEqual(tool.listActionProviders(),
                           ('portal_actions', 'foo'))
-        tool.addActionProvider('bar')
+        tool.addActionProvider('portal_url')
         tool.addActionProvider('foo')
         self.assertEqual(tool.listActionProviders(),
-                          ('portal_actions', 'foo', 'bar'))
+                          ('portal_actions', 'foo', 'portal_url'))
 
     def test_delActionProvider(self):
         tool = self.tool
@@ -75,7 +80,7 @@
                                       'category': 'object'}],
                           'folder': [],
                           'global': []})
-        
+
     def test_listDictionaryActions(self):
         """
         Check that listFilteredActionsFor works for objects


=== CMF/CMFCore/tests/test_Expression.py 1.3 => 1.4 ===
--- CMF/CMFCore/tests/test_Expression.py:1.3	Fri Feb 15 14:45:33 2002
+++ CMF/CMFCore/tests/test_Expression.py	Thu Nov 27 10:06:50 2003
@@ -1,19 +1,24 @@
-import Zope
 from unittest import TestSuite, makeSuite, main
 
-from Products.CMFCore.tests.base.testcase import \
-     SecurityTest
-
-from Products.CMFCore.tests.base.dummy import \
-     DummyContent, DummyTool as DummyMembershipTool
+import Zope
+try:
+    Zope.startup()
+except AttributeError:
+    # for Zope versions before 2.6.1
+    pass
 
 from Products.CMFCore.ActionInformation import ActionInformation
-from Products.CMFCore.Expression import Expression, createExprContext
+from Products.CMFCore.Expression import createExprContext
+from Products.CMFCore.Expression import Expression
+from Products.CMFCore.tests.base.dummy import DummyContent
+from Products.CMFCore.tests.base.dummy import DummyTool as DummyMembershipTool
+from Products.CMFCore.tests.base.testcase import SecurityTest
+
 
 class ExpressionTests( SecurityTest ):
 
     def setUp( self ):
-        
+
         SecurityTest.setUp(self)
         root = self.root
         root._setObject('portal', DummyContent('portal', url='url_portal'))
@@ -57,7 +62,8 @@
         self.failUnless(folder)
         self.assertEqual(folder.id, 'foo')
         self.assertEqual(folder.absolute_url(), 'url_foo')
-        
+
+
 def test_suite():
     return TestSuite((
         makeSuite(ExpressionTests),




More information about the CMF-checkins mailing list