Back to index

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

List of all members.

Public Member Functions

def test_getCandidateLocalRoles
def test_createMemberArea
def test_createMemberAreaCMFBTreeFolder
def test_createMemberArea_chained
def test_deleteMembers
def test_deleteMembersUnsupported
def test_getMemberById_nonesuch
def test_getMemberById_local
def test_getMemberById_nonlocal
def test_getMemberById_chained

Private Member Functions

def _makeOne
def _makeSite

Detailed Description

Definition at line 54 of file test_MembershipTool.py.


Member Function Documentation

Definition at line 56 of file test_MembershipTool.py.

00056 
00057     def _makeOne(self, *args, **kw):
00058         from Products.CMFCore.MembershipTool import MembershipTool
00059 
00060         return MembershipTool(*args, **kw)

def CMFCore.tests.test_MembershipTool.MembershipToolSecurityTests._makeSite (   self,
  parent = None 
) [private]

Definition at line 61 of file test_MembershipTool.py.

00061 
00062     def _makeSite(self, parent=None):
00063         if parent is None:
00064             parent = self.root
00065         site = DummySite( 'site' ).__of__( parent )
00066         site._setObject( 'portal_membership', self._makeOne() )
00067         return site

Here is the call graph for this function:

Definition at line 80 of file test_MembershipTool.py.

00080 
00081     def test_createMemberArea(self):
00082         site = self._makeSite()
00083         mtool = site.portal_membership
00084         members = site._setObject( 'Members', PortalFolder('Members') )
00085         acl_users = site._setObject( 'acl_users', DummyUserFolder() )
00086         wtool = site._setObject( 'portal_workflow', DummyTool() )
00087 
00088         # permission
00089         mtool.createMemberArea('user_foo')
00090         self.failIf( hasattr(members.aq_self, 'user_foo') )
00091         newSecurityManager(None, acl_users.user_bar)
00092         mtool.createMemberArea('user_foo')
00093         self.failIf( hasattr(members.aq_self, 'user_foo') )
00094         newSecurityManager(None, acl_users.user_foo)
00095         mtool.setMemberareaCreationFlag()
00096         mtool.createMemberArea('user_foo')
00097         self.failIf( hasattr(members.aq_self, 'user_foo') )
00098         newSecurityManager(None, acl_users.all_powerful_Oz)
00099         mtool.setMemberareaCreationFlag()
00100         mtool.createMemberArea('user_foo')
00101         self.failUnless( hasattr(members.aq_self, 'user_foo') )
00102 
00103         # default content
00104         f = members.user_foo
00105         ownership = acl_users.user_foo
00106         localroles = ( ( 'user_foo', ('Owner',) ), )
00107         self.assertEqual( f.getOwner(), ownership )
00108         self.assertEqual( f.get_local_roles(), localroles,
00109                           'CMF Collector issue #162 (LocalRoles broken): %s'
00110                           % str( f.get_local_roles() ) )

Here is the call graph for this function:

Definition at line 144 of file test_MembershipTool.py.

00144 
00145     def test_createMemberArea_chained(self):
00146         LOCAL_USER_ID = 'user_foo'
00147         NONLOCAL_USER_ID = 'user_bar'
00148 
00149         self.root._setObject( 'folder', Folder('folder') )
00150         site = self._makeSite( self.root.folder )
00151         mtool = site.portal_membership
00152         members = site._setObject( 'Members', PortalFolder('Members') )
00153         wtool = site._setObject( 'portal_workflow', DummyTool() )
00154 
00155         local_uf = DummyUserFolder()
00156         delattr( local_uf, NONLOCAL_USER_ID )
00157         acl_users = site._setObject('acl_users', local_uf)
00158 
00159         nonlocal_uf = DummyUserFolder()
00160         delattr( nonlocal_uf, LOCAL_USER_ID )
00161         self.root.folder._setObject('acl_users', nonlocal_uf)
00162 
00163         newSecurityManager(None, acl_users.all_powerful_Oz)
00164         mtool.createMemberArea( NONLOCAL_USER_ID )
00165         self.failUnless( hasattr(members.aq_self, NONLOCAL_USER_ID ) )
00166         mtool.createMemberArea( LOCAL_USER_ID )
00167         self.failUnless( hasattr(members.aq_self, LOCAL_USER_ID ) )

Here is the call graph for this function:

Definition at line 111 of file test_MembershipTool.py.

00111 
00112     def test_createMemberAreaCMFBTreeFolder(self):
00113         # Test member area creation if the toplevel "Members" folder is
00114         # a CMFBTreeFolder (http://www.zope.org/Collectors/CMF/441
00115         site = self._makeSite()
00116         mtool = site.portal_membership
00117         members = site._setObject( 'Members', CMFBTreeFolder('Members') )
00118         acl_users = site._setObject( 'acl_users', DummyUserFolder() )
00119         wtool = site._setObject( 'portal_workflow', DummyTool() )
00120 
00121         # permission
00122         mtool.createMemberArea('user_foo')
00123         self.failIf( hasattr(members.aq_self, 'user_foo') )
00124         newSecurityManager(None, acl_users.user_bar)
00125         mtool.createMemberArea('user_foo')
00126         self.failIf( hasattr(members.aq_self, 'user_foo') )
00127         newSecurityManager(None, acl_users.user_foo)
00128         mtool.setMemberareaCreationFlag()
00129         mtool.createMemberArea('user_foo')
00130         self.failIf( hasattr(members.aq_self, 'user_foo') )
00131         newSecurityManager(None, acl_users.all_powerful_Oz)
00132         mtool.setMemberareaCreationFlag()
00133         mtool.createMemberArea('user_foo')
00134         self.failUnless( hasattr(members.aq_self, 'user_foo') )
00135 
00136         # default content
00137         f = members.user_foo
00138         ownership = acl_users.user_foo
00139         localroles = ( ( 'user_foo', ('Owner',) ), )
00140         self.assertEqual( f.getOwner(), ownership )
00141         self.assertEqual( f.get_local_roles(), localroles,
00142                           'CMF Collector issue #162 (LocalRoles broken): %s'
00143                           % str( f.get_local_roles() ) )

Here is the call graph for this function:

Definition at line 168 of file test_MembershipTool.py.

00168 
00169     def test_deleteMembers(self):
00170         site = self._makeSite()
00171         sm = getSiteManager()
00172         sm.registerUtility(site, ISiteRoot)
00173         mtool = site.portal_membership
00174         members = site._setObject( 'Members', PortalFolder('Members') )
00175         acl_users = site._setObject( 'acl_users', DummyUserFolder() )
00176         mdtool = site._setObject( 'portal_memberdata', MemberDataTool() )
00177         newSecurityManager(None, acl_users.all_powerful_Oz)
00178 
00179         self.assertEqual( acl_users.getUserById('user_foo'),
00180                           acl_users.user_foo )
00181         mtool.createMemberArea('user_foo')
00182         self.failUnless( hasattr(members.aq_self, 'user_foo') )
00183         mdtool.registerMemberData('Dummy', 'user_foo')
00184         self.failUnless( mdtool._members.has_key('user_foo') )
00185 
00186         rval = mtool.deleteMembers( ('user_foo', 'user_baz') )
00187         self.assertEqual( rval, ('user_foo',) )
00188         self.failIf( acl_users.getUserById('user_foo', None) )
00189         self.failIf( mdtool._members.has_key('user_foo') )
00190         self.failIf( hasattr(members.aq_self, 'user_foo') )
00191 
00192         cleanUp()

Here is the call graph for this function:

Definition at line 193 of file test_MembershipTool.py.

00193 
00194     def test_deleteMembersUnsupported(self):
00195         # Quite a few user folders do not support the deletion API
00196         # http://www.zope.org/Collectors/CMF/481
00197         # Make sure we get the right exception
00198         site = self._makeSite()
00199         mtool = site.portal_membership
00200         members = site._setObject( 'Members', PortalFolder('Members') )
00201         acl_users = site._setObject( 'acl_users', DummyUserFolder() )
00202         utool = site._setObject( 'portal_url', DummyTool() )
00203         wtool = site._setObject( 'portal_workflow', DummyTool() )
00204         mdtool = site._setObject( 'portal_memberdata', MemberDataTool() )
00205         newSecurityManager(None, acl_users.all_powerful_Oz)
00206 
00207         self.assertEqual( acl_users.getUserById('user_foo'),
00208                           acl_users.user_foo )
00209         mtool.createMemberArea('user_foo')
00210         self.failUnless( hasattr(members.aq_self, 'user_foo') )
00211         mdtool.registerMemberData('Dummy', 'user_foo')
00212         self.failUnless( mdtool._members.has_key('user_foo') )
00213 
00214         # Fake an incompatible user folder by deleting the class method
00215         deletion_method = DummyUserFolder.userFolderDelUsers
00216         del DummyUserFolder.userFolderDelUsers
00217         self.assertRaises( NotImplementedError
00218                          , mtool.deleteMembers
00219                          , ('user_foo',)
00220                          )
00221         self.failUnless( acl_users.getUserById('user_foo', None) )
00222         self.failUnless( mdtool._members.has_key('user_foo') )
00223         self.failUnless( hasattr(members.aq_self, 'user_foo') )
00224 
00225         # Cleanup
00226         DummyUserFolder.userFolderDelUsers = deletion_method

Here is the call graph for this function:

Definition at line 68 of file test_MembershipTool.py.

00068 
00069     def test_getCandidateLocalRoles(self):
00070         site = self._makeSite()
00071         mtool = site.portal_membership
00072         acl_users = site._setObject( 'acl_users', DummyUserFolder() )
00073 
00074         newSecurityManager(None, acl_users.user_foo)
00075         rval = mtool.getCandidateLocalRoles(mtool)
00076         self.assertEqual( rval, ('Dummy',) )
00077         newSecurityManager(None, acl_users.all_powerful_Oz)
00078         rval = mtool.getCandidateLocalRoles(mtool)
00079         self.assertEqual( rval, ('Manager', 'Member', 'Owner', 'Reviewer') )

Here is the call graph for this function:

Definition at line 256 of file test_MembershipTool.py.

00256 
00257     def test_getMemberById_chained(self):
00258         LOCAL_USER_ID = 'user_foo'
00259         NONLOCAL_USER_ID = 'user_bar'
00260 
00261         self.root._setObject( 'folder', Folder( 'folder' ) )
00262         site = self._makeSite( self.root.folder )
00263         tool = site.portal_membership
00264 
00265         local_uf = DummyUserFolder()
00266         delattr( local_uf, NONLOCAL_USER_ID )
00267         site._setObject('acl_users', local_uf)
00268 
00269         nonlocal_uf = DummyUserFolder()
00270         delattr( nonlocal_uf, LOCAL_USER_ID )
00271         self.root.folder._setObject('acl_users', nonlocal_uf)
00272 
00273         local_member = tool.getMemberById(LOCAL_USER_ID)
00274         self.assertEqual(local_member.getId(), LOCAL_USER_ID)
00275 
00276         nonlocal_member = tool.getMemberById(NONLOCAL_USER_ID)
00277         self.assertEqual(nonlocal_member.getId(), NONLOCAL_USER_ID)
00278 

Here is the call graph for this function:

Definition at line 236 of file test_MembershipTool.py.

00236 
00237     def test_getMemberById_local(self):
00238         LOCAL_USER_ID = 'user_foo'
00239 
00240         self.root._setObject( 'folder', Folder('folder') )
00241         site = self._makeSite( self.root.folder )
00242         site._setObject( 'acl_users', DummyUserFolder() )
00243         tool = site.portal_membership
00244         member = tool.getMemberById( LOCAL_USER_ID)
00245         self.assertEqual( member.getId(), LOCAL_USER_ID )

Here is the call graph for this function:

Definition at line 227 of file test_MembershipTool.py.

00227 
00228     def test_getMemberById_nonesuch(self):
00229         INVALID_USER_ID = 'nonesuch'
00230 
00231         self.root._setObject( 'folder', Folder( 'folder' ) )
00232         site = self._makeSite( self.root.folder )
00233         tool = site.portal_membership
00234         site.acl_users = DummyUserFolder()
00235         self.assertEqual( None, tool.getMemberById( INVALID_USER_ID ) )

Here is the call graph for this function:

Definition at line 246 of file test_MembershipTool.py.

00246 
00247     def test_getMemberById_nonlocal(self):
00248         NONLOCAL_USER_ID = 'user_bar'
00249 
00250         self.root._setObject( 'folder', Folder( 'folder' ) )
00251         site = self._makeSite( self.root.folder )
00252         self.root.folder._setObject( 'acl_users', DummyUserFolder() )
00253         tool = site.portal_membership
00254         member = tool.getMemberById( NONLOCAL_USER_ID )
00255         self.assertEqual( member.getId(), NONLOCAL_USER_ID )

Here is the call graph for this function:


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