Beispiel #1
0
 def check_HasGroupMembership(self):
     self.test_stmt("HasGroupMembership()")
     g = HasGroupMembership()
     staff = UserGroup()
     staff.set_group_id('staff')
     admin = UserGroup()
     admin.set_group_id('admin')
     other = UserGroup()
     other.set_group_id('other')
     
     self.test_exc("g.is_member_of_group('staff')", TypeError)
     self.test_exc("g.add_to_group('staff')", TypeError)
     self.test_exc("g.remove_from_group('staff')", TypeError)
     
     
     self.test_stmt("g.add_to_group(staff)")
     self.test_true("g.is_member_of_group(staff)")
     self.test_true("staff in g.group_list()")
     
     self.test_stmt("g.add_to_group(admin)")
     self.test_true("g.is_member_of_group(admin)")
     self.test_true("admin in g.group_list()")
     
     self.test_false("g.is_member_of_group(other)")
     self.test_stmt("g.remove_from_group(staff)")
     self.test_false("g.is_member_of_group(staff)")
     self.test_stmt("g.remove_from_all_groups()")
     self.test_false("g.is_member_of_group(admin)")
     self.test_exc("g.remove_from_group([other, staff])", TypeError)  # can't remove list
     
     g.remove_from_all_groups()
     self.test_stmt("g.add_to_group([staff, admin])")
     self.test_true("g.is_member_of_group(staff)")
     self.test_true("g.is_member_of_group(admin)")
     self.test_false("g.is_member_of_group(other)")
Beispiel #2
0
 def check_group(self):
     g = UserGroup()
     g.set_group_id('foo')
     db = UserGroupDB()
     self.test_stmt("db.add_usergroup(g)")
     self.test_val("db.get_usergroup('foo')", g)
     self.test_exc("db.add_usergroup(g)", KeyError)
     
     self.test_stmt("db.remove_group('foo')")
     self.test_stmt("db.add_usergroup(g)")
     self.test_val("db.get_usergroup('foo')", g)
Beispiel #3
0
    def check_HasOwnership(self):
        self.test_stmt("HasOwnership()")
        ho = HasOwnership()
        
        foo = User()
        foo.set_user_id('foo')
        
        staff = UserGroup()
        staff.set_group_id('staff')

        self.test_stmt("ho.add_owner(foo)")
        self.test_stmt("ho.add_owning_group(staff)")
        self.test_stmt("ho.set_owner_perms(['read', 'write'])")
        self.test_stmt("ho.set_group_perms('read')")
        self.test_exc("ho.test_perm('fooble', User())", KeyError)
        
        u = User('foo')
        nobody = User('nobody')
        self.test_false("ho.can_read(u)")
        self.test_true("ho.can_read(foo)")
        self.test_false("ho.can_read(nobody)")
        self.test_false("ho.can_write(u)")
        self.test_true("ho.can_write(foo)")
        self.test_false("ho.can_write(nobody)")
        
        nobody.add_to_group(staff)
        self.test_true("ho.can_read(nobody)")
        self.test_false("ho.can_write(nobody)")
        
        self.test_stmt("ho.remove_owner(foo)")
        self.test_false("ho.can_read(foo)")
        self.test_false("ho.can_write(foo)")
        
        # check 'other' perms
        nobody = User()
        ho = HasOwnership()
        self.test_false("ho.can_read(nobody)")
        self.test_stmt("ho.set_other_perms('read')")
        self.test_true("ho.can_read(nobody)")
        self.test_false("ho.can_write(nobody)")
        self.test_stmt("ho.set_other_perms('write')")
        self.test_true("ho.can_write(nobody)")
        self.test_false("ho.can_manage(nobody)")
        self.test_stmt("ho.set_other_perms('manage')")
        self.test_true("ho.can_manage(nobody)")