vendor/CMF/1.6.3/CMFCore

view tests/test_ActionsTool.py @ 0:587011552858

import CMF 1.6.3
author bdelbosc
date Mon, 23 Apr 2007 13:58:01 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
4 #
5 # This software is subject to the provisions of the Zope Public License,
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10 # FOR A PARTICULAR PURPOSE.
11 #
12 ##############################################################################
13 """ Unit tests for ActionsTool module.
15 $Id$
16 """
18 from unittest import TestSuite, makeSuite, main
19 import Testing
20 try:
21 import Zope2
22 except ImportError: # BBB: for Zope 2.7
23 import Zope as Zope2
24 Zope2.startup()
26 from Products.CMFCore.MembershipTool import MembershipTool
27 from Products.CMFCore.RegistrationTool import RegistrationTool
28 from Products.CMFCore.tests.base.testcase import SecurityRequestTest
29 from Products.CMFCore.TypesTool import TypesTool
30 from Products.CMFCore.URLTool import URLTool
33 class ActionsToolTests( SecurityRequestTest ):
35 def _makeOne(self, *args, **kw):
36 from Products.CMFCore.ActionsTool import ActionsTool
38 return ActionsTool(*args, **kw)
40 def setUp(self):
41 SecurityRequestTest.setUp(self)
43 root = self.root
44 root._setObject( 'portal_actions', self._makeOne() )
45 root._setObject( 'portal_url', URLTool() )
46 root._setObject( 'foo', URLTool() )
47 root._setObject('portal_membership', MembershipTool())
48 root._setObject('portal_types', TypesTool())
49 self.tool = root.portal_actions
50 self.tool.action_providers = ('portal_actions',)
52 def test_z2interfaces(self):
53 from Interface.Verify import verifyClass
54 from Products.CMFCore.ActionsTool import ActionsTool
55 from Products.CMFCore.interfaces.portal_actions \
56 import ActionProvider as IActionProvider
57 from Products.CMFCore.interfaces.portal_actions \
58 import portal_actions as IActionsTool
60 verifyClass(IActionProvider, ActionsTool)
61 verifyClass(IActionsTool, ActionsTool)
63 def test_z3interfaces(self):
64 try:
65 from zope.interface.verify import verifyClass
66 from Products.CMFCore.interfaces import IActionProvider
67 from Products.CMFCore.interfaces import IActionsTool
68 except ImportError:
69 # BBB: for Zope 2.7
70 return
71 from Products.CMFCore.ActionsTool import ActionsTool
73 verifyClass(IActionProvider, ActionsTool)
74 verifyClass(IActionsTool, ActionsTool)
76 def test_actionProviders(self):
77 tool = self.tool
78 self.assertEqual(tool.listActionProviders(), ('portal_actions',))
80 def test_addActionProvider(self):
81 tool = self.tool
82 tool.addActionProvider('foo')
83 self.assertEqual(tool.listActionProviders(),
84 ('portal_actions', 'foo'))
85 tool.addActionProvider('portal_url')
86 tool.addActionProvider('foo')
87 self.assertEqual(tool.listActionProviders(),
88 ('portal_actions', 'foo', 'portal_url'))
90 def test_delActionProvider(self):
91 tool = self.tool
92 tool.deleteActionProvider('foo')
93 self.assertEqual(tool.listActionProviders(),
94 ('portal_actions',))
96 def test_listActionInformationActions(self):
97 """
98 Check that listFilteredActionsFor works for objects
99 that return ActionInformation objects
100 """
101 root = self.root
102 tool = self.tool
103 root._setObject('portal_registration', RegistrationTool())
104 self.tool.action_providers = ('portal_actions',)
105 self.assertEqual(tool.listFilteredActionsFor(root.portal_registration),
106 {'workflow': [],
107 'user': [],
108 'object': [],
109 'folder': [{'permissions': ('List folder contents',),
110 'id': 'folderContents',
111 'url': 'http://foo/folder_contents',
112 'title': 'Folder contents',
113 'name': 'Folder contents',
114 'visible': True,
115 'available': True,
116 'allowed': True,
117 'category': 'folder'}],
118 'global': []})
121 def test_suite():
122 return TestSuite((
123 makeSuite(ActionsToolTests),
124 ))
126 if __name__ == '__main__':
127 main(defaultTest='test_suite')