Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions
CMFCore.tests.test_ActionProviderBase.ActionProviderBaseTests Class Reference
Inheritance diagram for CMFCore.tests.test_ActionProviderBase.ActionProviderBaseTests:
Inheritance graph
[legend]
Collaboration diagram for CMFCore.tests.test_ActionProviderBase.ActionProviderBaseTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def setUp
def tearDown
def test_z2interfaces
def test_z3interfaces
def test_addAction
def test_addActionBlankPermission
def test_extractActionBlankPermission
def test_changeActions
def test_deleteActions
def test_DietersNastySharingBug
def test_listActionInfos
def test_getActionObject
def test_getActionInfo

Public Attributes

 site

Private Member Functions

def _makeProvider

Detailed Description

Definition at line 62 of file test_ActionProviderBase.py.


Member Function Documentation

Definition at line 74 of file test_ActionProviderBase.py.

00074 
00075     def _makeProvider( self, dummy=0 ):
00076 
00077         klass = dummy and DummyProvider or ActionProviderBase
00078         return klass()

Here is the caller graph for this function:

Definition at line 64 of file test_ActionProviderBase.py.

00064 
00065     def setUp(self):
00066         SecurityRequestTest.setUp(self)
00067         self.site = DummySite('site').__of__(self.root)
00068         utool = self.site._setObject( 'portal_url', DummyTool() )
00069         mtool = self.site._setObject( 'portal_membership', DummyTool() )

Definition at line 70 of file test_ActionProviderBase.py.

00070 
00071     def tearDown(self):
00072         cleanUp()
00073         SecurityRequestTest.tearDown(self)

Here is the call graph for this function:

Definition at line 92 of file test_ActionProviderBase.py.

00092 
00093     def test_addAction( self ):
00094 
00095         apb = self._makeProvider()
00096         self.failIf( apb._actions )
00097         old_actions = apb._actions
00098         apb.addAction( id='foo'
00099                      , name='foo_action'
00100                      , action=''
00101                      , condition=''
00102                      , permission=''
00103                      , category=''
00104                      )
00105         self.failUnless( apb._actions )
00106         self.failIf( apb._actions is old_actions )

Here is the call graph for this function:

Definition at line 107 of file test_ActionProviderBase.py.

00107 
00108     def test_addActionBlankPermission(self):
00109         # make sure a blank permission gets stored as an empty tuple
00110         # '' and () and ('',) should mean no permission.
00111 
00112         apb = self._makeProvider()
00113         apb.addAction(id='foo',
00114                       name='foo_action',
00115                       action='',
00116                       condition='',
00117                       permission='',
00118                       category='',
00119                       )
00120         self.assertEqual(apb._actions[0].permissions, ())
00121 
00122         apb.addAction(id='foo',
00123                       name='foo_action',
00124                       action='',
00125                       condition='',
00126                       permission=('',),
00127                       category='',
00128                       )
00129         self.assertEqual(apb._actions[1].permissions, ())
00130 
00131         apb.addAction(id='foo',
00132                       name='foo_action',
00133                       action='',
00134                       condition='',
00135                       permission=(),
00136                       category='',
00137                       )
00138         self.assertEqual(apb._actions[2].permissions, ())

Here is the call graph for this function:

Definition at line 164 of file test_ActionProviderBase.py.

00164 
00165     def test_changeActions( self ):
00166 
00167         apb = DummyTool()
00168         old_actions = list( apb._actions )
00169 
00170         keys = [ ( 'id_%d', None )
00171                , ( 'name_%d', None )
00172                , ( 'action_%d', '' )
00173                , ( 'condition_%d', '' )
00174                , ( 'permission_%d', None )
00175                , ( 'category_%d', None )
00176                , ( 'visible_%d', 0 )
00177                ]
00178 
00179         properties = {}
00180         for i in range( len( old_actions ) ):
00181             for key, value in keys:
00182                 token = key % i
00183                 if value is None:
00184                     value = token
00185                 properties[ token ] = value
00186 
00187         apb.changeActions( properties=properties )
00188 
00189         marker = []
00190         for i in range( len( apb._actions ) ):
00191 
00192             for key, value in keys:
00193                 attr = key[ : -3 ]
00194 
00195                 if value is None:
00196                     value = key % i
00197 
00198                 if attr == 'name':    # WAAAA
00199                     attr = 'title'
00200 
00201                 if attr == 'permission':    # WAAAA
00202                     attr = 'permissions'
00203                     value = ( value, )
00204 
00205                 attr_value = getattr( apb._actions[i], attr, marker )
00206                 self.assertEqual( attr_value
00207                                 , value
00208                                 , '%s, %s != %s, %s'
00209                                   % ( attr, attr_value, key, value )  )
00210         self.failIf( apb._actions is old_actions )

Definition at line 211 of file test_ActionProviderBase.py.

00211 
00212     def test_deleteActions( self ):
00213 
00214         apb = self._makeProvider()
00215         apb._actions = tuple( map( DummyAction, [ '0', '1', '2' ] ) )
00216         apb.deleteActions( selections=(0,2) )
00217         self.assertEqual( len( apb._actions ), 1 )
00218         self.failUnless( DummyAction('1') in apb._actions )

Here is the call graph for this function:

Definition at line 219 of file test_ActionProviderBase.py.

00219 
00220     def test_DietersNastySharingBug( self ):
00221 
00222         one = self._makeProvider( dummy=1 )
00223         another = self._makeProvider( dummy=1 )
00224 
00225         def idify( x ):
00226             return id( x )
00227 
00228         old_ids = one_ids = map( idify, one.listActions() )
00229         another_ids = map( idify, another.listActions() )
00230 
00231         self.assertEqual( one_ids, another_ids )
00232 
00233         one.changeActions( { 'id_0'            : 'different_id'
00234                            , 'name_0'          : 'A Different Title'
00235                            , 'action_0'        : 'arise_shine'
00236                            , 'condition_0'     : 'always'
00237                            , 'permissions_0'   : 'granted'
00238                            , 'category_0'      : 'quality'
00239                            , 'visible_0'       : 1
00240                            } )
00241 
00242         one_ids = map( idify, one.listActions() )
00243         another_ids = map( idify, another.listActions() )
00244         self.failIf( one_ids == another_ids )
00245         self.assertEqual( old_ids, another_ids )

Here is the call graph for this function:

Definition at line 139 of file test_ActionProviderBase.py.

00139 
00140     def test_extractActionBlankPermission(self):
00141         # make sure a blank permission gets stored as an empty tuple
00142         # both () and ('',) should mean no permission.
00143 
00144         apb = self._makeProvider()
00145 
00146         index = 5
00147         properties = {
00148             'id_5': 'foo',
00149             'name_5': 'foo_action',
00150             'permission_5': (),
00151             }
00152         action = apb._extractAction(properties, index)
00153         self.assertEqual(action.permissions, ())
00154 
00155         index = 2
00156         properties = {
00157             'id_2': 'foo',
00158             'name_2': 'foo_action',
00159             'permission_2': ('',),
00160             }
00161         action = apb._extractAction(properties, index)
00162         self.assertEqual(action.permissions, ())
00163 

Here is the call graph for this function:

Definition at line 267 of file test_ActionProviderBase.py.

00267 
00268     def test_getActionInfo(self):
00269         wanted = {'id': 'an_id', 'title': 'A Title', 'description': '',
00270                   'url': '', 'category': 'object', 'visible': False,
00271                   'available': True, 'allowed': True}
00272 
00273         apb = self.site._setObject( 'portal_apb', self._makeProvider(1) )
00274         rval = apb.getActionInfo( ('object/an_id',) )
00275         self.assertEqual( rval, wanted )
00276         rval = apb.getActionInfo('object/an_id')
00277         self.assertEqual( rval, wanted )
00278         self.assertRaises( ValueError,
00279                            apb.getActionInfo,
00280                            'object/an_id', check_visibility=1 )
00281 
00282         # The following is nasty, but I want to make sure the ValueError
00283         # carries some useful information
00284         INVALID_ID = 'invalid_id'
00285         try:
00286             rval = apb.getActionInfo('object/%s' % INVALID_ID)
00287         except ValueError, e:
00288             message = e.args[0]
00289             detail = '"%s" does not offer action "%s"' % (message, INVALID_ID)
00290             self.failUnless(message.find(INVALID_ID) != -1, detail)
00291 

Here is the call graph for this function:

Definition at line 259 of file test_ActionProviderBase.py.

00259 
00260     def test_getActionObject(self):
00261         apb = self.site._setObject( 'portal_apb', self._makeProvider(1) )
00262         rval = apb.getActionObject('object/an_id')
00263         self.assertEqual(rval, apb._actions[0])
00264         rval = apb.getActionObject('object/not_existing_id')
00265         self.assertEqual(rval, None)
00266         self.assertRaises(ValueError, apb.getActionObject, 'wrong_format')

Here is the call graph for this function:

Definition at line 246 of file test_ActionProviderBase.py.

00246 
00247     def test_listActionInfos(self):
00248         wanted = [{'id': 'an_id', 'title': 'A Title', 'description': '',
00249                    'url': '', 'category': 'object', 'visible': False,
00250                    'available': True, 'allowed': True}]
00251 
00252         apb = self.site._setObject( 'portal_apb', self._makeProvider(1) )
00253         rval = apb.listActionInfos()
00254         self.assertEqual( rval, [] )
00255         rval = apb.listActionInfos(check_visibility=0)
00256         self.assertEqual( rval, wanted )
00257         rval = apb.listActionInfos('foo/another_id', check_visibility=0)
00258         self.assertEqual( rval, [] )

Here is the call graph for this function:

Definition at line 79 of file test_ActionProviderBase.py.

00079 
00080     def test_z2interfaces(self):
00081         from Interface.Verify import verifyClass
00082         from Products.CMFCore.interfaces.portal_actions \
00083                 import ActionProvider as IActionProvider
00084 
00085         verifyClass(IActionProvider, ActionProviderBase)

Definition at line 86 of file test_ActionProviderBase.py.

00086 
00087     def test_z3interfaces(self):
00088         from zope.interface.verify import verifyClass
00089         from Products.CMFCore.interfaces import IActionProvider
00090 
00091         verifyClass(IActionProvider, ActionProviderBase)


Member Data Documentation

Definition at line 66 of file test_ActionProviderBase.py.


The documentation for this class was generated from the following file: