Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
PloneTestCase.testMembershipTool.TestMembershipTool Class Reference
Inheritance diagram for PloneTestCase.testMembershipTool.TestMembershipTool:
Inheritance graph
[legend]
Collaboration diagram for PloneTestCase.testMembershipTool.TestMembershipTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def testAddMember
def testAddMemberIfMemberExists
def testGetMemberById
def testListMemberIds
def testListMembers
def testGetAuthenticatedMember
def testGetAuthenticatedMemberIfAnonymous
def testIsAnonymousUser
def testSetPassword
def testSetPassword
def testSetPasswordIfAnonymous
def testWrapUserWrapsBareUser
def testWrapUserWrapsWrappedUser
def testWrapUserDoesntWrapMemberData
def testWrapUserWrapsAnonymous
def testWrapUserDoesntWrapAnonymous
def testGetPortalRoles
def testGetPortalRoles
def testSetRoleMapping
def testGetMappedRole
def testMemberareaCreationFlag
def testCreateMemberarea
def testCreateMemberareaIfDisabled
def testWrapUserCreatesMemberarea
def testCreateMemberarea
def testCreateMemberareaIfDisabled
def testWrapUserCreatesMemberarea
def testWrapUserDoesntCreateMemberarea
def testGetCandidateLocalRoles
def testSetLocalRoles
def testDeleteLocalRoles
def testGetHomeFolder
def testGetHomeUrl
def getPortal
def createMemberarea
def setRoles
def setGroups
def loginAsPortalOwner
def addProfile
def addProduct

Public Attributes

 membership

Static Public Attributes

 layer = layer.PloneSite

Detailed Description

Definition at line 27 of file testMembershipTool.py.


Member Function Documentation

def PloneTestCase.PloneTestCase.PloneTestCase.addProduct (   self,
  name 
) [inherited]
Quickinstalls a product into the site.

Definition at line 156 of file PloneTestCase.py.

00156 
00157     def addProduct(self, name):
00158         '''Quickinstalls a product into the site.'''
00159         sm = getSecurityManager()
00160         self.loginAsPortalOwner()
00161         try:
00162             qi = self.portal.portal_quickinstaller
00163             if not qi.isProductInstalled(name):
00164                 qi.installProduct(name)
00165                 self._refreshSkinData()
00166         finally:
00167             setSecurityManager(sm)
00168 

Here is the call graph for this function:

Here is the caller graph for this function:

def PloneTestCase.PloneTestCase.PloneTestCase.addProfile (   self,
  name 
) [inherited]
Imports an extension profile into the site.

Definition at line 134 of file PloneTestCase.py.

00134 
00135     def addProfile(self, name):
00136         '''Imports an extension profile into the site.'''
00137         sm = getSecurityManager()
00138         self.loginAsPortalOwner()
00139         try:
00140             installed = getattr(self.portal, '_installed_profiles', {})
00141             if not installed.has_key(name):
00142                 setup = self.portal.portal_setup
00143                 profile_id = 'profile-%s' % (name,)
00144                 if PLONE30:
00145                     setup.runAllImportStepsFromProfile(profile_id)
00146                 else:
00147                     saved = setup.getImportContextID()
00148                     try:
00149                         setup.setImportContext(profile_id)
00150                         setup.runAllImportSteps()
00151                     finally:
00152                         setup.setImportContext(saved)
00153                 self._refreshSkinData()
00154         finally:
00155             setSecurityManager(sm)

Here is the call graph for this function:

Definition at line 29 of file testMembershipTool.py.

00029 
00030     def afterSetUp(self):
00031         self.membership = self.portal.portal_membership
00032         self.membership.memberareaCreationFlag = 1
00033         self.membership.addMember('user2', 'secret', ['Member'], [])

def PloneTestCase.PloneTestCase.PloneTestCase.createMemberarea (   self,
  name 
) [inherited]
Creates a minimal memberarea.

Definition at line 96 of file PloneTestCase.py.

00096 
00097     def createMemberarea(self, name):
00098         '''Creates a minimal memberarea.'''
00099         _createHomeFolder(self.portal, name)

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the portal object.

   Do not call this method! Use the self.portal
   attribute to access the portal object from tests.

Definition at line 88 of file PloneTestCase.py.

00088 
00089     def getPortal(self):
00090         '''Returns the portal object.
00091 
00092            Do not call this method! Use the self.portal
00093            attribute to access the portal object from tests.
00094         '''
00095         return getattr(self.app, portal_name)

Here is the caller graph for this function:

Use if - AND ONLY IF - you need to manipulate
   the portal object itself.

Definition at line 122 of file PloneTestCase.py.

00122 
00123     def loginAsPortalOwner(self):
00124         '''Use if - AND ONLY IF - you need to manipulate
00125            the portal object itself.
00126         '''
00127         uf = self.app.acl_users
00128         user = uf.getUserById(portal_owner)
00129         if not hasattr(user, 'aq_base'):
00130             user = user.__of__(uf)
00131         newSecurityManager(None, user)

def PloneTestCase.PloneTestCase.PloneTestCase.setGroups (   self,
  groups,
  name = default_user 
) [inherited]
Changes the user's groups.

Definition at line 112 of file PloneTestCase.py.

00112 
00113     def setGroups(self, groups, name=default_user):
00114         '''Changes the user's groups.'''
00115         uf = self.portal.acl_users
00116         if PLONE25:
00117             uf.userSetGroups(name, utils.makelist(groups))
00118         else:
00119             uf._updateUser(name, groups=utils.makelist(groups))
00120         if name == getSecurityManager().getUser().getId():
00121             self.login(name)

Here is the call graph for this function:

Here is the caller graph for this function:

def PloneTestCase.PloneTestCase.PloneTestCase.setRoles (   self,
  roles,
  name = default_user 
) [inherited]
Changes the user's roles.

Definition at line 102 of file PloneTestCase.py.

00102 
00103     def setRoles(self, roles, name=default_user):
00104         '''Changes the user's roles.'''
00105         uf = self.portal.acl_users
00106         if PLONE25:
00107             uf.userFolderEditUser(name, None, utils.makelist(roles), [])
00108         else:
00109             uf._updateUser(name, roles=utils.makelist(roles))
00110         if name == getSecurityManager().getUser().getId():
00111             self.login(name)

Here is the call graph for this function:

Definition at line 34 of file testMembershipTool.py.

00034 
00035     def testAddMember(self):
00036         self.failUnless(self.portal.acl_users.getUserById('user2'))

Definition at line 37 of file testMembershipTool.py.

00037 
00038     def testAddMemberIfMemberExists(self):
00039         # Nothing should happen
00040         self.membership.addMember('user2', 'secret', ['Member'], [])
00041         self.failUnless(self.portal.acl_users.getUserById('user2'))

Definition at line 186 of file testMembershipTool.py.

00186 
00187         def testCreateMemberarea(self):
00188             # CMF 1.5 requires user2 to be logged in!
00189             self.login('user2')
00190             members = self.membership.getMembersFolder()
00191             self.failIf(hasattr(aq_base(members), 'user2'))
00192             self.membership.createMemberArea('user2')
00193             self.failUnless(hasattr(aq_base(members), 'user2'))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 213 of file testMembershipTool.py.

00213 
00214         def testCreateMemberarea(self):
00215             members = self.membership.getMembersFolder()
00216             self.failIf(hasattr(aq_base(members), 'user2'))
00217             self.membership.createMemberarea('user2')
00218             self.failUnless(hasattr(aq_base(members), 'user2'))

Here is the call graph for this function:

Definition at line 194 of file testMembershipTool.py.

00194 
00195         def testCreateMemberareaIfDisabled(self):
00196             # No longer works in CMF 1.5
00197             self.membership.setMemberareaCreationFlag() # toggle
00198             members = self.membership.getMembersFolder()
00199             self.failIf(hasattr(aq_base(members), 'user2'))
00200             self.membership.createMemberArea('user2')
00201             #self.failUnless(hasattr(aq_base(members), 'user2'))
00202             self.failIf(hasattr(aq_base(members), 'user2'))

Here is the caller graph for this function:

Definition at line 219 of file testMembershipTool.py.

00219 
00220         def testCreateMemberareaIfDisabled(self):
00221             # This should work even if the flag is off
00222             self.membership.setMemberareaCreationFlag() # toggle
00223             members = self.membership.getMembersFolder()
00224             self.failIf(hasattr(aq_base(members), 'user2'))
00225             self.membership.createMemberarea('user2')
00226             self.failUnless(hasattr(aq_base(members), 'user2'))

Here is the call graph for this function:

Definition at line 253 of file testMembershipTool.py.

00253 
00254     def testDeleteLocalRoles(self):
00255         self.setRoles(['Member', 'Reviewer'])
00256         self.membership.setLocalRoles(self.folder, ['user2'], 'Reviewer')
00257         self.assertEqual(self.folder.get_local_roles_for_userid('user2'), ('Reviewer',))
00258         self.membership.deleteLocalRoles(self.folder, ['user2'])
00259         self.assertEqual(self.folder.get_local_roles_for_userid('user2'), ())

Here is the call graph for this function:

Definition at line 62 of file testMembershipTool.py.

00062 
00063     def testGetAuthenticatedMember(self):
00064         member = self.membership.getAuthenticatedMember()
00065         self.assertEqual(member.getUserName(), default_user)

Definition at line 66 of file testMembershipTool.py.

00066 
00067     def testGetAuthenticatedMemberIfAnonymous(self):
00068         self.logout()
00069         member = self.membership.getAuthenticatedMember()
00070         self.assertEqual(member.getUserName(), 'Anonymous User')

Here is the call graph for this function:

Definition at line 241 of file testMembershipTool.py.

00241 
00242     def testGetCandidateLocalRoles(self):
00243         self.assertEqual(self.membership.getCandidateLocalRoles(self.folder), ('Owner',))
00244         self.setRoles(['Member', 'Reviewer'])
00245         self.assertEqual(self.membership.getCandidateLocalRoles(self.folder), ('Owner', 'Reviewer'))

Here is the call graph for this function:

Definition at line 260 of file testMembershipTool.py.

00260 
00261     def testGetHomeFolder(self):
00262         self.failIfEqual(self.membership.getHomeFolder(), None)
00263         self.assertEqual(self.membership.getHomeFolder('user2'), None)

Definition at line 264 of file testMembershipTool.py.

00264 
00265     def testGetHomeUrl(self):
00266         self.failIfEqual(self.membership.getHomeUrl(), None)
00267         self.assertEqual(self.membership.getHomeUrl('user2'), None)
00268 

Definition at line 169 of file testMembershipTool.py.

00169 
00170     def testGetMappedRole(self):
00171         self.membership.setRoleMapping('Reviewer', 'FooRole')
00172         self.assertEqual(self.membership.getMappedRole('Reviewer'), 'FooRole')

Definition at line 42 of file testMembershipTool.py.

00042 
00043     def testGetMemberById(self):
00044         user = self.membership.getMemberById(default_user)
00045         self.failIfEqual(user, None)
00046         self.assertEqual(user.__class__.__name__, 'MemberData')
00047         self.assertEqual(user.aq_parent.__class__.__name__, USERTYPE)

Definition at line 144 of file testMembershipTool.py.

00144 
00145         def testGetPortalRoles(self):
00146             roles = self.membership.getPortalRoles()
00147             self.assertEqual(len(roles), 7)
00148             self.failUnless('Manager' in roles)
00149             self.failUnless('Member' in roles)
00150             self.failUnless('Owner' in roles)
00151             self.failUnless('Reviewer' in roles)
00152             self.failUnless('Reader' in roles)
00153             self.failUnless('Editor' in roles)
00154             self.failUnless('Contributor' in roles)

Here is the caller graph for this function:

Definition at line 157 of file testMembershipTool.py.

00157 
00158         def testGetPortalRoles(self):
00159             roles = self.membership.getPortalRoles()
00160             self.assertEqual(len(roles), 4)
00161             self.failUnless('Manager' in roles)
00162             self.failUnless('Member' in roles)
00163             self.failUnless('Owner' in roles)
00164             self.failUnless('Reviewer' in roles)

Here is the call graph for this function:

Definition at line 71 of file testMembershipTool.py.

00071 
00072     def testIsAnonymousUser(self):
00073         self.failIf(self.membership.isAnonymousUser())
00074         self.logout()
00075         self.failUnless(self.membership.isAnonymousUser())

Here is the call graph for this function:

Definition at line 48 of file testMembershipTool.py.

00048 
00049     def testListMemberIds(self):
00050         ids = self.membership.listMemberIds()
00051         self.assertEqual(len(ids), 2)
00052         self.failUnless(default_user in ids)
00053         self.failUnless('user2' in ids)

Definition at line 54 of file testMembershipTool.py.

00054 
00055     def testListMembers(self):
00056         members = self.membership.listMembers()
00057         self.assertEqual(len(members), 2)
00058         self.assertEqual(members[0].__class__.__name__, 'MemberData')
00059         self.assertEqual(members[0].aq_parent.__class__.__name__, USERTYPE)
00060         self.assertEqual(members[1].__class__.__name__, 'MemberData')
00061         self.assertEqual(members[1].aq_parent.__class__.__name__, USERTYPE)

Definition at line 181 of file testMembershipTool.py.

00181 
00182     def testMemberareaCreationFlag(self):
00183         self.failUnless(self.membership.getMemberareaCreationFlag())

Definition at line 246 of file testMembershipTool.py.

00246 
00247     def testSetLocalRoles(self):
00248         self.failUnless('Owner' in self.folder.get_local_roles_for_userid(default_user))
00249         self.setRoles(['Member', 'Reviewer'])
00250         self.membership.setLocalRoles(self.folder, [default_user, 'user2'], 'Reviewer')
00251         self.assertEqual(self.folder.get_local_roles_for_userid(default_user), ('Owner', 'Reviewer'))
00252         self.assertEqual(self.folder.get_local_roles_for_userid('user2'), ('Reviewer',))

Here is the call graph for this function:

Definition at line 78 of file testMembershipTool.py.

00078 
00079         def testSetPassword(self):
00080             # PAS does not provide the password
00081             self.membership.setPassword('geheim')
00082             member = self.membership.getMemberById(default_user)
00083             #self.assertEqual(member.getPassword(), 'geheim')
00084             self.assertEqual(member.getPassword(), None)

Here is the caller graph for this function:

Definition at line 87 of file testMembershipTool.py.

00087 
00088         def testSetPassword(self):
00089             self.membership.setPassword('geheim')
00090             member = self.membership.getMemberById(default_user)
00091             self.assertEqual(member.getPassword(), 'geheim')

Here is the call graph for this function:

Definition at line 92 of file testMembershipTool.py.

00092 
00093     def testSetPasswordIfAnonymous(self):
00094         self.logout()
00095         try:
00096             self.membership.setPassword('geheim')
00097         except BadRequest:
00098             pass
00099         except:
00100             # String exceptions suck
00101             e,v,tb = sys.exc_info(); del tb
00102             if str(v) == 'Bad Request':
00103                 pass
00104         else:
00105             self.fail('Anonymous can change password')

Here is the call graph for this function:

Definition at line 165 of file testMembershipTool.py.

00165 
00166     def testSetRoleMapping(self):
00167         self.membership.setRoleMapping('Reviewer', 'FooRole')
00168         self.assertEqual(self.membership.role_map['Reviewer'], 'FooRole')

Definition at line 203 of file testMembershipTool.py.

00203 
00204         def testWrapUserCreatesMemberarea(self):
00205             # No longer the case in CMF 1.5
00206             members = self.membership.getMembersFolder()
00207             user = self.portal.acl_users.getUserById('user2')
00208             user = self.membership.wrapUser(user)
00209             #self.failUnless(hasattr(aq_base(members), 'user2'))
00210             self.failIf(hasattr(aq_base(members), 'user2'))

Here is the caller graph for this function:

Definition at line 227 of file testMembershipTool.py.

00227 
00228         def testWrapUserCreatesMemberarea(self):
00229             members = self.membership.getMembersFolder()
00230             user = self.portal.acl_users.getUserById('user2')
00231             user = self.membership.wrapUser(user)
00232             self.failUnless(hasattr(aq_base(members), 'user2'))

Here is the call graph for this function:

Definition at line 233 of file testMembershipTool.py.

00233 
00234     def testWrapUserDoesntCreateMemberarea(self):
00235         # No member area is created if the flag is off
00236         self.membership.setMemberareaCreationFlag()
00237         members = self.membership.getMembersFolder()
00238         user = self.portal.acl_users.getUserById('user2')
00239         user = self.membership.wrapUser(user)
00240         self.failIf(hasattr(aq_base(members), 'user2'))

Definition at line 138 of file testMembershipTool.py.

00138 
00139     def testWrapUserDoesntWrapAnonymous(self):
00140         user = self.membership.wrapUser(nobody)
00141         self.assertEqual(user.__class__.__name__, 'SpecialUser')

Definition at line 125 of file testMembershipTool.py.

00125 
00126     def testWrapUserDoesntWrapMemberData(self):
00127         user = self.portal.acl_users.getUserById(default_user)
00128         user.getMemberId = lambda x: 1
00129         user = self.membership.wrapUser(user)
00130         self.assertEqual(user.__class__.__name__, USERTYPE)

Definition at line 131 of file testMembershipTool.py.

00131 
00132     def testWrapUserWrapsAnonymous(self):
00133         self.failIf(hasattr(nobody, 'aq_base'))
00134         user = self.membership.wrapUser(nobody, wrap_anon=1)
00135         self.assertEqual(user.__class__.__name__, 'MemberData')
00136         self.assertEqual(user.aq_parent.__class__.__name__, 'SpecialUser')
00137         self.assertEqual(user.aq_parent.aq_parent.__class__.__name__, USERFOLDER)

Definition at line 106 of file testMembershipTool.py.

00106 
00107     def testWrapUserWrapsBareUser(self):
00108         user = self.portal.acl_users.getUserById(default_user)
00109         # XXX: GRUF users are wrapped
00110         self.failUnless(hasattr(user, 'aq_base'))
00111         user = aq_base(user)
00112         user = self.membership.wrapUser(user)
00113         self.assertEqual(user.__class__.__name__, 'MemberData')
00114         self.assertEqual(user.aq_parent.__class__.__name__, USERTYPE)
00115         self.assertEqual(user.aq_parent.aq_parent.__class__.__name__, USERFOLDER)

Definition at line 116 of file testMembershipTool.py.

00116 
00117     def testWrapUserWrapsWrappedUser(self):
00118         user = self.portal.acl_users.getUserById(default_user)
00119         # XXX: GRUF users are wrapped
00120         self.failUnless(hasattr(user, 'aq_base'))
00121         user = self.membership.wrapUser(user)
00122         self.assertEqual(user.__class__.__name__, 'MemberData')
00123         self.assertEqual(user.aq_parent.__class__.__name__, USERTYPE)
00124         self.assertEqual(user.aq_parent.aq_parent.__class__.__name__, USERFOLDER)


Member Data Documentation

Definition at line 65 of file PloneTestCase.py.

Definition at line 30 of file testMembershipTool.py.


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