Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
PluggableAuthService.plugins.tests.test_DynamicGroupsPlugin.DynamicGroupsPlugin Class Reference
Inheritance diagram for PluggableAuthService.plugins.tests.test_DynamicGroupsPlugin.DynamicGroupsPlugin:
Inheritance graph
[legend]
Collaboration diagram for PluggableAuthService.plugins.tests.test_DynamicGroupsPlugin.DynamicGroupsPlugin:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_empty
def test_addGroup_simple
def test_addGroup_duplicate
def test_removeGroup_nonesuch
def test_removeGroup
def test_updateGroup_nonesuch
def test_updateGroup_simple
def test_updateGroup_partial
def test_enumerateGroups_all
def test_enumerateGroups_exact_list
def test_enumerateGroups_exact_one
def test_enumerateGroups_skip_inactive
def test_getGroupsForPrincipal_empty
def test_getGroupsForPrincipal_principal
def test_getGroupsForPrincipal_python
def test_getGroupsForPrincipal_request
def test_getGroupsForPrincipal_group
def test_getGroupsForPrincipal_plugin_nope
def test_getGroupsForPrincipal_plugin_ok
def test_enumerateGroups_matching_with_optional_prefix
def test_enumerateGroups_enumerating_with_optional_prefix
def test_getGroupsForPrincipal_optional_prefix
def testPOSTProtections

Private Member Functions

def _getTargetClass
def _makeOne

Detailed Description

Definition at line 55 of file test_DynamicGroupsPlugin.py.


Member Function Documentation

Definition at line 57 of file test_DynamicGroupsPlugin.py.

00057 
00058     def _getTargetClass( self ):
00059 
00060         from Products.PluggableAuthService.plugins.DynamicGroupsPlugin \
00061             import DynamicGroupsPlugin
00062 
00063         return DynamicGroupsPlugin

def PluggableAuthService.plugins.tests.test_DynamicGroupsPlugin.DynamicGroupsPlugin._makeOne (   self,
  id = 'test',
  args,
  kw 
) [private]

Definition at line 64 of file test_DynamicGroupsPlugin.py.

00064 
00065     def _makeOne( self, id='test', *args, **kw ):
00066 
00067         return self._getTargetClass()( id, *args, **kw )

Definition at line 94 of file test_DynamicGroupsPlugin.py.

00094 
00095     def test_addGroup_duplicate( self ):
00096 
00097         dpg = self._makeOne( 'adding_duplicate' )
00098 
00099         dpg.addGroup( 'everyone', 'python:True', 'title', 'description', True )
00100 
00101         self.assertRaises( KeyError
00102                          , dpg.addGroup
00103                          , 'everyone'
00104                          , 'python:False'
00105                          , 'other title'
00106                          , 'other descripton'
00107                          , False )
00108 
00109         self.assertEqual( len( dpg.listGroupInfo() ), 1 )
00110         info = dpg.listGroupInfo()[0]
00111 
00112         self.assertEqual( info[ 'id' ], 'everyone' )
00113         self.assertEqual( info[ 'predicate' ], 'python:True' )
00114         self.assertEqual( info[ 'title' ], 'title' )
00115         self.assertEqual( info[ 'description' ], 'description' )
00116         self.assertEqual( info[ 'active' ], True )

Definition at line 76 of file test_DynamicGroupsPlugin.py.

00076 
00077     def test_addGroup_simple( self ):
00078 
00079         dpg = self._makeOne( 'adding' )
00080 
00081         dpg.addGroup( 'everyone', 'python:True', 'title', 'description', True )
00082 
00083         self.assertEqual( len( dpg.listGroupIds() ), 1 )
00084         self.failUnless( 'everyone' in dpg.listGroupIds() )
00085 
00086         self.assertEqual( len( dpg.listGroupInfo() ), 1 )
00087         info = dpg.listGroupInfo()[0]
00088 
00089         self.assertEqual( info[ 'id' ], 'everyone' )
00090         self.assertEqual( info[ 'title' ], 'title' )
00091         self.assertEqual( info[ 'description' ], 'description' )
00092         self.assertEqual( info[ 'predicate' ], 'python:True' )
00093         self.assertEqual( info[ 'active' ], True )

Definition at line 68 of file test_DynamicGroupsPlugin.py.

00068 
00069     def test_empty( self ):
00070 
00071         dpg = self._makeOne( 'empty' )
00072 
00073         self.assertEqual( len( dpg.listGroupIds() ), 0 )
00074         self.assertEqual( len( dpg.listGroupInfo() ), 0 )
00075         self.assertEqual( len( dpg.enumerateGroups() ), 0 )

Definition at line 230 of file test_DynamicGroupsPlugin.py.

00230 
00231     def test_enumerateGroups_all( self ):
00232 
00233         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00234             import FauxRoot
00235 
00236         root = FauxRoot()
00237         dpg = self._makeOne( 'enumerating' ).__of__( root )
00238 
00239         dpg.addGroup( 'everyone', 'python:True', 'Everyone', '', True )
00240         dpg.addGroup( 'noone', 'python:False', active=True )
00241         dpg.addGroup( 'hohum', 'nothing', active=True )
00242 
00243         info_list = dpg.enumerateGroups()
00244 
00245         self.assertEqual( len( info_list ), 3 )
00246 
00247         ids = [ x[ 'id' ] for x in info_list ]
00248 
00249         self.failUnless( 'everyone' in ids )
00250         self.failUnless( 'noone' in ids )
00251         self.failUnless( 'hohum' in ids )

Definition at line 444 of file test_DynamicGroupsPlugin.py.

00444 
00445     def test_enumerateGroups_enumerating_with_optional_prefix( self ):
00446 
00447         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00448             import FauxRoot
00449 
00450         root = FauxRoot()
00451         dpg = self._makeOne( 'enumerating' ).__of__( root )
00452         dpg.prefix = 'enumerating_'
00453 
00454         dpg.addGroup( 'everyone', 'python:True', 'Everyone', '', True )
00455         dpg.addGroup( 'noone', 'python:False', active=True )
00456         dpg.addGroup( 'hohum', 'nothing', active=True )
00457 
00458         ID_LIST = ( 'enumerating_everyone', 'enumerating_noone',
00459                     'enumerating_hohum' )
00460 
00461         info_list = dpg.enumerateGroups()
00462 
00463         self.assertEqual( len( info_list ), len( ID_LIST ) )
00464 
00465         ids = [ x[ 'id' ] for x in info_list ]
00466 
00467         for id in ID_LIST:
00468             self.failUnless( id in ids )

Definition at line 252 of file test_DynamicGroupsPlugin.py.

00252 
00253     def test_enumerateGroups_exact_list( self ):
00254 
00255         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00256             import FauxRoot
00257 
00258         root = FauxRoot()
00259         dpg = self._makeOne( 'enumerating' ).__of__( root )
00260 
00261         dpg.addGroup( 'everyone', 'python:True', 'Everyone', '', True )
00262         dpg.addGroup( 'noone', 'python:False', active=True )
00263         dpg.addGroup( 'hohum', 'nothing', active=True )
00264 
00265         ID_LIST = ( 'everyone', 'noone' )
00266 
00267         info_list = dpg.enumerateGroups( id=ID_LIST, exact_match=True )
00268 
00269         self.assertEqual( len( info_list ), len( ID_LIST ) )
00270 
00271         ids = [ x[ 'id' ] for x in info_list ]
00272 
00273         for id in ID_LIST:
00274             self.failUnless( id in ids )

Definition at line 275 of file test_DynamicGroupsPlugin.py.

00275 
00276     def test_enumerateGroups_exact_one( self ):
00277 
00278         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00279             import FauxRoot
00280 
00281         root = FauxRoot()
00282         dpg = self._makeOne( 'enumerating' ).__of__( root )
00283 
00284         dpg.addGroup( 'everyone', 'python:True', 'Everyone', '', True )
00285         dpg.addGroup( 'noone', 'python:False', active=True )
00286         dpg.addGroup( 'hohum', 'nothing', active=True )
00287 
00288         info_list = dpg.enumerateGroups( id='noone', exact_match=True )
00289 
00290         self.assertEqual( len( info_list ), 1 )
00291         info = info_list[ 0 ]
00292 
00293         self.assertEqual( info[ 'id' ], 'noone' )
00294         self.assertEqual( info[ 'title' ], '' )
00295         self.assertEqual( info[ 'description' ], '' )
00296         self.assertEqual( info[ 'active' ], True )
00297         self.assertEqual( info[ 'predicate' ], 'python:False' )
00298         self.assertEqual( info[ 'pluginid' ], 'enumerating' )
00299 
00300         # Because teher is no proper REQUEST, the properties_url will be incorrect
00301         # It should normally be  '/enumerating/noone/manage_propertiesForm'
00302         # But it will be '//noone/manage_propertiesForm'
00303         URL = '//noone/manage_propertiesForm'
00304         self.assertEqual( info[ 'properties_url' ], URL )
00305         self.assertEqual( info[ 'members_url' ], URL )

Definition at line 420 of file test_DynamicGroupsPlugin.py.

00420 
00421     def test_enumerateGroups_matching_with_optional_prefix( self ):
00422 
00423         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00424             import FauxRoot
00425 
00426         root = FauxRoot()
00427         dpg = self._makeOne( 'enumerating' ).__of__( root )
00428         dpg.prefix = 'enumerating_'
00429 
00430         dpg.addGroup( 'everyone', 'python:True', 'Everyone', '', True )
00431         dpg.addGroup( 'noone', 'python:False', active=True )
00432         dpg.addGroup( 'hohum', 'nothing', active=True )
00433 
00434         ID_LIST = ( 'enumerating_everyone', )
00435 
00436         info_list = dpg.enumerateGroups( id=ID_LIST, exact_match=True )
00437 
00438         self.assertEqual( len( info_list ), len( ID_LIST ) )
00439 
00440         ids = [ x[ 'id' ] for x in info_list ]
00441 
00442         for id in ID_LIST:
00443             self.failUnless( id in ids )

Definition at line 306 of file test_DynamicGroupsPlugin.py.

00306 
00307     def test_enumerateGroups_skip_inactive( self ):
00308 
00309         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00310             import FauxRoot
00311 
00312         root = FauxRoot()
00313         dpg = self._makeOne( 'enumerating' ).__of__( root )
00314 
00315         dpg.addGroup( 'everyone', 'python:True', 'Everyone', '', True )
00316         dpg.addGroup( 'noone', 'python:False', active=True )
00317         dpg.addGroup( 'inactive', 'nothing', active=False )
00318 
00319         info_list = dpg.enumerateGroups()
00320 
00321         self.assertEqual( len( info_list ), 2 )
00322 
00323         ids = [ x[ 'id' ] for x in info_list ]
00324 
00325         self.failUnless( 'everyone' in ids )
00326         self.failUnless( 'noone' in ids )
00327         self.failIf( 'inactive' in ids )

Definition at line 328 of file test_DynamicGroupsPlugin.py.

00328 
00329     def test_getGroupsForPrincipal_empty( self ):
00330 
00331         dpg = self._makeOne( 'ggp_request' )
00332         principal = FauxPrincipal( 'faux' )
00333 
00334         groups = dpg.getGroupsForPrincipal( principal )
00335 
00336         self.assertEqual( len( groups ), 0 )

Definition at line 378 of file test_DynamicGroupsPlugin.py.

00378 
00379     def test_getGroupsForPrincipal_group( self ):
00380 
00381         _setUpDefaultTraversable()
00382         dpg = self._makeOne( 'ggp_group' )
00383         principal = FauxPrincipal( 'faux' )
00384 
00385         dpg.addGroup( 'willing', 'group/willing' )
00386         dpg.willing._setProperty( 'willing', type='boolean', value=0 )
00387 
00388         groups = dpg.getGroupsForPrincipal( principal, {} )
00389         self.assertEqual( len( groups ), 0 )
00390 
00391         dpg.willing._updateProperty( 'willing', 1 )
00392         groups = dpg.getGroupsForPrincipal( principal, {} )
00393         self.assertEqual( len( groups ), 1 )
00394         self.failUnless( 'willing' in groups )

Definition at line 469 of file test_DynamicGroupsPlugin.py.

00469 
00470     def test_getGroupsForPrincipal_optional_prefix( self ):
00471 
00472         dpg = self._makeOne( 'ggp_prefixed' )
00473         dpg.prefix = 'ggp_'
00474 
00475         principal = FauxPrincipal( 'faux' )
00476 
00477         dpg.addGroup( 'effable', 'python:principal.getId().startswith("f")' )
00478         groups = dpg.getGroupsForPrincipal( principal, {} )
00479         self.assertEqual( len( groups ), 1 )
00480         self.failUnless( 'ggp_effable' in groups )

Definition at line 395 of file test_DynamicGroupsPlugin.py.

00395 
00396     def test_getGroupsForPrincipal_plugin_nope( self ):
00397 
00398         dpg = self._makeOne( 'ggp_plugin' )
00399         principal = FauxPrincipal( 'faux' )
00400 
00401         dpg.addGroup( 'scripted', 'python: plugin.callme(request)' )
00402         callme = FauxScript( 'callme', 0 )
00403         dpg._setOb( 'callme', callme )
00404 
00405         groups = dpg.getGroupsForPrincipal( principal, {} )
00406         self.assertEqual( len( groups ), 0 )

Definition at line 407 of file test_DynamicGroupsPlugin.py.

00407 
00408     def test_getGroupsForPrincipal_plugin_ok( self ):
00409 
00410         dpg = self._makeOne( 'ggp_plugin' )
00411         principal = FauxPrincipal( 'faux' )
00412 
00413         dpg.addGroup( 'scripted', 'python: plugin.callme(request)' )
00414         callme = FauxScript( 'callme', 1 )
00415         dpg._setOb( 'callme', callme )
00416 
00417         groups = dpg.getGroupsForPrincipal( principal, {} )
00418         self.assertEqual( len( groups ), 1 )
00419         self.failUnless( 'scripted' in groups )

Definition at line 337 of file test_DynamicGroupsPlugin.py.

00337 
00338     def test_getGroupsForPrincipal_principal( self ):
00339 
00340         dpg = self._makeOne( 'ggp_principal' )
00341         principal = FauxPrincipal( 'faux' )
00342 
00343         dpg.addGroup( 'effable', 'python:principal.getId().startswith("f")' )
00344         groups = dpg.getGroupsForPrincipal( principal, {} )
00345         self.assertEqual( len( groups ), 1 )
00346         self.failUnless( 'effable' in groups )

Definition at line 347 of file test_DynamicGroupsPlugin.py.

00347 
00348     def test_getGroupsForPrincipal_python( self ):
00349 
00350         dpg = self._makeOne( 'ggp_python' )
00351         principal = FauxPrincipal( 'faux' )
00352 
00353         dpg.addGroup( 'everyone', 'python:1' )
00354         groups = dpg.getGroupsForPrincipal( principal, {} )
00355         self.assertEqual( len( groups ), 1 )
00356         self.failUnless( 'everyone' in groups )

Definition at line 357 of file test_DynamicGroupsPlugin.py.

00357 
00358     def test_getGroupsForPrincipal_request( self ):
00359 
00360         _setUpDefaultTraversable()
00361         dpg = self._makeOne( 'ggp_request' )
00362         principal = FauxPrincipal( 'faux' )
00363 
00364         dpg.addGroup( 'local', 'request/is_local | nothing' )
00365 
00366         groups = dpg.getGroupsForPrincipal( principal, {} )
00367 
00368         self.assertEqual( len( groups ), 0 )
00369 
00370         groups = dpg.getGroupsForPrincipal( principal, { 'is_local' : 0 } )
00371 
00372         self.assertEqual( len( groups ), 0 )
00373 
00374         groups = dpg.getGroupsForPrincipal( principal, { 'is_local' : 1 } )
00375 
00376         self.assertEqual( len( groups ), 1 )
00377         self.failUnless( 'local' in groups )

Definition at line 123 of file test_DynamicGroupsPlugin.py.

00123 
00124     def test_removeGroup( self ):
00125 
00126         dpg = self._makeOne( 'removing' )
00127 
00128         dpg.addGroup( 'everyone', predicate='python:True' )
00129         dpg.addGroup( 'beast', predicate='python:666' )
00130         dpg.addGroup( 'noone', predicate='python:False' )
00131 
00132         self.assertEqual( len( dpg.listGroupIds() ), 3 )
00133         self.failUnless( 'everyone' in dpg.listGroupIds() )
00134         self.failUnless( 'beast' in dpg.listGroupIds() )
00135         self.failUnless( 'noone' in dpg.listGroupIds() )
00136 
00137         info_list = dpg.listGroupInfo()
00138         self.assertEqual( len( info_list ), 3 )
00139 
00140         ids = [ x[ 'id' ] for x in info_list ]
00141         self.failUnless( 'everyone' in ids )
00142         self.failUnless( 'beast' in ids )
00143         self.failUnless( 'noone' in ids )
00144 
00145         dpg.removeGroup( 'beast' )
00146 
00147         self.assertEqual( len( dpg.listGroupIds() ), 2 )
00148         self.failUnless( 'everyone' in dpg.listGroupIds() )
00149         self.failIf( 'beast' in dpg.listGroupIds() )
00150         self.failUnless( 'noone' in dpg.listGroupIds() )
00151 
00152         info_list = dpg.listGroupInfo()
00153         self.assertEqual( len( info_list ), 2 )
00154 
00155         ids = [ x[ 'id' ] for x in info_list ]
00156         self.failUnless( 'everyone' in ids )
00157         self.failIf( 'beast' in ids )
00158         self.failUnless( 'noone' in ids )

Definition at line 117 of file test_DynamicGroupsPlugin.py.

00117 
00118     def test_removeGroup_nonesuch( self ):
00119 
00120         dpg = self._makeOne( 'removing_nonesuch' )
00121 
00122         self.assertRaises( KeyError, dpg.removeGroup, 'everyone' )

Definition at line 159 of file test_DynamicGroupsPlugin.py.

00159 
00160     def test_updateGroup_nonesuch( self ):
00161 
00162         dpg = self._makeOne( 'updating_nonesuch' )
00163 
00164         self.assertRaises( KeyError, dpg.updateGroup
00165                          , 'everyone', 'title', True )

Definition at line 198 of file test_DynamicGroupsPlugin.py.

00198 
00199     def test_updateGroup_partial( self ):
00200 
00201         dpg = self._makeOne( 'updating_partial' )
00202 
00203         dpg.addGroup( 'everyone', 'python:True', 'title', 'description', True )
00204 
00205         self.assertEqual( len( dpg.listGroupIds() ), 1 )
00206         self.failUnless( 'everyone' in dpg.listGroupIds() )
00207 
00208         self.assertEqual( len( dpg.listGroupInfo() ), 1 )
00209         info = dpg.listGroupInfo()[0]
00210 
00211         self.assertEqual( info[ 'id' ], 'everyone' )
00212         self.assertEqual( info[ 'predicate' ], 'python:True' )
00213         self.assertEqual( info[ 'title' ], 'title' )
00214         self.assertEqual( info[ 'description' ], 'description' )
00215         self.assertEqual( info[ 'active' ], True )
00216 
00217         dpg.updateGroup( 'everyone', predicate='python:False' )
00218 
00219         self.assertEqual( len( dpg.listGroupIds() ), 1 )
00220         self.failUnless( 'everyone' in dpg.listGroupIds() )
00221 
00222         self.assertEqual( len( dpg.listGroupInfo() ), 1 )
00223         info = dpg.listGroupInfo()[0]
00224 
00225         self.assertEqual( info[ 'id' ], 'everyone' )
00226         self.assertEqual( info[ 'predicate' ], 'python:False' )
00227         self.assertEqual( info[ 'title' ], 'title' )
00228         self.assertEqual( info[ 'description' ], 'description' )
00229         self.assertEqual( info[ 'active' ], True )

Definition at line 166 of file test_DynamicGroupsPlugin.py.

00166 
00167     def test_updateGroup_simple( self ):
00168 
00169         dpg = self._makeOne( 'updating_simple' )
00170 
00171         dpg.addGroup( 'noone', predicate='python:False' )
00172 
00173         self.assertEqual( len( dpg.listGroupIds() ), 1 )
00174         self.failUnless( 'noone' in dpg.listGroupIds() )
00175 
00176         self.assertEqual( len( dpg.listGroupInfo() ), 1 )
00177         info = dpg.listGroupInfo()[0]
00178 
00179         self.assertEqual( info[ 'id' ], 'noone' )
00180         self.assertEqual( info[ 'predicate' ], 'python:False' )
00181         self.assertEqual( info[ 'title' ], '' )
00182         self.assertEqual( info[ 'description' ], '' )
00183         self.assertEqual( info[ 'active' ], True )
00184 
00185         dpg.updateGroup( 'noone', 'python:True', 'title', 'description', False )
00186 
00187         self.assertEqual( len( dpg.listGroupIds() ), 1 )
00188         self.failUnless( 'noone' in dpg.listGroupIds() )
00189 
00190         self.assertEqual( len( dpg.listGroupInfo() ), 1 )
00191         info = dpg.listGroupInfo()[0]
00192 
00193         self.assertEqual( info[ 'id' ], 'noone' )
00194         self.assertEqual( info[ 'predicate' ], 'python:True' )
00195         self.assertEqual( info[ 'title' ], 'title' )
00196         self.assertEqual( info[ 'description' ], 'description' )
00197         self.assertEqual( info[ 'active' ], False )

Definition at line 481 of file test_DynamicGroupsPlugin.py.

00481 
00482     def testPOSTProtections(self):
00483         from zExceptions import Forbidden
00484 
00485         GROUP_ID = 'testgroup'
00486 
00487         dpg = self._makeOne( 'adding' )
00488 
00489         dpg.addGroup( GROUP_ID, 'python:True', 'title', 'description', True )
00490 
00491         req, res = makeRequestAndResponse()
00492 
00493         req.set('REQUEST_METHOD', 'GET')
00494 
00495         # Fails with a GET
00496         # test removeGroup
00497         req.set('REQUEST_METHOD', 'GET')
00498         self.assertRaises(Forbidden, dpg.removeGroup,
00499                           GROUP_ID, REQUEST=req)
00500         # Works with a POST
00501         req.set('REQUEST_METHOD', 'POST')
00502         dpg.removeGroup(GROUP_ID, REQUEST=req)


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