Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
GroupUserFolder.tests.testUserAPI.TestUserFolderAPI Class Reference
Inheritance diagram for GroupUserFolder.tests.testUserAPI.TestUserFolderAPI:
Inheritance graph
[legend]
Collaboration diagram for GroupUserFolder.tests.testUserAPI.TestUserFolderAPI:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test03ClassSecurityInfo
def test_getId
def test_getUserName
def test_getName
def test_getRoles
def test_setRoles
def test_addRole
def test_removeRole
def test_getRolesInContext
def test_has_permission
def test_allowed
def test_has_role
def test_isGroup
def test_getGroupNames
def test_getGroupIds
def test_getGroups
def test_getImmediateGroups
def test_getAllGroupIds
def test_getAllGroupNames
def test_isInGroup
def test_setGroups
def test_addGroup
def test_removeGroup
def test_getRealId
def test_getDomains
def test_setPassword
def test_setDomains
def test_addDomain
def test_removeDomain
def test_getMemberIds
def test_getUserMemberIds
def test_getGroupMemberIds
def test_hasMember
def test_addMember
def test_removeMember
def test_getProperty
def test_hasProperty
def test_setProperty
def gruf_setup
def gruf_sources_setup
def security_context_setup
def security_context_setup_users
def test01Interfaces
def test02TestCaseCompletude

Public Attributes

 gruf_folder
 gruf
 lr
 sublr
 sublr2
 sublr3
 subsublr2
 subsublr3

Static Public Attributes

tuple klasses

Detailed Description

Definition at line 63 of file testUserAPI.py.


Member Function Documentation

gruf_setup(self,) => Basic gruf setup

Definition at line 86 of file GRUFTestCase.py.

00086 
00087     def gruf_setup(self,):
00088         """
00089         gruf_setup(self,) => Basic gruf setup
00090         """
00091         # Replace default acl_user by a GRUF one
00092         self.folder.manage_delObjects(['acl_users'])
00093         self.folder.manage_addProduct['OFSP'].manage_addFolder('testFolder')
00094         self.gruf_folder = self.folder.testFolder
00095         self.gruf_folder.manage_addProduct['GroupUserFolder'].manage_addGroupUserFolder()
00096         self.gruf = self.gruf_folder.acl_users
00097 

Here is the caller graph for this function:

gruf_sources_setup(self,) => this method installs the required sources inside GRUF.
One can override this in a test case to install other sources and make another bunch of unit tests
For example, for LDAPUserFolder, use manage_addProduct/LDAPUserFolder/addLDAPUserFolder

Reimplemented in GroupUserFolder.tests.testLDAPGroupFolder.TestLDAPUserFolderGroups, and GroupUserFolder.tests.testLDAPUserFolder.TestLDAPUserFolderBasics.

Definition at line 98 of file GRUFTestCase.py.

00098 
00099     def gruf_sources_setup(self,):
00100         """
00101         gruf_sources_setup(self,) => this method installs the required sources inside GRUF.
00102         One can override this in a test case to install other sources and make another bunch of unit tests
00103         For example, for LDAPUserFolder, use manage_addProduct/LDAPUserFolder/addLDAPUserFolder
00104         """
00105         # Use this to replace the default user source
00106         self.gruf.replaceUserSource("Users", "manage_addProduct/OFSP/manage_addUserFolder")
00107 
00108         # Use this to replace the default group source
00109         self.gruf.replaceUserSource("Groups", "manage_addProduct/OFSP/manage_addUserFolder")
00110 
00111         # add a second (empty) user source
00112         self.gruf.addUserSource("manage_addProduct/OFSP/manage_addUserFolder")

Build a complex security environment

It creates:
  * 3 roles, r1, r2 and r3
  * 3 groups: g1, g2, g3
  * n users as follows (roles are between parenthesis)

      !   g1    ! g2(r1)     ! g3(r2)     ! g4(r2,r3)  !  Resulting roles !
  ------------!---------!------------!------------!------------!------------------!
  u1          !         !            !            !            !   => (no role)   !
  u2          !   X     !            !            !            !   => (no role)   !
  u3          !   X     !      X     !            !            !   => r1          !
  u4          !   X     !      X     !      X     !            !   => r1,r2       !
  u5(r1)      !         !      X     !      X     !            !   => r1,r2       !
  u6(r1)      !         !            !      X     !            !   => r1,r2       !
  u7(r1)      !         !            !            !     X      !   => r1,r2,r3    !
  ---------------------------------------------------------------------------------

It also creates a 'lr' folder in which g1 group and u3 and u6 are granted r3 role.


And then, it creates nested groups as follow (-> = belongs to group...):

     u/g   !  belongs to... ! resulting roles                     !
 ----------!----------------!-------------------------------------!
  ng1      !   g1           ! (no role)                           !
  ng2      !   g2, g3       ! r1, r2                              !
  ng3      !   g2, ng2      ! r1, r2                              !
  ng4(r3)  !   g2, ng2      ! r1, r2, r3                          !
  ng5      !   g2, ng4      ! r1, r2, r3                          !
  ng6      !   ng5, ng6     ! r1, r2, r3 (no circ. ref)           !
  u8       !   ng1          ! (no role)                           !
  u9       !   g1, ng2      ! r1, r2                              !
  u10      !   ng2, ng3     ! r1, r2                              !
  u11(r3)  !   ng2, ng3     ! r1, r2, r3                          !
  u12      !   ng5, ng6     ! r1, r2, r3                          !
 -----------------------------------------------------------------!

 Plus we have the following local roles matrix (roles inside parenthesis are implicitly
 user-defined, roles inside brackets are implicitly lr-defined).

 folder
   |
   |-- acl_users (GRUF)
   |
   |                                          r1    r2    r3
   |                             /--
   |                             | group_g1               x
   |-- lr                        | u3        (x)          x
       |                         | u6        (x)   (x)    x
       |                         \--
       |
       |                         /--
       |                         | group_g1              [x]
       |-- sublr                 | u3        (x)    x    [x]
       |                         | u6        (x)    x*   [x]
       |                         \--
       |
       |                         /--
       |                         | group_g1              [x]
       |-- sublr2                | u3        (x)    x    [x]
       |   |                     | u6        (x)    x*   [x]
       |   |                     \--
       |   |
       |   |                     /--
       |   |                     | group_g1              [x]
       |   |-- subsublr2         | u3        (x)   [x]   [x]
       |                         | u6        (x)  [(x)]  [x]
       |                         \--
       |
 (now we block local roles under this branch)
       |
       |                         /--
       |                         | group_g1              
       |-- sublr3                | u3        (x)    x    
   |                     | u6        (x)    x*   
   |                     \--
   |
   |                     /--
   |                     | group_g1              
   |-- subsublr3         | u3        (x)   [x]   
                         | u6        (x)  [(x)]  
                         \--
                         
*: u6 will have r2 as a localrole AND a userdefined role.

Definition at line 113 of file GRUFTestCase.py.

00113 
00114     def security_context_setup(self,):
00115         """
00116         Build a complex security environment
00117 
00118         It creates:
00119           * 3 roles, r1, r2 and r3
00120           * 3 groups: g1, g2, g3
00121           * n users as follows (roles are between parenthesis)
00122 
00123                       !   g1    ! g2(r1)     ! g3(r2)     ! g4(r2,r3)  !  Resulting roles !
00124           ------------!---------!------------!------------!------------!------------------!
00125           u1          !         !            !            !            !   => (no role)   !
00126           u2          !   X     !            !            !            !   => (no role)   !
00127           u3          !   X     !      X     !            !            !   => r1          !
00128           u4          !   X     !      X     !      X     !            !   => r1,r2       !
00129           u5(r1)      !         !      X     !      X     !            !   => r1,r2       !
00130           u6(r1)      !         !            !      X     !            !   => r1,r2       !
00131           u7(r1)      !         !            !            !     X      !   => r1,r2,r3    !
00132           ---------------------------------------------------------------------------------
00133 
00134         It also creates a 'lr' folder in which g1 group and u3 and u6 are granted r3 role.
00135 
00136 
00137         And then, it creates nested groups as follow (-> = belongs to group...):
00138 
00139              u/g   !  belongs to... ! resulting roles                     !
00140          ----------!----------------!-------------------------------------!
00141           ng1      !   g1           ! (no role)                           !
00142           ng2      !   g2, g3       ! r1, r2                              !
00143           ng3      !   g2, ng2      ! r1, r2                              !
00144           ng4(r3)  !   g2, ng2      ! r1, r2, r3                          !
00145           ng5      !   g2, ng4      ! r1, r2, r3                          !
00146           ng6      !   ng5, ng6     ! r1, r2, r3 (no circ. ref)           !
00147           u8       !   ng1          ! (no role)                           !
00148           u9       !   g1, ng2      ! r1, r2                              !
00149           u10      !   ng2, ng3     ! r1, r2                              !
00150           u11(r3)  !   ng2, ng3     ! r1, r2, r3                          !
00151           u12      !   ng5, ng6     ! r1, r2, r3                          !
00152          -----------------------------------------------------------------!
00153 
00154          Plus we have the following local roles matrix (roles inside parenthesis are implicitly
00155          user-defined, roles inside brackets are implicitly lr-defined).
00156 
00157          folder
00158            |
00159            |-- acl_users (GRUF)
00160            |
00161            |                                          r1    r2    r3
00162            |                             /--
00163            |                             | group_g1               x
00164            |-- lr                        | u3        (x)          x
00165                |                         | u6        (x)   (x)    x
00166                |                         \--
00167                |
00168                |                         /--
00169                |                         | group_g1              [x]
00170                |-- sublr                 | u3        (x)    x    [x]
00171                |                         | u6        (x)    x*   [x]
00172                |                         \--
00173                |
00174                |                         /--
00175                |                         | group_g1              [x]
00176                |-- sublr2                | u3        (x)    x    [x]
00177                |   |                     | u6        (x)    x*   [x]
00178                |   |                     \--
00179                |   |
00180                |   |                     /--
00181                |   |                     | group_g1              [x]
00182                |   |-- subsublr2         | u3        (x)   [x]   [x]
00183                |                         | u6        (x)  [(x)]  [x]
00184                |                         \--
00185                |
00186          (now we block local roles under this branch)
00187                |
00188                |                         /--
00189                |                         | group_g1              
00190                |-- sublr3                | u3        (x)    x    
00191                    |                     | u6        (x)    x*   
00192                    |                     \--
00193                    |
00194                    |                     /--
00195                    |                     | group_g1              
00196                    |-- subsublr3         | u3        (x)   [x]   
00197                                          | u6        (x)  [(x)]  
00198                                          \--
00199                                          
00200         *: u6 will have r2 as a localrole AND a userdefined role.
00201         """
00202         # Create a few roles
00203         self.gruf.userFolderAddRole("r1")
00204         self.gruf.userFolderAddRole("r2")
00205         self.gruf.userFolderAddRole("r3")
00206 
00207         # Set View permission on those roles
00208         permissions = self.gruf_folder.ac_inherited_permissions(1)
00209         for ip in range(len(permissions)):
00210             name, value = permissions[ip][:2]
00211             if name == "View":
00212                 break
00213         p=Permission.Permission(name,value, self.gruf_folder)
00214         p.setRoles(("r1", "r2", "r3", ))
00215 
00216         # Setup users and groups
00217         self.security_context_setup_groups()
00218         self.security_context_setup_users()
00219         
00220         # Create a few folders to play with
00221         self.gruf_folder.manage_addProduct['OFSP'].manage_addFolder('lr')
00222         lr = self.gruf_folder.lr
00223         lr.manage_addProduct['OFSP'].manage_addFolder("sublr")
00224         sublr = self.gruf_folder.lr.sublr
00225         lr.manage_addProduct['OFSP'].manage_addFolder("sublr2")
00226         sublr2 = self.gruf_folder.lr.sublr2
00227         sublr2.manage_addProduct['OFSP'].manage_addFolder("subsublr2")
00228         subsublr2 = self.gruf_folder.lr.sublr2.subsublr2
00229         lr.manage_addProduct['OFSP'].manage_addFolder("sublr3")
00230         sublr3 = self.gruf_folder.lr.sublr3
00231         sublr3.manage_addProduct['OFSP'].manage_addFolder("subsublr3")
00232         subsublr3 = self.gruf_folder.lr.sublr3.subsublr3
00233         self.gruf._acquireLocalRoles(sublr3, 0)
00234         lr.manage_addLocalRoles("group_g1", ("r3", ))
00235         lr.manage_addLocalRoles("u3", ("r3", ))
00236         lr.manage_addLocalRoles("u6", ("r3", ))
00237         sublr.manage_addLocalRoles("u3", ("r2", ))
00238         sublr.manage_addLocalRoles("u6", ("r2", ))
00239         sublr2.manage_addLocalRoles("u3", ("r2", ))
00240         sublr2.manage_addLocalRoles("u6", ("r2", ))
00241         sublr3.manage_addLocalRoles("u3", ("r2", ))
00242         sublr3.manage_addLocalRoles("u6", ("r2", ))
00243         self.lr = lr
00244         self.sublr = sublr
00245         self.sublr2 = sublr2
00246         self.sublr3 = sublr3
00247         self.subsublr2 = subsublr2
00248         self.subsublr3 = subsublr3
00249 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 250 of file GRUFTestCase.py.

00250 
00251     def security_context_setup_users(self,):
00252         # Create a manager and a few users
00253         self.gruf.userFolderAddUser('manager', 'secret', ('Manager',), (), (), )
00254         self.gruf.userFolderAddUser('u1', 'secret', (), (), (), )
00255         self.gruf.userFolderAddUser('u2', 'secret', (), (), ('g1', ), )
00256         self.gruf.userFolderAddUser('u3', 'secret', (), (), ('g1', 'g2'), )
00257         self.gruf.userFolderAddUser('u4', 'secret', (), (), ('g1', 'g2', 'g3'), )
00258         self.gruf.userFolderAddUser('u5', 'secret', ('r1', ), (), ('g2', 'g3'), )
00259         self.gruf.userFolderAddUser('u6', 'secret', ('r1', ), (), ('g3', ), )
00260         self.gruf.userFolderAddUser('u7', 'secret', ('r1', ), (), ('g4', ), )
00261 
00262         # Create nested-groups users
00263         self.gruf.userFolderAddUser('u8', 'secret', (), (), ('ng1', ), )        
00264         self.gruf.userFolderAddUser('u9', 'secret', (), (), ('g1', 'ng2', ), )
00265         self.gruf.userFolderAddUser('u10', 'secret', (), (), ('ng2', 'ng3', ), )        
        self.gruf.userFolderAddUser('u11', 'secret', ('r3', ), (), ('ng2', 'ng3', ), )        

Here is the caller graph for this function:

Test that interfaces are okay

Definition at line 81 of file testInterface.py.

00081 
00082     def test01Interfaces(self,):
00083         """
00084         Test that interfaces are okay
00085         """
00086         # Check interface for each and every class
00087         ignore = getattr(self, "ignore_interfaces", [])
00088         for klass in self.klasses:
00089             intfs = getattr(klass, "__implements__", None)
00090             self.failUnless(intfs, "'%s' class doesn't implement an interface!" % (klass.__name__, ))
00091 
00092             # Flatten interfaces
00093             intfs = flattenList(intfs)
00094 
00095             # Check each and everyone
00096             for intf in intfs:
00097                 if intf in ignore:
00098                     continue
00099                 self.failUnless(
00100                     Verify.verifyClass(
00101                     intf,
00102                     klass,
00103                     ),
00104                     "'%s' class doesn't implement '%s' interface correctly." % (klass.__name__, intf.__name__, ),
00105                     )
00106 

Here is the call graph for this function:

Check that the test case is complete : each interface entry xxx must be associated
to a test_xxx method in the test class.

Definition at line 107 of file testInterface.py.

00107 
00108     def test02TestCaseCompletude(self,):
00109         """
00110         Check that the test case is complete : each interface entry xxx must be associated
00111         to a test_xxx method in the test class.
00112         """
00113         not_defined = []
00114         tests = dir(self)
00115         count = 0
00116         
00117         # Check interface for each and every class
00118         ignore = getattr(self, "ignore_interfaces", [])
00119         for klass in self.klasses:
00120             intfs = getattr(klass, "__implements__", None)
00121             self.failUnless(intfs, "'%s' class doesn't implement an interface!" % (klass.__name__, ))
00122 
00123             # Flatten interfaces
00124             intfs = flattenInterfaces(intfs)
00125 
00126             # Check each and every interface
00127             for intf in intfs:
00128                 if intf in ignore:
00129                     continue
00130                 for name in intf.names():
00131                     count += 1
00132                     if not "test_%s" % (name,) in tests:
00133                         not_defined.append("%s.%s" % (klass.__name__, name))
00134 
00135 
00136         # Raise in case some tests are missing
00137         if not_defined:
00138             raise RuntimeError, "%d (over %d) MISSING TESTS:\n%s do not have a test associated." % (
00139                 len(not_defined),
00140                 count,
00141                 string.join(not_defined, ", "),
00142                 )
00143         
        

Here is the call graph for this function:

We inhibit this test: class security info is not managed this way with user objects

Reimplemented from GroupUserFolder.tests.testInterface.TestInterface.

Definition at line 70 of file testUserAPI.py.

00070 
00071     def test03ClassSecurityInfo(self,):
00072         """We inhibit this test: class security info is not managed this way with user objects
00073         """
00074         pass
    

Definition at line 490 of file testUserAPI.py.

00490 
00491     def test_addDomain(self, ):
00492         "..."

Definition at line 411 of file testUserAPI.py.

00411 
00412     def test_addGroup(self, ):
00413         u = self.gruf.getUser("u1")
00414         self.failUnless(u.getGroups() == [])
00415         u.addGroup("g3")
00416         self.failUnless(u.getGroups() == ["group_g3"])
00417         u.addGroup("group_g2")
00418         r = u.getGroups()
00419         r.sort()
00420         self.failUnless(r == ["group_g2", "group_g3"])
00421         

Definition at line 523 of file testUserAPI.py.

00523 
00524     def test_addMember(self, ):
00525         g = self.gruf.getGroup("ng3")
00526         self.failUnless("u1" not in g.getMemberIds())
00527         g.addMember("u1")
00528         self.failUnless("u1" in g.getMemberIds())

Definition at line 137 of file testUserAPI.py.

00137 
00138     def test_addRole(self,):
00139         # Initial situation
00140         u = self.gruf.getUser("u5")
00141         r = list(u.getRoles())
00142         r.sort()
00143         self.failUnless(r == ["Authenticated", "r1", "r2", ])
00144 
00145         # Regular role adding
00146         u.addRole("r3", )
00147         r = list(u.getRoles())
00148         r.sort()
00149         self.failUnless(r == ["Authenticated", "r1", "r2", "r3"])
00150 
00151         # Invalid role adding -> should raise
00152         try:
00153             u.addRole("bloub", )
00154         except ValueError:
00155             pass
00156         else:
00157             raise AssertionError, "Should raise a ValueError here"

Definition at line 194 of file testUserAPI.py.

00194 
00195     def test_allowed(self, ):
00196         pass            # XXX Will have to test that intensively !

Definition at line 316 of file testUserAPI.py.

00316 
00317     def test_getAllGroupIds(self):
00318         # Regular test
00319         u = self.gruf.getUser("u2")
00320         g = u.getAllGroupIds()
00321         g.sort()
00322         self.failUnless(g == ["group_g1", ])
00323 
00324         # Empty list test
00325         u = self.gruf.getUser("u1")
00326         g = u.getAllGroupIds()
00327         g.sort()
00328         self.failUnless(g == [])
00329 
00330         # GroupOfGroup test
00331         u = self.gruf.getUser("ng1")
00332         g = u.getAllGroupIds()
00333         g.sort()
00334         self.failUnless(g == ["group_g1", ])
00335 
00336         # Transitivity test
00337         u = self.gruf.getUser("u10")
00338         g = u.getAllGroupIds()
00339         g.sort()
00340         self.failUnless(g == ["group_g2", "group_g3", "group_ng2", "group_ng3", ])
00341 

Definition at line 342 of file testUserAPI.py.

00342 
00343     def test_getAllGroupNames(self):
00344         # Regular test
00345         u = self.gruf.getUser("u2")
00346         g = u.getAllGroupNames()
00347         g.sort()
00348         self.failUnless(g == ["g1", ])
00349 
00350         # Empty list test
00351         u = self.gruf.getUser("u1")
00352         g = u.getAllGroupNames()
00353         g.sort()
00354         self.failUnless(g == [])
00355 
00356         # GroupOfGroup test
00357         u = self.gruf.getUser("ng1")
00358         g = u.getAllGroupNames()
00359         g.sort()
00360         self.failUnless(g == ["g1", ])
00361 
00362         # Transitivity test
00363         u = self.gruf.getUser("u10")
00364         g = u.getAllGroupNames()
00365         g.sort()
00366         self.failUnless(g == ["g2", "g3", "ng2", "ng3", ])
00367 

Return the list of domain restrictions for a user

Definition at line 445 of file testUserAPI.py.

00445 
00446     def test_getDomains(self,):
00447         """Return the list of domain restrictions for a user"""
00448         self.gruf.userFolderAddUser(
00449             "test_crea",
00450             "secret",
00451             [],
00452             ["a", 'b', 'c'],
00453             [],
00454             )
00455         u = self.gruf.getUser("test_crea")
00456         d = list(u.getDomains())
00457         d.sort()
00458         self.failUnless(d == ["a", "b", "c", ])
00459 
    

Definition at line 239 of file testUserAPI.py.

00239 
00240     def test_getGroupIds(self, ):
00241         # Regular test
00242         u = self.gruf.getUser("u2")
00243         g = u.getGroupIds()
00244         g.sort()
00245         self.failUnless(g == ["group_g1", ])
00246 
00247         # Empty list test
00248         u = self.gruf.getUser("u1")
00249         g = u.getGroupIds()
00250         g.sort()
00251         self.failUnless(g == [])
00252 
00253         # GroupOfGroup test
00254         u = self.gruf.getUser("ng1")
00255         g = u.getGroupIds()
00256         g.sort()
00257         self.failUnless(g == ["group_g1", ])
00258 
00259         # Non-transitivity test
00260         u = self.gruf.getUser("u10")
00261         g = u.getGroupIds()
00262         g.sort()
00263         self.failUnless(g == ["group_ng2", "group_ng3", ])

Definition at line 513 of file testUserAPI.py.

00513 
00514     def test_getGroupMemberIds(self, ):
00515         u = self.gruf.getGroup("ng2")
00516         ulist = u.getGroupMemberIds()
00517         ulist.sort()
00518         self.failUnless(ulist == ['group_ng3', 'group_ng4', 'group_ng5'])

Definition at line 214 of file testUserAPI.py.

00214 
00215     def test_getGroupNames(self,):
00216         # Regular test
00217         u = self.gruf.getUser("u2")
00218         g = u.getGroupNames()
00219         g.sort()
00220         self.failUnless(g == ["g1", ])
00221 
00222         # Empty list test
00223         u = self.gruf.getUser("u1")
00224         g = u.getGroupNames()
00225         g.sort()
00226         self.failUnless(g == [])
00227 
00228         # GroupOfGroup test
00229         u = self.gruf.getUser("ng1")
00230         g = u.getGroupNames()
00231         g.sort()
00232         self.failUnless(g == ["g1", ])
00233 
00234         # Non-transitivity test
00235         u = self.gruf.getUser("u10")
00236         g = u.getGroupNames()
00237         g.sort()
00238         self.failUnless(g == ["ng2", "ng3", ])

Definition at line 264 of file testUserAPI.py.

00264 
00265     def test_getGroups(self, ):
00266         # Regular test
00267         u = self.gruf.getUser("u2")
00268         g = u.getGroups()
00269         g.sort()
00270         self.failUnless(g == ["group_g1", ])
00271 
00272         # Empty list test
00273         u = self.gruf.getUser("u1")
00274         g = u.getGroups()
00275         g.sort()
00276         self.failUnless(g == [])
00277 
00278         # GroupOfGroup test
00279         u = self.gruf.getUser("ng1")
00280         g = u.getGroups()
00281         g.sort()
00282         self.failUnless(g == ["group_g1", ])
00283 
00284         # Transitivity test
00285         u = self.gruf.getUser("u10")
00286         g = u.getGroups()
00287         g.sort()
00288         self.failUnless(g == ["group_g2", "group_g3", "group_ng2", "group_ng3", ])
00289 

Definition at line 75 of file testUserAPI.py.

00075 
00076     def test_getId(self,):
00077         u = self.gruf.getUser("u1")
00078         self.failUnless(u.getId() == "u1")
00079         u = self.gruf.getUser("group_g1")
00080         self.failUnless(u.getId() == "group_g1")

Definition at line 290 of file testUserAPI.py.

00290 
00291     def test_getImmediateGroups(self,):
00292         # Regular test
00293         u = self.gruf.getUser("u2")
00294         g = u.getImmediateGroups()
00295         g.sort()
00296         self.failUnless(g == ["group_g1", ])
00297 
00298         # Empty list test
00299         u = self.gruf.getUser("u1")
00300         g = u.getImmediateGroups()
00301         g.sort()
00302         self.failUnless(g == [])
00303 
00304         # GroupOfGroup test
00305         u = self.gruf.getUser("ng1")
00306         g = u.getImmediateGroups()
00307         g.sort()
00308         self.failUnless(g == ["group_g1", ])
00309 
00310         # Transitivity test
00311         u = self.gruf.getUser("u10")
00312         g = u.getImmediateGroups()
00313         g.sort()
00314         self.failUnless(g == ["group_ng2", "group_ng3", ], u.getImmediateGroups())
00315 

Definition at line 496 of file testUserAPI.py.

00496 
00497     def test_getMemberIds(self, ):
00498         u = self.gruf.getGroup("ng2")
00499         ulist = u.getMemberIds()
00500         ulist.sort()
00501         self.failUnless(ulist == ['group_ng3', 'group_ng4', 'group_ng5', 'u10', 'u11', 'u9', ])

Definition at line 87 of file testUserAPI.py.

00087 
00088     def test_getName(self,):
00089         u = self.gruf.getUser("u1")
00090         self.failUnless(u.getUserName() == "u1")
00091         u = self.gruf.getUser("group_g1")
00092         self.failUnless(u.getUserName() == "g1")

Will raise for regular user folders

Definition at line 554 of file testUserAPI.py.

00554 
00555     def test_getProperty(self,):
00556         """Will raise for regular user folders
00557         """
00558         try:
00559             self.gruf.getUser("u1").getProperty("email")
00560         except:
00561             pass
00562         else:
00563             raise AssertionError, "Should raise"

Definition at line 436 of file testUserAPI.py.

00436 
00437     def test_getRealId(self, ):
00438         u = self.gruf.getUser("u1")
00439         self.failUnless(u.getRealId() == "u1")
00440         u = self.gruf.getUser("g1")
00441         self.failUnless(u.getRealId() == "g1")
00442         u = self.gruf.getUser("group_g1")
00443         self.failUnless(u.getRealId() == "g1")
00444         

Definition at line 93 of file testUserAPI.py.

00093 
00094     def test_getRoles(self):
00095         u = self.gruf.getUser("u5")
00096         r = list(u.getRoles())
00097         r.sort()
00098         Log(LOG_DEBUG, r)
00099         self.failUnless(r == ["Authenticated", "r1", "r2", ])

Here is the call graph for this function:

Definition at line 184 of file testUserAPI.py.

00184 
00185     def test_getRolesInContext(self, ):
00186         r = self.gruf.getUser("u2").getRolesInContext(self.gruf_folder.lr)
00187         self.failUnless("r3" in r)
00188         r = self.gruf.getUser("u3").getRolesInContext(self.gruf_folder.lr)
00189         self.failUnless("r1" in r)
00190         self.failUnless("r3" in r)

Here is the call graph for this function:

Definition at line 502 of file testUserAPI.py.

00502 
00503     def test_getUserMemberIds(self, ):
00504         u = self.gruf.getGroup("ng2")
00505         ulist = u.getUserMemberIds()
00506         ulist.sort()
00507         self.failUnless(ulist == ['u10', 'u11', 'u9', ])
00508 
00509         u = self.gruf.getGroup("g2")
00510         ulist = u.getUserMemberIds()
00511         ulist.sort()
00512         self.failUnless(ulist == ['u10', 'u11', 'u3', 'u4', 'u5', 'u9', ])

Definition at line 81 of file testUserAPI.py.

00081 
00082     def test_getUserName(self,):
00083         u = self.gruf.getUser("u1")
00084         self.failUnless(u.getUserName() == "u1")
00085         u = self.gruf.getUser("group_g1")
00086         self.failUnless(u.getUserName() == "g1")

Definition at line 191 of file testUserAPI.py.

00191 
00192     def test_has_permission(self, ):
00193         pass            # Don't know how to test this :(

Definition at line 197 of file testUserAPI.py.

00197 
00198     def test_has_role(self, ):
00199         u = self.gruf.getUser("u2")
00200         self.failUnless(u.has_role("r3", self.gruf_folder.lr, ))

Definition at line 519 of file testUserAPI.py.

00519 
00520     def test_hasMember(self, ):
00521         self.failUnless(self.gruf.getGroup("g2").hasMember("u4"))
00522         self.failUnless(self.gruf.getGroup("g2").hasMember("group_ng2"))

Here is the call graph for this function:

Definition at line 564 of file testUserAPI.py.

00564 
00565     def test_hasProperty(self,):
00566         self.failUnless(not self.gruf.getUser("u1").hasProperty("email"))

Definition at line 201 of file testUserAPI.py.

00201 
00202     def test_isGroup(self, ):
00203         u = self.gruf.getUser("u1")
00204         self.failUnless(not u.isGroup())
00205         u = self.gruf.getUser("u2")
00206         self.failUnless(not u.isGroup())
00207         u = self.gruf.getUser("g1")
00208         self.failUnless(u.isGroup())
00209         u = self.gruf.getUser("ng2")
00210         self.failUnless(u.isGroup())
00211         u = self.gruf.getUser("g3")
00212         self.failUnless(u.isGroup())
00213         

Definition at line 368 of file testUserAPI.py.

00368 
00369     def test_isInGroup(self, ):
00370         u = self.gruf.getUser("u2")
00371         self.failUnless(u.isInGroup("group_g1", ))
00372         self.failUnless(not u.isInGroup("g1", ))        # We don not allow group names
00373 
00374         # Empty list test
00375         u = self.gruf.getUser("u1")
00376         self.failUnless(not u.isInGroup("group_g1", ))
00377 
00378         # GroupOfGroup test
00379         u = self.gruf.getUser("ng1")
00380         self.failUnless(u.isInGroup("group_g1", ))
00381 
00382         # Transitivity test
00383         u = self.gruf.getUser("u10")
00384         self.failUnless(u.isInGroup("group_g2", ))
00385         self.failUnless(u.isInGroup("group_g3", ))
00386         self.failUnless(u.isInGroup("group_ng2", ))
00387         self.failUnless(u.isInGroup("group_ng3", ))
00388         

Definition at line 493 of file testUserAPI.py.

00493 
00494     def test_removeDomain(self, ):
00495         "..."

Definition at line 422 of file testUserAPI.py.

00422 
00423     def test_removeGroup(self, ):
00424         u = self.gruf.getUser("u1")
00425         u.addGroup("group_g3")
00426         u.addGroup("group_g2")
00427         r = u.getGroups()
00428         r.sort()
00429         self.failUnless(r == ["group_g2", "group_g3"])
00430         u.removeGroup("group_g3")
00431         Log(LOG_DEBUG, u.getGroups())
00432         self.failUnless(u.getGroups() == ["group_g2", ])
00433         u.removeGroup("group_g2")
00434         self.failUnless(u.getGroups() == [])
00435         
        

Here is the call graph for this function:

Definition at line 529 of file testUserAPI.py.

00529 
00530     def test_removeMember(self, ):
00531         g = self.gruf.getGroup("ng3")
00532         self.failUnless("u1" not in g.getMemberIds())
00533         g.addMember("u1")
00534         self.failUnless("u1" in g.getMemberIds())
00535         g.removeMember("u1")
00536         self.failUnless("u1" not in g.getMemberIds())
00537 
00538         ## remove a group in a group
00539         # ng5 is in g2 and we add g3 in ng5
00540         g2 = self.gruf.getGroup("g2")
00541         ng5 = self.gruf.getGroup("ng5")
00542 
00543         self.failUnless("group_ng1" not in ng5.getMemberIds())
00544         self.failUnless("group_ng1" not in g2.getMemberIds())
00545         ng5.addMember("ng1")
00546 
00547         self.failUnless("group_ng1" in ng5.getMemberIds())
00548         self.failUnless("group_ng1" in g2.getMemberIds())
00549         ng5.removeMember("ng1")
00550 
00551         self.failUnless("group_ng1" not in ng5.getMemberIds())
00552         self.failUnless("group_ng1" not in g2.getMemberIds())
00553 

Definition at line 158 of file testUserAPI.py.

00158 
00159     def test_removeRole(self,):
00160         # Initial situation
00161         u = self.gruf.getUser("u6")
00162         r = list(u.getRoles())
00163         r.sort()
00164         self.failUnless(r == ["Authenticated", "r1", "r2", ])
00165 
00166         # Regular role removing
00167         u.removeRole("r1", )
00168         r = list(u.getRoles())
00169         r.sort()
00170         self.failUnless(r == ["Authenticated", "r2", ])
00171 
00172         # Try to remove a non-used role => should be transparent
00173         u.removeRole("r1", )
00174         r = list(u.getRoles())
00175         r.sort()
00176         self.failUnless(r == ["Authenticated", "r2", ])
00177 
00178         # Remove group role : we must keep group-defined roles
00179         u.removeRole("r2")
00180         r = list(u.getRoles())
00181         r.sort()
00182         Log(LOG_DEBUG, r)
00183         self.failUnless(r == ["Authenticated", "r2", ])

Here is the call graph for this function:

Definition at line 477 of file testUserAPI.py.

00477 
00478     def test_setDomains(self, ):
00479         u = self.gruf.getUser("u1")
00480         self.failUnless(not u.getDomains())
00481         u.setDomains(["d1", "d2", "d3", ])
00482         d = list(u.getDomains())
00483         d.sort()
00484         self.failUnless(d == ["d1", "d2", "d3", ])
00485         u.setDomains([])
00486         self.failUnless(tuple(u.getDomains()) == ())
00487         u.setDomains(["xxx"])
00488         self.failUnless(tuple(u.getDomains()) == ("xxx", ))
00489         

Definition at line 389 of file testUserAPI.py.

00389 
00390     def test_setGroups(self, ):
00391         self.gruf.userFolderAddUser(
00392             name = "created_user",
00393             password = "secret",
00394             groups = [],
00395             roles = (),
00396             domains = (),
00397             )
00398         u = self.gruf.getUser("created_user")
00399         u.setGroups(["g1", "g2", ], )
00400         self.compareGroups("created_user", ["g1", "g2", ], )
00401         u.setGroups([], )
00402         self.compareGroups("created_user", [], )
00403         u.setGroups(["group_g1", "group_g2", ], )
00404         self.compareGroups("created_user", ["g1", "g2", ], )
00405         try:
00406             u.setGroups(["group_g1", "group_g2", "bloub", ], )
00407         except ValueError:
00408             pass
00409         else:
00410             raise AssertionError, "Should raise ValueError"

Definition at line 460 of file testUserAPI.py.

00460 
00461     def test_setPassword(self):
00462         # Regular user password
00463         user = self.gruf.getUser('u1')
00464         self.failUnless(user.authenticate('secret', self.app.REQUEST))
00465         user.setPassword("marih")
00466         self.failUnless(not user.authenticate('secret', self.app.REQUEST))
00467         self.failUnless(user.authenticate('marih', self.app.REQUEST))
00468 
00469         # Prohibit group password changing (the method shouldn't even be available)
00470         u = self.gruf.getUser("g1")
00471         try:
00472             u.setPassword("bloub")
00473         except AttributeError:
00474             pass                # Ok
00475         else:
00476             raise AssertionError, "Password change must be prohibited for groups"

Definition at line 567 of file testUserAPI.py.

00567 
00568     def test_setProperty(self,):
00569         try:
00570             self.gruf.getUser("u1").setProperty("email", "test@test.com")
00571         except NotImplementedError:
00572             pass
00573         else:
00574             raise AssertionError, "Should raise here."
00575 
00576 

Here is the call graph for this function:

Definition at line 100 of file testUserAPI.py.

00100 
00101     def test_setRoles(self,):
00102         # Initial situation
00103         u = self.gruf.getUser("u5")
00104         r = list(u.getRoles())
00105         r.sort()
00106         self.failUnless(r == ["Authenticated", "r1", "r2", ])
00107 
00108         # Regular role setting
00109         u.setRoles(["r3", "r2", "r1"])
00110         r = list(u.getRoles())
00111         r.sort()
00112         self.failUnless(r == ["Authenticated", "r1", "r2", "r3"])
00113 
00114         # Try to add an invalid role => should be prohibited
00115         try:
00116             u.setRoles(["r3", "r2", "r1", "bloub"])
00117         except ValueError:
00118             pass
00119         else:
00120             raise AssertionError, "Should raise a ValueError here"
00121 
00122         # Reset roles : we must keep group-defined roles
00123         u.setRoles([])
00124         r = list(u.getRoles())
00125         r.sort()
00126         self.failUnless(r == ["Authenticated", "r1", "r2", ])
00127 
00128         # Now reset roles on another user
00129         u = self.gruf.getUser("u6")
00130         r = list(u.getRoles())
00131         r.sort()
00132         self.failUnless(r == ["Authenticated", "r1", "r2", ])
00133         u.setRoles([])
00134         r = list(u.getRoles())
00135         r.sort()
00136         self.failUnless(r == ["Authenticated", "r2", ])


Member Data Documentation

Definition at line 95 of file GRUFTestCase.py.

Definition at line 93 of file GRUFTestCase.py.

Initial value:
(        # tell which classes to check
        GRUFUser.GRUFUser,
        GRUFUser.GRUFGroup,
        )

Definition at line 65 of file testUserAPI.py.

Definition at line 242 of file GRUFTestCase.py.

Definition at line 243 of file GRUFTestCase.py.

Definition at line 244 of file GRUFTestCase.py.

Definition at line 245 of file GRUFTestCase.py.

Definition at line 246 of file GRUFTestCase.py.

Definition at line 247 of file GRUFTestCase.py.


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