コード例 #1
0
 def testManyRolesOnePermission(self):
     perm1 = definePermission('Perm One', 'title').id
     role1 = defineRole('Role One', 'Role #1').id
     role2 = defineRole('Role Two', 'Role #2').id
     roles = manager.getRolesForPermission(perm1)
     self.assertEqual(len(roles), 0)
     manager.grantPermissionToRole(perm1, role1)
     manager.grantPermissionToRole(perm1, role2)
     manager.grantPermissionToRole(perm1, role2)
     manager.denyPermissionToRole(perm1, role1)
     roles = manager.getRolesForPermission(perm1)
     self.assertEqual(len(roles), 2)
     self.failIf((role1,Allow) in roles)
     self.failUnless((role1,Deny) in roles)
     self.failUnless((role2,Allow) in roles)
     manager.unsetPermissionFromRole(perm1, role1)
     roles = manager.getRolesForPermission(perm1)
     self.assertEqual(len(roles), 1)
     self.failUnless((role2,Allow) in roles)
コード例 #2
0
 def testManyPermissionsOneRole(self):
     perm1 = definePermission('Perm One', 'P1').id
     perm2 = definePermission('Perm Two', 'P2').id
     perm3 = definePermission('Perm Three', 'P3').id
     role1 = defineRole('Role One', 'Role #1').id
     perms = manager.getPermissionsForRole(role1)
     self.assertEqual(len(perms), 0)
     manager.grantPermissionToRole(perm1, role1)
     manager.grantPermissionToRole(perm2, role1)
     manager.grantPermissionToRole(perm2, role1)
     manager.denyPermissionToRole(perm3, role1)
     perms = manager.getPermissionsForRole(role1)
     self.assertEqual(len(perms), 3)
     self.failUnless((perm1,Allow) in perms)
     self.failUnless((perm2,Allow) in perms)
     self.failUnless((perm3,Deny) in perms)
     manager.unsetPermissionFromRole(perm1, role1)
     perms = manager.getPermissionsForRole(role1)
     self.assertEqual(len(perms), 2)
     self.failUnless((perm2,Allow) in perms)