[CMF-checkins] CVS: Products/CMFCore/tests -
test_ActionInformation.py:1.10
Yvo Schubbe
y.2004_ at wcm-solutions.de
Thu Aug 5 09:52:32 EDT 2004
Update of /cvs-repository/Products/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv5280/CMFCore/tests
Modified Files:
test_ActionInformation.py
Log Message:
- reimplemented ActionInfo based on UserDict to avoid trouble with DTML
- added basic unittests for ActionInfo
=== Products/CMFCore/tests/test_ActionInformation.py 1.9 => 1.10 ===
--- Products/CMFCore/tests/test_ActionInformation.py:1.9 Wed Jun 30 11:40:17 2004
+++ Products/CMFCore/tests/test_ActionInformation.py Thu Aug 5 09:52:32 2004
@@ -1,9 +1,9 @@
-from unittest import TestSuite, makeSuite, main
+from unittest import TestCase, TestSuite, makeSuite, main
import Testing
import Zope
Zope.startup()
+from Interface.Verify import verifyClass
-from Products.CMFCore.ActionInformation import ActionInformation
from Products.CMFCore.Expression import createExprContext
from Products.CMFCore.Expression import Expression
from Products.CMFCore.tests.base.dummy import DummyContent
@@ -11,6 +11,61 @@
from Products.CMFCore.tests.base.testcase import TransactionalTest
+class ActionInfoTests(TestCase):
+
+ def _makeOne(self, *args, **kw):
+ from Products.CMFCore.ActionInformation import ActionInfo
+
+ return ActionInfo(*args, **kw)
+
+ def test_interface(self):
+ from Products.CMFCore.interfaces.portal_actions \
+ import ActionInfo as IActionInfo
+ from Products.CMFCore.ActionInformation import ActionInfo
+
+ verifyClass(IActionInfo, ActionInfo)
+
+ def test_create_from_ActionInformation(self):
+ from Products.CMFCore.ActionInformation import ActionInformation
+
+ wanted = {'allowed': True, 'available': True, 'category': 'object',
+ 'id': 'foo', 'name': 'foo', 'permissions': (),
+ 'title': 'foo', 'url': '', 'visible': True}
+
+ action = ActionInformation(id='foo')
+ ec = None
+ ai = self._makeOne(action, ec)
+
+ self.assertEqual( ai['id'], wanted['id'] )
+ self.assertEqual( ai['title'], wanted['title'] )
+ self.assertEqual( ai['url'], wanted['url'] )
+ self.assertEqual( ai['permissions'], wanted['permissions'] )
+ self.assertEqual( ai['category'], wanted['category'] )
+ self.assertEqual( ai['visible'], wanted['visible'] )
+ self.assertEqual( ai['available'], wanted['available'] )
+ self.assertEqual( ai['allowed'], wanted['allowed'] )
+ self.assertEqual( ai, wanted )
+
+ def test_create_from_dict(self):
+ wanted = {'allowed': True, 'available': True, 'category': 'object',
+ 'id': 'foo', 'name': 'foo', 'permissions': (),
+ 'title': 'foo', 'url': '', 'visible': True}
+
+ action = {'name': 'foo', 'url': ''}
+ ec = None
+ ai = self._makeOne(action, ec)
+
+ self.assertEqual( ai['id'], wanted['id'] )
+ self.assertEqual( ai['title'], wanted['title'] )
+ self.assertEqual( ai['url'], wanted['url'] )
+ self.assertEqual( ai['permissions'], wanted['permissions'] )
+ self.assertEqual( ai['category'], wanted['category'] )
+ self.assertEqual( ai['visible'], wanted['visible'] )
+ self.assertEqual( ai['available'], wanted['available'] )
+ self.assertEqual( ai['allowed'], wanted['allowed'] )
+ self.assertEqual( ai, wanted )
+
+
class ActionInformationTests(TransactionalTest):
def setUp( self ):
@@ -24,9 +79,14 @@
self.folder = DummyContent('foo', 'url_foo')
self.object = DummyContent('bar', 'url_bar')
+ def _makeOne(self, *args, **kw):
+ from Products.CMFCore.ActionInformation import ActionInformation
+
+ return ActionInformation(*args, **kw)
+
def test_basic_construction(self):
- ai = ActionInformation(id='view'
- )
+ ai = self._makeOne(id='view')
+
self.assertEqual(ai.getId(), 'view')
self.assertEqual(ai.Title(), 'view')
self.assertEqual(ai.Description(), '')
@@ -37,10 +97,9 @@
self.assertEqual(ai.getPermissions(), ())
def test_editing(self):
- ai = ActionInformation(id='view',
- category='folder',
- )
+ ai = self._makeOne(id='view', category='folder')
ai.edit(id='new_id', title='blah')
+
self.assertEqual(ai.getId(), 'new_id')
self.assertEqual(ai.Title(), 'blah')
self.assertEqual(ai.Description(), '')
@@ -51,14 +110,13 @@
self.assertEqual(ai.getPermissions(), ())
def test_construction_with_Expressions(self):
- ai = ActionInformation(id='view'
- , title='View'
- , action=Expression(
- text='view')
- , condition=Expression(
- text='member')
- , category='global'
- , visible=0)
+ ai = self._makeOne( id='view',
+ title='View',
+ action=Expression(text='view'),
+ condition=Expression(text='member'),
+ category='global',
+ visible=False )
+
self.assertEqual(ai.getId(), 'view')
self.assertEqual(ai.Title(), 'View')
self.assertEqual(ai.Description(), '')
@@ -72,20 +130,20 @@
portal = self.portal
folder = self.folder
object = self.object
- ai = ActionInformation(id='view'
- , title='View'
- , action=Expression(
- text='view')
- , condition=Expression(
- text='member')
- , category='global'
- , visible=1)
+ ai = self._makeOne( id='view',
+ title='View',
+ action=Expression(text='view'),
+ condition=Expression(text='member'),
+ category='global',
+ visible=True )
ec = createExprContext(folder, portal, object)
+
self.failIf(ai.testCondition(ec))
def test_suite():
return TestSuite((
+ makeSuite(ActionInfoTests),
makeSuite(ActionInformationTests),
))
More information about the CMF-checkins
mailing list