Back to index

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

List of all members.

Public Member Functions

def afterSetUp
def addMember
def makeRealImage
def testNoMorePersonalFolder
def testGetPersonalFolderIfNoHome
def testGetPersonalPortrait
def testChangeMemberPortrait
def testDeletePersonalPortrait
def testGetPersonalPortraitWithoutPassingId
def testListMembers
def testListMembersSkipsGroups
def testListMemberIds
def testListMemberIdsSkipsGroups
def testCurrentPassword
def testSetPassword
def testSetPasswordIfAnonymous
def testSetPasswordAndKeepGroups
def testGetMemberById
def testGetMemberByIdIsWrapped
def testGetAuthenticatedMember
def testGetAuthenticatedMemberIsWrapped
def testGetAuthenticatedMemberIfAnonymous
def testAnonymousMemberIsNotWrapped
def testIsAnonymousUser
def testWrapUserWrapsBareUser
def testWrapUserWrapsWrappedUser
def testWrapUserDoesntWrapMemberData
def testWrapUserDoesntWrapAnonymous
def testWrapUserWrapsAnonymous
def testGetCandidateLocalRoles
def testSetLocalRoles
def testDeleteLocalRoles
def testGetHomeFolder
def testGetHomeUrl
def testGetAuthenticatedMemberInfo
def testGetMemberInfo
def testGetCandidateLocalRolesIncludesLocalRolesOnObjectForManager
def testGetCandidateLocalRolesIncludesLocalRolesOnObjectForAssignees
def testGetCandidateLocalRolesForManager
def testGetCandidateLocalRolesForOwner
def testGetCandidateLocalRolesForAssigned
def test_bug4333_delete_user_remove_memberdata
def testBogusMemberPortrait
def testGetBadMembers
def beforeTearDown
def setRequestMethod
def getAuthenticator
def setupAuthenticator

Public Attributes

 membership
 groups

Detailed Description

Definition at line 24 of file testMembershipTool.py.


Member Function Documentation

def CMFPlone.tests.testMembershipTool.TestMembershipTool.addMember (   self,
  username,
  fullname,
  email,
  roles,
  last_login_time 
)

Definition at line 31 of file testMembershipTool.py.

00031 
00032     def addMember(self, username, fullname, email, roles, last_login_time):
00033         self.membership.addMember(username, 'secret', roles, [])
00034         member = self.membership.getMemberById(username)
00035         member.setMemberProperties({'fullname': fullname, 'email': email,
                                    'last_login_time': DateTime(last_login_time),})

Here is the caller graph for this function:

Definition at line 26 of file testMembershipTool.py.

00026 
00027     def afterSetUp(self):
00028         self.membership = self.portal.portal_membership
00029         self.groups = self.portal.portal_groups
00030         self._trap_warning_output()

Definition at line 355 of file testMembershipTool.py.

00355 
00356     def beforeTearDown(self):
00357         self._free_warning_output()
00358 

Here is the call graph for this function:

Definition at line 30 of file PloneTestCase.py.

00030 
00031     def getAuthenticator(self):
00032         tag = AuthenticatorView('context', 'request').authenticator()
00033         pattern = '<input .*name="(\w+)".*value="(\w+)"'
00034         return match(pattern, tag).groups()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 36 of file testMembershipTool.py.

00036 
00037     def makeRealImage(self):
00038         import Products.CMFPlone as plone
00039         plone_path = os.path.dirname(plone.__file__)
00040         path = os.path.join(plone_path, 'tests', 'images', 'test.jpg')
00041         image = open(path, 'rb')
00042         image_upload = dummy.FileUpload(dummy.FieldStorage(image))
00043         return image_upload

Here is the caller graph for this function:

def CMFPlone.tests.PloneTestCase.PloneTestCase.setRequestMethod (   self,
  method 
) [inherited]
This is a stub now, but in case you want to try
   something fancy on Your Branch (tm), put it here.

Definition at line 26 of file PloneTestCase.py.

00026 
00027     def setRequestMethod(self, method):
00028         self.app.REQUEST.set('REQUEST_METHOD', method)
00029         self.app.REQUEST.method = method

Here is the caller graph for this function:

Definition at line 35 of file PloneTestCase.py.

00035 
00036     def setupAuthenticator(self):
00037         name, token = self.getAuthenticator()
00038         self.app.REQUEST.form[name] = token
00039 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 305 of file testMembershipTool.py.

00305 
00306     def test_bug4333_delete_user_remove_memberdata(self):
00307         # delete user should delete portal_memberdata
00308         memberdata = self.portal.portal_memberdata
00309         self.setRoles(['Manager'])
00310         self.addMember('barney', 'Barney Rubble', 'barney@bedrock.com', ['Member'], '2002-01-01')
00311         barney = self.membership.getMemberById('barney')
00312         self.failUnlessEqual(barney.getProperty('email'), 'barney@bedrock.com')
00313         del barney
00314 
00315         self.membership.deleteMembers(['barney'])
00316         md = memberdata._members
00317         self.failIf(md.has_key('barney'))
00318 
00319         # There is an _v_ variable that is killed at the end of each request
00320         # which stores a temporary version of the member object, this is
00321         # a problem in this test.  In fact, this test does not really
00322         # demonstrate the bug, which is actually caused by the script not
00323         # using the tool.
00324         memberdata._v_temps = None
00325 
00326         self.membership.addMember('barney', 'secret', ['Member'], [])
00327         barney = self.membership.getMemberById('barney')
00328         self.failIfEqual(barney.getProperty('fullname'), 'Barney Rubble')
00329         self.failIfEqual(barney.getProperty('email'), 'barney@bedrock.com')

Here is the call graph for this function:

Definition at line 181 of file testMembershipTool.py.

00181 
00182     def testAnonymousMemberIsNotWrapped(self):
00183         # Also see http://dev.plone.org/plone/ticket/1851
00184         self.logout()
00185         member = self.membership.getAuthenticatedMember()
00186         self.failIfEqual(member.__class__.__name__, 'MemberData')
00187         self.assertEqual(member.__class__.__name__, 'SpecialUser')

Here is the call graph for this function:

Definition at line 330 of file testMembershipTool.py.

00330 
00331     def testBogusMemberPortrait(self):
00332         # Should change the portrait image
00333         bad_file = dummy.File(data='<div>This is a lie!!!</div>',
00334                               headers={'content_type':'image/jpeg'})
00335         self.assertRaises(IOError, self.membership.changeMemberPortrait,
00336                           bad_file, default_user)

Definition at line 60 of file testMembershipTool.py.

00060 
00061     def testChangeMemberPortrait(self):
00062         # Should change the portrait image
00063         # first we need a valid image
00064         image = self.makeRealImage()
00065         self.membership.changeMemberPortrait(image, default_user)
00066         self.assertEqual(self.membership.getPersonalPortrait(default_user).getId(), default_user)
00067         self.assertEqual(self.membership.getPersonalPortrait(default_user).meta_type, 'Image')

Here is the call graph for this function:

Definition at line 115 of file testMembershipTool.py.

00115 
00116     def testCurrentPassword(self):
00117         # Password checking should work
00118         self.failUnless(self.membership.testCurrentPassword('secret'))
00119         self.failIf(self.membership.testCurrentPassword('geheim'))

Definition at line 241 of file testMembershipTool.py.

00241 
00242     def testDeleteLocalRoles(self):
00243         self.setRoles(['Member', 'Reviewer'])
00244         self.membership.setLocalRoles(self.folder, ['user2'], 'Reviewer')
00245         self.assertEqual(self.folder.get_local_roles_for_userid('user2'), ('Reviewer',))
00246         self.membership.deleteLocalRoles(self.folder, ['user2'])
00247         self.assertEqual(self.folder.get_local_roles_for_userid('user2'), ())

Here is the call graph for this function:

Definition at line 68 of file testMembershipTool.py.

00068 
00069     def testDeletePersonalPortrait(self):
00070         # Should delete the portrait image
00071         image = self.makeRealImage()
00072         self.membership.changeMemberPortrait(image, default_user)
00073         self.assertEqual(self.membership.getPersonalPortrait(default_user).getId(), default_user)
00074         self.membership.deletePersonalPortrait(default_user)
00075         self.assertEqual(self.membership.getPersonalPortrait(default_user).getId(), 'defaultUser.gif')

Here is the call graph for this function:

Definition at line 166 of file testMembershipTool.py.

00166 
00167     def testGetAuthenticatedMember(self):
00168         member = self.membership.getAuthenticatedMember()
00169         self.assertEqual(member.getUserName(), default_user)

Definition at line 176 of file testMembershipTool.py.

00176 
00177     def testGetAuthenticatedMemberIfAnonymous(self):
00178         self.logout()
00179         member = self.membership.getAuthenticatedMember()
00180         self.assertEqual(member.getUserName(), 'Anonymous User')

Here is the call graph for this function:

Definition at line 256 of file testMembershipTool.py.

00256 
00257     def testGetAuthenticatedMemberInfo(self):
00258         member = self.membership.getAuthenticatedMember()
00259         member.setMemberProperties({'fullname': 'Test user'})
00260         info = self.membership.getMemberInfo()
00261         self.assertEqual(info['fullname'], 'Test user')

Definition at line 170 of file testMembershipTool.py.

00170 
00171     def testGetAuthenticatedMemberIsWrapped(self):
00172         member = self.membership.getAuthenticatedMember()
00173         self.assertEqual(member.getUserName(), default_user)
00174         self.assertEqual(member.__class__.__name__, 'MemberData')
00175         self.assertEqual(member.aq_parent.__class__.__name__, 'PloneUser')

Definition at line 337 of file testMembershipTool.py.

00337 
00338     def testGetBadMembers(self):
00339         # Should list members with bad images
00340         # We should not have any bad images out of the box
00341         self.assertEqual(self.membership.getBadMembers(), [])
00342         # Let's add one
00343         bad_file = Image(id=default_user, title='',
00344                                file=StringIO('<div>This is a lie!!!</div>'))
00345         # Manually set a bad image using private methods
00346         self.portal.portal_memberdata._setPortrait(bad_file, default_user)
00347         self.assertEqual(self.membership.getBadMembers(), [default_user])
00348         # Try an empty image
00349         empty_file =  Image(id=default_user, title='', file=StringIO(''))
00350         self.portal.portal_memberdata._setPortrait(empty_file, default_user)
00351         self.assertEqual(self.membership.getBadMembers(), [])
00352         # And a good image
00353         self.membership.changeMemberPortrait(self.makeRealImage(), default_user)
00354         self.assertEqual(self.membership.getBadMembers(), [])

Here is the call graph for this function:

Definition at line 229 of file testMembershipTool.py.

00229 
00230     def testGetCandidateLocalRoles(self):
00231         self.assertEqual(self.membership.getCandidateLocalRoles(self.folder), ('Owner',))
00232         self.setRoles(['Member', 'Reviewer'])
00233         self.assertEqual(self.membership.getCandidateLocalRoles(self.folder), ('Owner', 'Reviewer'))

Here is the call graph for this function:

Definition at line 297 of file testMembershipTool.py.

00297 
00298     def testGetCandidateLocalRolesForAssigned(self):
00299         self.folder._addRole('my_test_role')
00300         self.folder.manage_setLocalRoles(default_user, ('Reviewer','Owner'))
00301         roles = self.membership.getCandidateLocalRoles(self.folder)
00302         self.failUnless('Owner' in roles)
00303         self.failUnless('Reviewer' in roles)
00304         self.assertEqual(len(roles), 2)

Here is the call graph for this function:

Definition at line 283 of file testMembershipTool.py.

00283 
00284     def testGetCandidateLocalRolesForManager(self):
00285         self.folder._addRole('my_test_role')
00286         self.folder.manage_setLocalRoles(default_user, ('Manager','Owner'))
00287         roles = self.membership.getCandidateLocalRoles(self.folder)
00288         self.failUnless('Manager' in roles)
00289         self.failUnless('Owner' in roles)
00290         self.failUnless('Reviewer' in roles)

Here is the call graph for this function:

Definition at line 291 of file testMembershipTool.py.

00291 
00292     def testGetCandidateLocalRolesForOwner(self):
00293         self.folder._addRole('my_test_role')
00294         roles = self.membership.getCandidateLocalRoles(self.folder)
00295         self.failUnless('Owner' in roles)
00296         self.assertEqual(len(roles), 1)

Here is the call graph for this function:

Definition at line 275 of file testMembershipTool.py.

00275 
00276     def testGetCandidateLocalRolesIncludesLocalRolesOnObjectForAssignees(self):
00277         self.folder._addRole('my_test_role')
00278         self.folder.manage_setLocalRoles(default_user, ('my_test_role','Owner'))
00279         roles = self.membership.getCandidateLocalRoles(self.folder)
00280         self.failUnless('Owner' in roles)
00281         self.failUnless('my_test_role' in roles)
00282         self.assertEqual(len(roles), 2)

Here is the call graph for this function:

Definition at line 268 of file testMembershipTool.py.

00268 
00269     def testGetCandidateLocalRolesIncludesLocalRolesOnObjectForManager(self):
00270         self.folder._addRole('my_test_role')
00271         self.folder.manage_setLocalRoles(default_user, ('Manager','Owner'))
00272         roles = self.membership.getCandidateLocalRoles(self.folder)
00273         self.failUnless('my_test_role' in roles,
00274                         'my_test_role not in: %s'%str(roles))

Here is the call graph for this function:

Definition at line 248 of file testMembershipTool.py.

00248 
00249     def testGetHomeFolder(self):
00250         self.failIfEqual(self.membership.getHomeFolder(), None)
00251         self.assertEqual(self.membership.getHomeFolder('user2'), None)

Definition at line 252 of file testMembershipTool.py.

00252 
00253     def testGetHomeUrl(self):
00254         self.failIfEqual(self.membership.getHomeUrl(), None)
00255         self.assertEqual(self.membership.getHomeUrl('user2'), None)

Definition at line 150 of file testMembershipTool.py.

00150 
00151     def testGetMemberById(self):
00152         # This should work for portal users,
00153         self.failIfEqual(self.membership.getMemberById(default_user), None)
00154         # return None for unknown users,
00155         self.assertEqual(self.membership.getMemberById('foo'), None)
00156         # and return None for users defined outside of the portal.
00157         ##self.assertEqual(self.membership.getMemberById(PloneTestCase.portal_owner), None)
00158         # Since CMF 1.5.2 the membershiptool will search "up"
00159         self.failIfEqual(self.membership.getMemberById(PloneTestCase.portal_owner), None)

Definition at line 160 of file testMembershipTool.py.

00160 
00161     def testGetMemberByIdIsWrapped(self):
00162         member = self.membership.getMemberById(default_user)
00163         self.failIfEqual(member, None)
00164         self.assertEqual(member.__class__.__name__, 'MemberData')
00165         self.assertEqual(member.aq_parent.__class__.__name__, 'PloneUser')

Definition at line 262 of file testMembershipTool.py.

00262 
00263     def testGetMemberInfo(self):
00264         self.membership.addMember('user2', 'secret', ['Member'], [],
00265                                   properties={'fullname': 'Second user'})
00266         info = self.membership.getMemberInfo('user2')
00267         self.assertEqual(info['fullname'], 'Second user')

Definition at line 50 of file testMembershipTool.py.

00050 
00051     def testGetPersonalFolderIfNoHome(self):
00052         # Should return None as the user has no home folder
00053         members = self.membership.getMembersFolder()
00054         members._delObject(default_user)
00055         self.assertEqual(self.membership.getPersonalFolder(default_user), None)

Definition at line 56 of file testMembershipTool.py.

00056 
00057     def testGetPersonalPortrait(self):
00058         # Should return the default portrait
00059         self.assertEqual(self.membership.getPersonalPortrait(default_user).getId(), 'defaultUser.gif')

Definition at line 76 of file testMembershipTool.py.

00076 
00077     def testGetPersonalPortraitWithoutPassingId(self):
00078         # Should return the logged in users portrait if no id is given
00079         image = self.makeRealImage()
00080         self.membership.changeMemberPortrait(image, default_user)
00081         self.assertEqual(self.membership.getPersonalPortrait().getId(), default_user)
00082         self.assertEqual(self.membership.getPersonalPortrait().meta_type, 'Image')

Here is the call graph for this function:

Definition at line 188 of file testMembershipTool.py.

00188 
00189     def testIsAnonymousUser(self):
00190         self.failIf(self.membership.isAnonymousUser())
00191         self.logout()
00192         self.failUnless(self.membership.isAnonymousUser())

Here is the call graph for this function:

Definition at line 99 of file testMembershipTool.py.

00099 
00100     def testListMemberIds(self):
00101         # Should return the members ids list
00102         memberids = self.membership.listMemberIds()
00103         self.assertEqual(len(memberids), 1)
00104         self.assertEqual(memberids[0], default_user)

Definition at line 105 of file testMembershipTool.py.

00105 
00106     def testListMemberIdsSkipsGroups(self):
00107         # Should only return real members, not groups
00108         uf = self.portal.acl_users
00109         self.groups.addGroup('Foo')
00110         self.groups.addGroup('Bar')
00111         self.assertEqual(len(uf.getUserNames()), 1)
00112         memberids = self.membership.listMemberIds()
00113         self.assertEqual(len(memberids), 1)
00114         self.assertEqual(memberids[0], default_user)

Definition at line 83 of file testMembershipTool.py.

00083 
00084     def testListMembers(self):
00085         # Should return the members list
00086         members = self.membership.listMembers()
00087         self.assertEqual(len(members), 1)
00088         self.assertEqual(members[0].getId(), default_user)

Definition at line 89 of file testMembershipTool.py.

00089 
00090     def testListMembersSkipsGroups(self):
00091         # Should only return real members, not groups
00092         uf = self.portal.acl_users
00093         self.groups.addGroup('Foo')
00094         self.groups.addGroup('Bar')
00095         self.assertEqual(len(uf.getUserNames()), 1)
00096         members = self.membership.listMembers()
00097         self.assertEqual(len(members), 1)
00098         self.assertEqual(members[0].getId(), default_user)

Definition at line 44 of file testMembershipTool.py.

00044 
00045     def testNoMorePersonalFolder(self):
00046         # .personal folders are history
00047         personal = getattr(self.folder, self.membership.personal_id, None)
00048         self.assertEqual(personal, None)
00049         self.assertEqual(self.membership.getPersonalFolder(default_user), None)

Here is the call graph for this function:

Definition at line 234 of file testMembershipTool.py.

00234 
00235     def testSetLocalRoles(self):
00236         self.failUnless('Owner' in self.folder.get_local_roles_for_userid(default_user))
00237         self.setRoles(['Member', 'Reviewer'])
00238         self.membership.setLocalRoles(self.folder, [default_user, 'user2'], 'Reviewer')
00239         self.assertEqual(self.folder.get_local_roles_for_userid(default_user), ('Owner', 'Reviewer'))
00240         self.assertEqual(self.folder.get_local_roles_for_userid('user2'), ('Reviewer',))

Here is the call graph for this function:

Definition at line 120 of file testMembershipTool.py.

00120 
00121     def testSetPassword(self):
00122         # Password should be changed
00123         self.membership.setPassword('geheim')
00124         self.failUnless(self.membership.testCurrentPassword('geheim'))

Definition at line 137 of file testMembershipTool.py.

00137 
00138     def testSetPasswordAndKeepGroups(self):
00139         # Password should be changed and user must not change group membership
00140         group2 = 'g2'
00141         groups = self.groups
00142         groups.addGroup(group2, None, [], [])
00143         group = groups.getGroupById(group2)
00144         self.loginAsPortalOwner() # GRUF 3.52
00145         group.addMember(default_user)
00146         self.login(default_user) # Back to normal
00147         ugroups = self.portal.acl_users.getUserById(default_user).getGroups()
00148         self.membership.setPassword('geheim')
00149         self.failUnless(self.portal.acl_users.getUserById(default_user).getGroups() == ugroups)

Here is the call graph for this function:

Definition at line 125 of file testMembershipTool.py.

00125 
00126     def testSetPasswordIfAnonymous(self):
00127         # Anonymous should not be able to change password
00128         self.logout()
00129         try:
00130             self.membership.setPassword('geheim')
00131         except BadRequest:
00132             import sys; e, v, tb = sys.exc_info(); del tb
00133             if str(v) == 'Not logged in.':
00134                 pass
00135             else:
00136                 raise

Here is the call graph for this function:

Definition at line 218 of file testMembershipTool.py.

00218 
00219     def testWrapUserDoesntWrapAnonymous(self):
00220         user = self.membership.wrapUser(nobody)
00221         self.assertEqual(user.__class__.__name__, 'SpecialUser')

Definition at line 212 of file testMembershipTool.py.

00212 
00213     def testWrapUserDoesntWrapMemberData(self):
00214         user = self.portal.acl_users.getUserById(default_user)
00215         user.getMemberId = lambda x: 1
00216         user = self.membership.wrapUser(user)
00217         self.assertEqual(user.__class__.__name__, 'PloneUser')

Definition at line 222 of file testMembershipTool.py.

00222 
00223     def testWrapUserWrapsAnonymous(self):
00224         self.failIf(hasattr(nobody, 'aq_base'))
00225         user = self.membership.wrapUser(nobody, wrap_anon=1)
00226         self.assertEqual(user.__class__.__name__, 'MemberData')
00227         self.assertEqual(user.aq_parent.__class__.__name__, 'SpecialUser')
00228         self.assertEqual(user.aq_parent.aq_parent.__class__.__name__, 'PluggableAuthService')

Definition at line 193 of file testMembershipTool.py.

00193 
00194     def testWrapUserWrapsBareUser(self):
00195         user = self.portal.acl_users.getUserById(default_user)
00196         # TODO: GRUF users are wrapped
00197         self.failUnless(hasattr(user, 'aq_base'))
00198         user = aq_base(user)
00199         user = self.membership.wrapUser(user)
00200         self.assertEqual(user.__class__.__name__, 'MemberData')
00201         self.assertEqual(user.aq_parent.__class__.__name__, 'PloneUser')
00202         self.assertEqual(user.aq_parent.aq_parent.__class__.__name__, 'PluggableAuthService')

Definition at line 203 of file testMembershipTool.py.

00203 
00204     def testWrapUserWrapsWrappedUser(self):
00205         user = self.portal.acl_users.getUserById(default_user)
00206         # TODO: GRUF users are wrapped
00207         self.failUnless(hasattr(user, 'aq_base'))
00208         user = self.membership.wrapUser(user)
00209         self.assertEqual(user.__class__.__name__, 'MemberData')
00210         self.assertEqual(user.aq_parent.__class__.__name__, 'PloneUser')
00211         self.assertEqual(user.aq_parent.aq_parent.__class__.__name__, 'PluggableAuthService')


Member Data Documentation

Definition at line 28 of file testMembershipTool.py.

Definition at line 27 of file testMembershipTool.py.


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