Example #1
0
 def check_user(self):
     u = User()
     u.set_user_id('foo')
     db = UserDB()
     self.test_stmt("db.add_user(u)")
     self.test_val("db.get_user('foo')", u)
     self.test_exc("db.add_user(u)", KeyError)
     
     self.test_stmt("db.remove_user('foo')")
     self.test_stmt("db.add_user(u)")
     self.test_val("db.get_user('foo')", u)
Example #2
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)")