Back to index

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

List of all members.

Public Member Functions

def test_empty
def test_addGroup
def test_addGroup_exists
def test_updateGroup_normal
def test_addPrincipalToGroup
def test_addPrincipalToGroupThenRemovePrincipal
def test_removePrincipalFromGroup
def test_removeGroupOutFromUnderPrincipal
def test_multiplePrincipalsPerGroup
def test_enumerateGroups_exact_nonesuch
def test_enumerateGroups_multiple
def test_enumerateGroups_prefixed
def test_addPrincipalToGroup
def testPOSTProtections

Private Member Functions

def _getTargetClass
def _makeOne

Detailed Description

Definition at line 36 of file test_ZODBGroupManager.py.


Member Function Documentation

Definition at line 38 of file test_ZODBGroupManager.py.

00038 
00039     def _getTargetClass( self ):
00040 
00041         from Products.PluggableAuthService.plugins.ZODBGroupManager \
00042             import ZODBGroupManager
00043 
00044         return ZODBGroupManager

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

Definition at line 45 of file test_ZODBGroupManager.py.

00045 
00046     def _makeOne( self, id='test', *args, **kw ):
00047 
00048         return self._getTargetClass()( id=id, *args, **kw )

Definition at line 60 of file test_ZODBGroupManager.py.

00060 
00061     def test_addGroup( self ):
00062 
00063         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00064             import FauxRoot
00065 
00066         root = FauxRoot()
00067         zgm = self._makeOne().__of__( root )
00068 
00069         zgm.addGroup( 'group' )
00070 
00071         group_ids = zgm.listGroupIds()
00072         self.assertEqual( len( group_ids ), 1 )
00073         self.assertEqual( group_ids[0], 'group' )
00074 
00075         info_list = zgm.enumerateGroups()
00076         self.assertEqual( len( info_list ), 1 )
00077         info = info_list[ 0 ]
00078         self.assertEqual( info[ 'id' ], 'group' )

Definition at line 79 of file test_ZODBGroupManager.py.

00079 
00080     def test_addGroup_exists( self ):
00081 
00082         zgm = self._makeOne()
00083 
00084         zgm.addGroup( 'group' )
00085         self.assertRaises( KeyError, zgm.addGroup, 'group' )

Definition at line 98 of file test_ZODBGroupManager.py.

00098 
00099     def test_addPrincipalToGroup( self ):
00100 
00101         zgm = self._makeOne()
00102 
00103         zgm.addGroup( 'group' )
00104 
00105         user = DummyUser( 'userid' )
00106 
00107         zgm.addPrincipalToGroup( user.getId(), 'group' )
00108         groups = zgm.getGroupsForPrincipal( user )
00109         self.assertEqual( groups, ( 'group', ) )

Here is the caller graph for this function:

Definition at line 255 of file test_ZODBGroupManager.py.

00255 
00256     def test_addPrincipalToGroup( self ):
00257 
00258         zgm = self._makeOne()
00259         zgm.prefix = 'prefixed_'
00260 
00261         zgm.addGroup( 'group' )
00262 
00263         user = DummyUser( 'userid' )
00264 
00265         zgm.addPrincipalToGroup( user.getId(), 'group' )
00266         groups = zgm.getGroupsForPrincipal( user )
00267         self.assertEqual( groups, ( 'prefixed_group', ) )

Definition at line 110 of file test_ZODBGroupManager.py.

00110 
00111     def test_addPrincipalToGroupThenRemovePrincipal( self ):
00112 
00113         root = FauxSmartPAS()
00114         root.user_ids['foo'] = 'foo'
00115 
00116         zgm = self._makeOne( id='groups' ).__of__( root )
00117 
00118         zgm.addGroup( 'group', 'group_title', 'group_desc' )
00119         self.assertEqual( len( zgm.listAssignedPrincipals( 'group' ) ), 0 )
00120 
00121         new = zgm.addPrincipalToGroup( 'foo', 'group' )
00122 
00123         self.failUnless( new )
00124 
00125         assigned = [x[1] for x in zgm.listAssignedPrincipals( 'group' )]
00126 
00127         self.assertEqual( len( assigned ), 1 )
00128         self.assertEqual( assigned[0], 'foo' )
00129 
00130         del root.user_ids['foo']
00131 
00132         assigned = [x[1] for x in zgm.listAssignedPrincipals( 'group' )]
00133 
00134         self.assertEqual( len( assigned ), 1 )
00135         self.assertEqual( assigned[0], '<foo: not found>' )

Definition at line 49 of file test_ZODBGroupManager.py.

00049 
00050     def test_empty( self ):
00051 
00052         zgm = self._makeOne()
00053 
00054         self.assertEqual( len( zgm.listGroupIds() ), 0 )
00055         self.assertEqual( len( zgm.enumerateGroups() ), 0 )
00056 
00057         user = DummyUser( 'userid' )
00058         groups = zgm.getGroupsForPrincipal( user )
00059         self.assertEqual( len( groups ), 0 )

Definition at line 185 of file test_ZODBGroupManager.py.

00185 
00186     def test_enumerateGroups_exact_nonesuch( self ):
00187 
00188         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00189             import FauxRoot
00190 
00191         root = FauxRoot()
00192         zgm = self._makeOne( id='exact_nonesuch' ).__of__( root )
00193 
00194         ID_LIST = ( 'foo', 'bar', 'baz', 'bam' )
00195 
00196         for id in ID_LIST:
00197 
00198             zgm.addGroup( id, 'Group %s' % id, 'This is group, %s' % id )
00199 
00200         self.assertEqual( zgm.enumerateGroups( id='qux', exact_match=True )
00201                         , () )

Definition at line 202 of file test_ZODBGroupManager.py.

00202 
00203     def test_enumerateGroups_multiple( self ):
00204 
00205         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00206             import FauxRoot
00207 
00208         root = FauxRoot()
00209         zrm = self._makeOne( id='partial' ).__of__( root )
00210 
00211         ID_LIST = ( 'foo', 'bar', 'baz', 'bam' )
00212 
00213         for id in ID_LIST:
00214 
00215             zrm.addGroup( id, 'Group %s' % id, 'This is group, %s' % id )
00216 
00217         info_list = zrm.enumerateGroups( id=ID_LIST, exact_match=False )
00218 
00219         self.assertEqual( len( info_list ), len( ID_LIST ) )
00220 
00221         for info in info_list:
00222             self.failUnless( info[ 'id' ] in ID_LIST )
00223 
00224         SUBSET = ID_LIST[:3]
00225 
00226         info_list = zrm.enumerateGroups( id=SUBSET, exact_match=False )
00227 
00228         self.assertEqual( len( info_list ), len( SUBSET ) )
00229 
00230         for info in info_list:
00231             self.failUnless( info[ 'id' ] in SUBSET )

Definition at line 232 of file test_ZODBGroupManager.py.

00232 
00233     def test_enumerateGroups_prefixed( self ):
00234 
00235         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00236             import FauxRoot
00237 
00238         root = FauxRoot()
00239         zrm = self._makeOne( id='prefixed' ).__of__( root )
00240         zrm.prefix = 'prefixed_'
00241 
00242         ID_LIST = ( 'foo', 'bar', 'baz', 'bam' )
00243         PRE_LIST = tuple(['prefixed_%s' % x for x in ID_LIST])
00244 
00245         for id in ID_LIST:
00246 
00247             zrm.addGroup( id, 'Group %s' % id, 'This is group, %s' % id )
00248 
00249         info_list = zrm.enumerateGroups()
00250 
00251         self.assertEqual( len( info_list ), len( ID_LIST ) )
00252 
00253         for info in info_list:
00254             self.failUnless( info[ 'id' ] in PRE_LIST )

Definition at line 164 of file test_ZODBGroupManager.py.

00164 
00165     def test_multiplePrincipalsPerGroup( self ):
00166 
00167         pas = FauxPAS()
00168         zgm = self._makeOne().__of__( pas )
00169         
00170         zgm.addGroup( 'group1' )
00171         zgm.addGroup( 'group2' )
00172 
00173         user1 = DummyUser( 'userid1' )
00174         user2 = DummyUser( 'userid2' )
00175         
00176         zgm.addPrincipalToGroup( user1.getId(), 'group1' )
00177         zgm.addPrincipalToGroup( user1.getId(), 'group2' )
00178         zgm.addPrincipalToGroup( user2.getId(), 'group2' )
00179 
00180         group_ids = zgm.listGroupIds()
00181         self.assertEqual( len( group_ids ), 2 )
00182         principals = zgm.listAssignedPrincipals( 'group2' )
00183         self.assertEqual( principals, [ ( 'userid1', 'userid1' ),
00184                                         ( 'userid2', 'userid2' ) ] )

Definition at line 149 of file test_ZODBGroupManager.py.

00149 
00150     def test_removeGroupOutFromUnderPrincipal( self ):
00151 
00152         zgm = self._makeOne()
00153 
00154         zgm.addGroup( 'group' )
00155 
00156         user = DummyUser( 'userid' )
00157         
00158         zgm.addPrincipalToGroup( user.getId(), 'group' )
00159         zgm.removeGroup( 'group' )
00160         group_ids = zgm.listGroupIds()
00161         self.assertEqual( len( group_ids ), 0 )
00162         groups = zgm.getGroupsForPrincipal( user )
00163         self.assertEqual( groups, () )

Definition at line 136 of file test_ZODBGroupManager.py.

00136 
00137     def test_removePrincipalFromGroup( self ):
00138 
00139         zgm = self._makeOne()
00140 
00141         zgm.addGroup( 'group' )
00142 
00143         user = DummyUser( 'userid' )
00144         
00145         zgm.addPrincipalToGroup( user.getId(), 'group' )
00146         zgm.removePrincipalFromGroup( user.getId(), 'group' )
00147         groups = zgm.getGroupsForPrincipal( user )
00148         self.assertEqual( groups, () )

Definition at line 86 of file test_ZODBGroupManager.py.

00086 
00087     def test_updateGroup_normal( self ):
00088 
00089         zgm = self._makeOne()
00090 
00091         zgm.addGroup( 'group', 'group_title', 'group_desc' )
00092 
00093         group_info = zgm.getGroupInfo( 'group' )
00094         self.assertEqual( group_info['title'], 'group_title' )
00095         zgm.updateGroup( 'group', 'group_title_changed', 'group_desc' )
00096         group_info = zgm.getGroupInfo( 'group' )
00097         self.assertEqual( group_info['title'], 'group_title_changed' )

Definition at line 268 of file test_ZODBGroupManager.py.

00268 
00269     def testPOSTProtections(self):
00270         from zExceptions import Forbidden
00271 
00272         USER_ID = 'testuser'
00273         GROUP_ID = 'testgroup'
00274 
00275         zgm = self._makeOne()
00276         zgm.prefix = 'prefixed_'
00277 
00278         zgm.addGroup( GROUP_ID )
00279         user = DummyUser( USER_ID )
00280 
00281         req, res = makeRequestAndResponse()
00282 
00283         # test addPrincipalToGroup
00284         # Fails with a GET
00285         req.set('REQUEST_METHOD', 'GET')
00286         self.assertRaises(Forbidden, zgm.addPrincipalToGroup,
00287                           USER_ID, GROUP_ID, REQUEST=req)
00288         # Works with a POST
00289         req.set('REQUEST_METHOD', 'POST')
00290         zgm.addPrincipalToGroup(USER_ID, GROUP_ID, REQUEST=req)
00291 
00292         # test removePrincipalFromGroup
00293         req.set('REQUEST_METHOD', 'GET')
00294         self.assertRaises(Forbidden, zgm.removePrincipalFromGroup,
00295                           USER_ID, GROUP_ID, REQUEST=req)
00296         # Works with a POST
00297         req.set('REQUEST_METHOD', 'POST')
00298         zgm.removePrincipalFromGroup(USER_ID, GROUP_ID, REQUEST=req)
00299 
00300         # test manage_addPrincipalsToGroup
00301         req.set('REQUEST_METHOD', 'GET')
00302         self.assertRaises(Forbidden, zgm.manage_addPrincipalsToGroup,
00303                           GROUP_ID, [USER_ID], REQUEST=req)
00304         req.set('REQUEST_METHOD', 'POST')
00305         zgm.manage_addPrincipalsToGroup(GROUP_ID, [USER_ID], REQUEST=req)
00306 
00307         # test manage_removePrincipalsFromGroup
00308         req.set('REQUEST_METHOD', 'GET')
00309         self.assertRaises(Forbidden, zgm.manage_removePrincipalsFromGroup,
00310                           GROUP_ID, [USER_ID], REQUEST=req)
00311         req.set('REQUEST_METHOD', 'POST')
00312         zgm.manage_removePrincipalsFromGroup(GROUP_ID, [USER_ID], REQUEST=req)
00313 
00314         # test manage_removeGroup
00315         req.set('REQUEST_METHOD', 'GET')
00316         self.assertRaises(Forbidden, zgm.manage_removeGroups,
00317                           [GROUP_ID], REQUEST=req)
00318         # Works with a POST
00319         req.set('REQUEST_METHOD', 'POST')
00320         zgm.manage_removeGroups([GROUP_ID], REQUEST=req)


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