[CMF-checkins] SVN: CMF/trunk/C - fixed getActionObject by making it skip newstyle Actions

Yvo Schubbe y.2005- at wcm-solutions.de
Sun Nov 6 11:16:11 EST 2005


Log message for revision 39946:
  - fixed getActionObject by making it skip newstyle Actions
  - refactored test_ActionsTool.py and added getActionObject test

Changed:
  U   CMF/trunk/CHANGES.txt
  U   CMF/trunk/CMFCore/ActionProviderBase.py
  U   CMF/trunk/CMFCore/tests/test_ActionsTool.py

-=-
Modified: CMF/trunk/CHANGES.txt
===================================================================
--- CMF/trunk/CHANGES.txt	2005-11-06 14:59:26 UTC (rev 39945)
+++ CMF/trunk/CHANGES.txt	2005-11-06 16:16:10 UTC (rev 39946)
@@ -94,6 +94,8 @@
 
   Bug Fixes
 
+    - ActionProviderBase: getActionObject did stumble over newstyle Actions.
+
     - CMFCore.exportimport.content:  Ensure that BODYFILE in our "faux"
       request is a file-like object, FBO objects which expect to call its
       'read' method.

Modified: CMF/trunk/CMFCore/ActionProviderBase.py
===================================================================
--- CMF/trunk/CMFCore/ActionProviderBase.py	2005-11-06 14:59:26 UTC (rev 39945)
+++ CMF/trunk/CMFCore/ActionProviderBase.py	2005-11-06 16:16:10 UTC (rev 39946)
@@ -72,8 +72,11 @@
 
         # search for action and return first one found
         for ai in self.listActions():
-            if id == ai.getId() and category == ai.getCategory():
-                return ai
+            try:
+                if id == ai.getId() and category == ai.getCategory():
+                    return ai
+            except AttributeError:
+                continue
 
         # no action found
         return None

Modified: CMF/trunk/CMFCore/tests/test_ActionsTool.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_ActionsTool.py	2005-11-06 14:59:26 UTC (rev 39945)
+++ CMF/trunk/CMFCore/tests/test_ActionsTool.py	2005-11-06 16:16:10 UTC (rev 39946)
@@ -18,6 +18,8 @@
 import unittest
 import Testing
 
+from Products.CMFCore.ActionInformation import Action
+from Products.CMFCore.ActionInformation import ActionCategory
 from Products.CMFCore.ActionInformation import ActionInformation
 from Products.CMFCore.Expression import Expression
 from Products.CMFCore.MembershipTool import MembershipTool
@@ -25,7 +27,7 @@
 from Products.CMFCore.URLTool import URLTool
 
 
-class ActionsToolTests(SecurityRequestTest):
+class ActionsToolTests(unittest.TestCase):
 
     def _getTargetClass(self):
         from Products.CMFCore.ActionsTool import ActionsTool
@@ -35,17 +37,6 @@
     def _makeOne(self, *args, **kw):
         return self._getTargetClass()(*args, **kw)
 
-    def setUp(self):
-        SecurityRequestTest.setUp(self)
-
-        root = self.root
-        root._setObject( 'portal_actions', self._makeOne() )
-        root._setObject( 'portal_url', URLTool() )
-        root._setObject( 'foo', URLTool() )
-        root._setObject('portal_membership', MembershipTool())
-        self.tool = root.portal_actions
-        self.tool.action_providers = ('portal_actions',)
-
     def test_z2interfaces(self):
         from Interface.Verify import verifyClass
         from Products.CMFCore.interfaces.portal_actions \
@@ -64,12 +55,16 @@
         verifyClass(IActionProvider, self._getTargetClass())
         verifyClass(IActionsTool, self._getTargetClass())
 
-    def test_actionProviders(self):
-        tool = self.tool
+    def test_listActionProviders(self):
+        tool = self._makeOne()
+        tool.action_providers = ('portal_actions',)
         self.assertEqual(tool.listActionProviders(), ('portal_actions',))
 
     def test_addActionProvider(self):
-        tool = self.tool
+        tool = self._makeOne()
+        tool.foo = 'acquirable attribute'
+        tool.portal_url = 'acquirable attribute'
+        tool.action_providers = ('portal_actions',)
         tool.addActionProvider('foo')
         self.assertEqual(tool.listActionProviders(),
                           ('portal_actions', 'foo'))
@@ -78,12 +73,47 @@
         self.assertEqual(tool.listActionProviders(),
                           ('portal_actions', 'foo', 'portal_url'))
 
-    def test_delActionProvider(self):
-        tool = self.tool
+    def test_deleteActionProvider(self):
+        tool = self._makeOne()
+        tool.action_providers = ('portal_actions', 'foo')
         tool.deleteActionProvider('foo')
-        self.assertEqual(tool.listActionProviders(),
-                          ('portal_actions',))
+        self.assertEqual(tool.listActionProviders(), ('portal_actions',))
 
+    def test_getActionObject(self):
+        tool = self._makeOne()
+        tool._setObject('object', ActionCategory('object'))
+        tool.object._setObject('newstyle_id', Action('newstyle_id'))
+        tool.addAction('an_id', 'name', '', '', '', 'object')
+        rval = tool.getActionObject('object/an_id')
+        self.assertEqual(rval, tool._actions[0])
+        rval = tool.getActionObject('object/newstyle_id')
+        self.assertEqual(rval, None)
+        rval = tool.getActionObject('object/not_existing_id')
+        self.assertEqual(rval, None)
+        self.assertRaises(ValueError, tool.getActionObject, 'wrong_format')
+
+
+class ActionsToolSecurityRequestTests(SecurityRequestTest):
+
+    def _getTargetClass(self):
+        from Products.CMFCore.ActionsTool import ActionsTool
+
+        return ActionsTool
+
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
+
+    def setUp(self):
+        SecurityRequestTest.setUp(self)
+
+        root = self.root
+        root._setObject( 'portal_actions', self._makeOne() )
+        root._setObject( 'portal_url', URLTool() )
+        root._setObject( 'foo', URLTool() )
+        root._setObject('portal_membership', MembershipTool())
+        self.tool = root.portal_actions
+        self.tool.action_providers = ('portal_actions',)
+
     def test_listActionInformationActions(self):
         # Check that listFilteredActionsFor works for objects that return
         # ActionInformation objects
@@ -119,6 +149,7 @@
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(ActionsToolTests),
+        unittest.makeSuite(ActionsToolSecurityRequestTests),
         ))
 
 if __name__ == '__main__':



More information about the CMF-checkins mailing list