Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
CMFTestCase.testMembershipTool.TestMembershipTool Class Reference
Inheritance diagram for CMFTestCase.testMembershipTool.TestMembershipTool:
Inheritance graph
[legend]
Collaboration diagram for CMFTestCase.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 testSetPasswordIfAnonymous
def testWrapUserWrapsBareUser
def testWrapUserWrapsWrappedUser
def testWrapUserDoesntWrapMemberData
def testWrapUserWrapsAnonymous
def testWrapUserDoesntWrapAnonymous
def testGetPortalRoles
def testSetRoleMapping
def testGetMappedRole
def testWrapUserMapsRoles
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 loginAsPortalOwner
def addProfile
def addProduct

Public Attributes

 membership

Static Public Attributes

 layer = layer.CMFSite

Detailed Description

Definition at line 21 of file testMembershipTool.py.


Member Function Documentation

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

Definition at line 145 of file CMFTestCase.py.

00145 
00146     def addProduct(self, name):
00147         '''Installs a product into the site.'''
00148         sm = getSecurityManager()
00149         self.loginAsPortalOwner()
00150         try:
00151             installed = getattr(self.portal, '_installed_products', {})
00152             if not installed.has_key(name):
00153                 exec 'from Products.%s.Extensions.Install import install' % (name,)
00154                 install(self.portal)
00155                 self._refreshSkinData()
00156         finally:
00157             setSecurityManager(sm)
00158 

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 123 of file CMFTestCase.py.

00123 
00124     def addProfile(self, name):
00125         '''Imports an extension profile into the site.'''
00126         sm = getSecurityManager()
00127         self.loginAsPortalOwner()
00128         try:
00129             installed = getattr(self.portal, '_installed_profiles', {})
00130             if not installed.has_key(name):
00131                 setup = self.portal.portal_setup
00132                 profile_id = 'profile-%s' % (name,)
00133                 if CMF21:
00134                     setup.runAllImportStepsFromProfile(profile_id)
00135                 else:
00136                     saved = setup.getImportContextID()
00137                     try:
00138                         setup.setImportContext(profile_id)
00139                         setup.runAllImportSteps()
00140                     finally:
00141                         setup.setImportContext(saved)
00142                 self._refreshSkinData()
00143         finally:
00144             setSecurityManager(sm)

Here is the call graph for this function:

Definition at line 23 of file testMembershipTool.py.

00023 
00024     def afterSetUp(self):
00025         self.membership = self.portal.portal_membership
00026         self.membership.addMember('user2', 'secret', ['Member'], [])

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

Definition at line 93 of file CMFTestCase.py.

00093 
00094     def createMemberarea(self, name):
00095         '''Creates a minimal memberarea.'''
00096         uf = self.portal.acl_users
00097         user = uf.getUserById(name)
00098         if user is None:
00099             raise ValueError, 'Member %s does not exist' % name
00100         if not hasattr(user, 'aq_base'):
00101             user = user.__of__(uf)
00102         pm = self.portal.portal_membership
00103         members = pm.getMembersFolder()
00104         members.manage_addPortalFolder(name)
00105         folder = pm.getHomeFolder(name)
00106         folder.changeOwnership(user)
00107         folder.__ac_local_roles__ = None
00108         folder.manage_setLocalRoles(name, ['Owner'])

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 85 of file CMFTestCase.py.

00085 
00086     def getPortal(self):
00087         '''Returns the portal object.
00088 
00089            Do not call this method! Use the self.portal
00090            attribute to access the portal object from tests.
00091         '''
00092         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 111 of file CMFTestCase.py.

00111 
00112     def loginAsPortalOwner(self):
00113         '''Use if - AND ONLY IF - you need to manipulate the
00114            portal object itself.
00115         '''
00116         uf = self.app.acl_users
00117         user = uf.getUserById(portal_owner)
00118         if not hasattr(user, 'aq_base'):
00119             user = user.__of__(uf)
00120         newSecurityManager(None, user)

Definition at line 27 of file testMembershipTool.py.

00027 
00028     def testAddMember(self):
00029         self.failUnless(self.portal.acl_users.getUserById('user2'))

Definition at line 30 of file testMembershipTool.py.

00030 
00031     def testAddMemberIfMemberExists(self):
00032         # Nothing should happen
00033         self.membership.addMember('user2', 'secret', ['Member'], [])
00034         self.failUnless(self.portal.acl_users.getUserById('user2'))

Definition at line 151 of file testMembershipTool.py.

00151 
00152         def testCreateMemberarea(self):
00153             # CMF 1.5 requires user2 to be logged in!
00154             self.login('user2')
00155             members = self.membership.getMembersFolder()
00156             self.failIf(hasattr(aq_base(members), 'user2'))
00157             self.membership.createMemberArea('user2')
00158             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 178 of file testMembershipTool.py.

00178 
00179         def testCreateMemberarea(self):
00180             members = self.membership.getMembersFolder()
00181             self.failIf(hasattr(aq_base(members), 'user2'))
00182             self.membership.createMemberarea('user2')
00183             self.failUnless(hasattr(aq_base(members), 'user2'))

Here is the call graph for this function:

Definition at line 159 of file testMembershipTool.py.

00159 
00160         def testCreateMemberareaIfDisabled(self):
00161             # No longer works in CMF 1.5
00162             self.membership.setMemberareaCreationFlag() # toggle
00163             members = self.membership.getMembersFolder()
00164             self.failIf(hasattr(aq_base(members), 'user2'))
00165             self.membership.createMemberArea('user2')
00166             #self.failUnless(hasattr(aq_base(members), 'user2'))
00167             self.failIf(hasattr(aq_base(members), 'user2'))

Here is the caller graph for this function:

Definition at line 184 of file testMembershipTool.py.

00184 
00185         def testCreateMemberareaIfDisabled(self):
00186             # This should work even if the flag is off
00187             self.membership.setMemberareaCreationFlag() # toggle
00188             members = self.membership.getMembersFolder()
00189             self.failIf(hasattr(aq_base(members), 'user2'))
00190             self.membership.createMemberarea('user2')
00191             self.failUnless(hasattr(aq_base(members), 'user2'))

Here is the call graph for this function:

Definition at line 218 of file testMembershipTool.py.

00218 
00219     def testDeleteLocalRoles(self):
00220         self.setRoles(['Member', 'Reviewer'])
00221         self.membership.setLocalRoles(self.folder, ['user2'], 'Reviewer')
00222         self.assertEqual(self.folder.get_local_roles_for_userid('user2'), ('Reviewer',))
00223         self.membership.deleteLocalRoles(self.folder, ['user2'])
00224         self.assertEqual(self.folder.get_local_roles_for_userid('user2'), ())

Here is the call graph for this function:

Definition at line 55 of file testMembershipTool.py.

00055 
00056     def testGetAuthenticatedMember(self):
00057         member = self.membership.getAuthenticatedMember()
00058         self.assertEqual(member.getUserName(), default_user)

Definition at line 59 of file testMembershipTool.py.

00059 
00060     def testGetAuthenticatedMemberIfAnonymous(self):
00061         self.logout()
00062         member = self.membership.getAuthenticatedMember()
00063         self.assertEqual(member.getUserName(), 'Anonymous User')

Here is the call graph for this function:

Definition at line 206 of file testMembershipTool.py.

00206 
00207     def testGetCandidateLocalRoles(self):
00208         self.assertEqual(self.membership.getCandidateLocalRoles(self.folder), ('Owner',))
00209         self.setRoles(['Member', 'Reviewer'])
00210         self.assertEqual(self.membership.getCandidateLocalRoles(self.folder), ('Owner', 'Reviewer'))

Here is the call graph for this function:

Definition at line 225 of file testMembershipTool.py.

00225 
00226     def testGetHomeFolder(self):
00227         self.failIfEqual(self.membership.getHomeFolder(), None)
00228         self.assertEqual(self.membership.getHomeFolder('user2'), None)

Definition at line 229 of file testMembershipTool.py.

00229 
00230     def testGetHomeUrl(self):
00231         self.failIfEqual(self.membership.getHomeUrl(), None)
00232         self.assertEqual(self.membership.getHomeUrl('user2'), None)
00233 

Definition at line 135 of file testMembershipTool.py.

00135 
00136     def testGetMappedRole(self):
00137         self.membership.setRoleMapping('Reviewer', 'FooRole')
00138         self.assertEqual(self.membership.getMappedRole('Reviewer'), 'FooRole')

Definition at line 35 of file testMembershipTool.py.

00035 
00036     def testGetMemberById(self):
00037         user = self.membership.getMemberById(default_user)
00038         self.failIfEqual(user, None)
00039         self.assertEqual(user.__class__.__name__, 'MemberData')
00040         self.assertEqual(user.aq_parent.__class__.__name__, 'User')

Definition at line 123 of file testMembershipTool.py.

00123 
00124     def testGetPortalRoles(self):
00125         roles = self.membership.getPortalRoles()
00126         self.assertEqual(len(roles), 4)
00127         self.failUnless('Manager' in roles)
00128         self.failUnless('Member' in roles)
00129         self.failUnless('Owner' in roles)
00130         self.failUnless('Reviewer' in roles)

Definition at line 64 of file testMembershipTool.py.

00064 
00065     def testIsAnonymousUser(self):
00066         self.failIf(self.membership.isAnonymousUser())
00067         self.logout()
00068         self.failUnless(self.membership.isAnonymousUser())

Here is the call graph for this function:

Definition at line 41 of file testMembershipTool.py.

00041 
00042     def testListMemberIds(self):
00043         ids = self.membership.listMemberIds()
00044         self.assertEqual(len(ids), 2)
00045         self.failUnless(default_user in ids)
00046         self.failUnless('user2' in ids)

Definition at line 47 of file testMembershipTool.py.

00047 
00048     def testListMembers(self):
00049         members = self.membership.listMembers()
00050         self.assertEqual(len(members), 2)
00051         self.assertEqual(members[0].__class__.__name__, 'MemberData')
00052         self.assertEqual(members[0].aq_parent.__class__.__name__, 'User')
00053         self.assertEqual(members[1].__class__.__name__, 'MemberData')
00054         self.assertEqual(members[1].aq_parent.__class__.__name__, 'User')

Definition at line 146 of file testMembershipTool.py.

00146 
00147     def testMemberareaCreationFlag(self):
00148         self.failUnless(self.membership.getMemberareaCreationFlag())

Definition at line 211 of file testMembershipTool.py.

00211 
00212     def testSetLocalRoles(self):
00213         self.failUnless('Owner' in self.folder.get_local_roles_for_userid(default_user))
00214         self.setRoles(['Member', 'Reviewer'])
00215         self.membership.setLocalRoles(self.folder, [default_user, 'user2'], 'Reviewer')
00216         self.assertEqual(self.folder.get_local_roles_for_userid(default_user), ('Owner', 'Reviewer'))
00217         self.assertEqual(self.folder.get_local_roles_for_userid('user2'), ('Reviewer',))

Here is the call graph for this function:

Definition at line 69 of file testMembershipTool.py.

00069 
00070     def testSetPassword(self):
00071         self.membership.setPassword('geheim')
00072         member = self.membership.getMemberById(default_user)
00073         auth = self.membership.getAuthenticatedMember()
00074         self.failUnless(pw_validate(member.getPassword(), 'geheim'))
00075         self.failUnless(pw_validate(auth.getPassword(), 'geheim'))

Definition at line 76 of file testMembershipTool.py.

00076 
00077     def testSetPasswordIfAnonymous(self):
00078         self.logout()
00079         try:
00080             self.membership.setPassword('geheim')
00081         except BadRequest:
00082             pass
00083         except:
00084             # String exceptions suck (but CMF < 1.5 has them)
00085             e,v,tb = sys.exc_info(); del tb
00086             if str(e) != 'Bad Request':
00087                 raise
00088         else:
00089             self.fail('Anonymous can change password')

Here is the call graph for this function:

Definition at line 131 of file testMembershipTool.py.

00131 
00132     def testSetRoleMapping(self):
00133         self.membership.setRoleMapping('Reviewer', 'FooRole')
00134         self.assertEqual(self.membership.role_map['Reviewer'], 'FooRole')

Definition at line 168 of file testMembershipTool.py.

00168 
00169         def testWrapUserCreatesMemberarea(self):
00170             # No longer the case in CMF 1.5
00171             members = self.membership.getMembersFolder()
00172             user = self.portal.acl_users.getUserById('user2')
00173             user = self.membership.wrapUser(user)
00174             #self.failUnless(hasattr(aq_base(members), 'user2'))
00175             self.failIf(hasattr(aq_base(members), 'user2'))

Here is the caller graph for this function:

Definition at line 192 of file testMembershipTool.py.

00192 
00193         def testWrapUserCreatesMemberarea(self):
00194             members = self.membership.getMembersFolder()
00195             user = self.portal.acl_users.getUserById('user2')
00196             user = self.membership.wrapUser(user)
00197             self.failUnless(hasattr(aq_base(members), 'user2'))

Here is the call graph for this function:

Definition at line 198 of file testMembershipTool.py.

00198 
00199     def testWrapUserDoesntCreateMemberarea(self):
00200         # No member area is created if the flag is off
00201         self.membership.setMemberareaCreationFlag()
00202         members = self.membership.getMembersFolder()
00203         user = self.portal.acl_users.getUserById('user2')
00204         user = self.membership.wrapUser(user)
00205         self.failIf(hasattr(aq_base(members), 'user2'))

Definition at line 119 of file testMembershipTool.py.

00119 
00120     def testWrapUserDoesntWrapAnonymous(self):
00121         user = self.membership.wrapUser(nobody)
00122         self.assertEqual(user.__class__.__name__, 'SpecialUser')

Definition at line 106 of file testMembershipTool.py.

00106 
00107     def testWrapUserDoesntWrapMemberData(self):
00108         user = self.portal.acl_users.getUserById(default_user)
00109         user.getMemberId = lambda x: 1
00110         user = self.membership.wrapUser(user)
00111         self.assertEqual(user.__class__.__name__, 'User')

Definition at line 139 of file testMembershipTool.py.

00139 
00140     def testWrapUserMapsRoles(self):
00141         self.membership.setRoleMapping('Reviewer', 'FooRole')
00142         self.setRoles(['FooRole'])
00143         user = self.portal.acl_users.getUserById(default_user)
00144         user = self.membership.wrapUser(user)
00145         self.assertEqual(user.getRoles(), ('FooRole', 'Reviewer', 'Authenticated'))

Here is the call graph for this function:

Definition at line 112 of file testMembershipTool.py.

00112 
00113     def testWrapUserWrapsAnonymous(self):
00114         self.failIf(hasattr(nobody, 'aq_base'))
00115         user = self.membership.wrapUser(nobody, wrap_anon=1)
00116         self.assertEqual(user.__class__.__name__, 'MemberData')
00117         self.assertEqual(user.aq_parent.__class__.__name__, 'SpecialUser')
00118         self.assertEqual(user.aq_parent.aq_parent.__class__.__name__, 'UserFolder')

Definition at line 90 of file testMembershipTool.py.

00090 
00091     def testWrapUserWrapsBareUser(self):
00092         user = self.portal.acl_users.getUserById(default_user)
00093         self.failIf(hasattr(user, 'aq_base'))
00094         user = self.membership.wrapUser(user)
00095         self.assertEqual(user.__class__.__name__, 'MemberData')
00096         self.assertEqual(user.aq_parent.__class__.__name__, 'User')
00097         self.assertEqual(user.aq_parent.aq_parent.__class__.__name__, 'UserFolder')

Definition at line 98 of file testMembershipTool.py.

00098 
00099     def testWrapUserWrapsWrappedUser(self):
00100         user = self.portal.acl_users.getUserById(default_user)
00101         user = user.__of__(self.portal.acl_users)
00102         user = self.membership.wrapUser(user)
00103         self.assertEqual(user.__class__.__name__, 'MemberData')
00104         self.assertEqual(user.aq_parent.__class__.__name__, 'User')
00105         self.assertEqual(user.aq_parent.aq_parent.__class__.__name__, 'UserFolder')


Member Data Documentation

Definition at line 62 of file CMFTestCase.py.

Definition at line 24 of file testMembershipTool.py.


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