Esempio n. 1
0
def get_group(id=None, name=None):
    try:
        if id:
            return Group.get(Group.id==id)
        elif name:
            return Group.get(Group.name==name)
        else:
            raise ValueError('nither `id` or `name` was given')
    except Group.DoesNotExist:
        raise NotFoundException("no group could be found with these attributes")
Esempio n. 2
0
def get_group(id=None, name=None):
    try:
        if id:
            return Group.get(Group.id==id)
        elif name:
            return Group.get(Group.name==name)
        else:
            raise ValueError('nither `id` or `name` was given')
    except Group.DoesNotExist:
        raise NotFoundException("no group could be found with these attributes")
Esempio n. 3
0
 def test_assign_user_to_multiple_group(self):
     rebels = Group.create(name='rebels')
     aliens = Group.create(name='aliens')
     allGroups = [aliens, rebels]
     # https://en.wikipedia.org/wiki/They_Live
     user = User.create(name='doubtful')
     user.groups.add(allGroups)
     belongsID = [g.id for g in user.groups]
     allGroupsID = [g.id for g in allGroups]
     eq_((set(belongsID), len(belongsID)), (set(allGroupsID), len(allGroupsID)))
Esempio n. 4
0
 def test_assign_user_to_multiple_group(self):
     rebels = Group.create(name='rebels')
     aliens = Group.create(name='aliens')
     allGroups = [aliens, rebels]
     # https://en.wikipedia.org/wiki/They_Live
     user = User.create(name='doubtful')
     user.groups.add(allGroups)
     belongsID = [g.id for g in user.groups]
     allGroupsID = [g.id for g in allGroups]
     eq_((set(belongsID), len(belongsID)),
         (set(allGroupsID), len(allGroupsID)))
Esempio n. 5
0
 def populate(self):
     with self.udb.atomic():
         cap1 = Capability.create(domain='res1', action=Action.READ)
         cap2 = Capability.create(domain='res2', action=Action.UPDATE)
         grp1 = Group.create(name='grp2')
         grp2 = Group.create(name='grp1')
         usr = User.create(name='usr')
         grp1.capabilities.add(cap1)
         grp2.capabilities.add(cap2)
         usr.groups.add([grp1, grp2])
     return usr, [cap1, cap2]
Esempio n. 6
0
 def test_user_can(self):
     cap1 = Capability.create(domain=Capability.simToReg('volumes/*'),
                              action=Action.CREATE | Action.READ)
     cap2 = Capability.create(domain=Capability.simToReg('volumes/123'),
                              action=Action.UPDATE)
     grp1 = Group.create(name='grp2')
     grp2 = Group.create(name='grp1')
     usr = User.create(name='usr')
     grp1.capabilities.add(cap1)
     grp2.capabilities.add(cap2)
     usr.groups.add([grp1, grp2])
     self.assertTrue(usr.can('volumes/61273', action=Action.CREATE))
     self.assertTrue(usr.can('volumes/123', Action.CREATE | Action.READ))
     self.assertFalse(usr.can('volumes/82828', Action.DELETE))
     self.assertFalse(usr.can('volumes/123', Action.DELETE))
Esempio n. 7
0
 def test_assign_user_to_group(self):
     anons = Group.create(name='anons')
     jhondohe = User.create(name='jhondhoe', password='******')
     anons.users.add(jhondohe)
     anons.save()
     eq_(jhondohe.groups.count(), 1)
     eq_(jhondohe.groups.get().id, anons.id)
Esempio n. 8
0
 def test_assign_capability_to_group(self):
     cap = Capability.create(domain='res', action=Action.DELETE)
     anons = Group.create(name='anons')
     anons.capabilities.add(cap)
     anons.save()
     eq_(anons.capabilities.count(), 1)
     eq_(anons.capabilities.get(), cap)
Esempio n. 9
0
 def test_assign_user_to_group(self):
     anons = Group.create(name='anons')
     jhondohe = User.create(name='jhondhoe', password='******')
     anons.users.add(jhondohe)
     anons.save()
     eq_(jhondohe.groups.count(), 1)
     eq_(jhondohe.groups.get().id, anons.id)
Esempio n. 10
0
 def test_remove_user_from_group(self):
     anons = Group.create(name='anons')
     jhondohe = User.create(name='jhondhoe', password='******')
     anons.users.add(jhondohe)
     anons.save()
     anons.users.remove(jhondohe)
     anons.save()
     eq_(jhondohe.groups.count(), 0)
     eq_(UserToGroup.select().count(), 0)
Esempio n. 11
0
 def test_remove_user_from_group(self):
     anons = Group.create(name='anons')
     jhondohe = User.create(name='jhondhoe', password='******')
     anons.users.add(jhondohe)
     anons.save()
     anons.users.remove(jhondohe)
     anons.save()
     eq_(jhondohe.groups.count(), 0)
     eq_(UserToGroup.select().count(), 0)
Esempio n. 12
0
 def test_assign_duplicate_user_to_group(self):
     anons = Group.create(name='anons')
     jhondohe = User.create(name='jhondhoe', password='******')
     anons.users.add(jhondohe)
     anons.save()
     with self.assertRaises(IntegrityError):
         anons.users.add(jhondohe)
         anons.save()
     eq_(jhondohe.groups.count(), 1)
     eq_(jhondohe.groups.get().id, anons.id)
Esempio n. 13
0
 def test_assign_duplicate_user_to_group(self):
     anons = Group.create(name='anons')
     jhondohe = User.create(name='jhondhoe', password='******')
     anons.users.add(jhondohe)
     anons.save()
     with self.assertRaises(IntegrityError):
         anons.users.add(jhondohe)
         anons.save()
     eq_(jhondohe.groups.count(), 1)
     eq_(jhondohe.groups.get().id, anons.id)
Esempio n. 14
0
 def test_assign_same_capability_to_group(self):
     cap = Capability.create(domain='res', action=Action.DELETE)
     anons = Group.create(name='anons')
     anons.capabilities.add(cap)
     anons.save()
     with self.assertRaises(IntegrityError):
         anons.capabilities.add(cap)
         anons.save()
     eq_(anons.capabilities.count(), 1)
     eq_(anons.capabilities.get(), cap)
Esempio n. 15
0
 def test_group_can(self):
     cap1 = Capability.create(domain=Capability.simToReg('volumes/*'),
                              action=Action.CREATE | Action.READ)
     cap2 = Capability.create(domain=Capability.simToReg('users/123'),
                              action=Action.CREATE | Action.DELETE)
     grp = Group.create(name='grp2')
     grp.capabilities.add([cap1, cap2])
     self.assertTrue(grp.can('volumes/123', Action.CREATE | Action.READ))
     self.assertFalse(grp.can('volumes/82828', Action.DELETE))
     self.assertTrue(grp.can('users/123', Action.DELETE))
     self.assertFalse(grp.can('users/123', Action.UPDATE))
Esempio n. 16
0
 def test_group_unique_name(self):
     Group.create(name='cyclists')
     with self.assertRaises(IntegrityError):
         Group.create(name='cyclists')
Esempio n. 17
0
 def test_group_creation(self):
     newGroup = Group.create(name='chefs')
     Group.get(Group.name == newGroup.name)
     eq_(Group.select().count(), 1)
Esempio n. 18
0
def add_group(name):
    try:
        return Group.create(name=name)
    except IntegrityError:
        raise ConflictException("a group with the same name already exists")
Esempio n. 19
0
def delete_group(id):
    if not Group.delete().where(Group.id == id).execute():
        raise NotFoundException('no group could be found with this id')
Esempio n. 20
0
def delete_group(id):
    if not Group.delete().where(Group.id == id).execute():
        raise NotFoundException('no group could be found with this id')
Esempio n. 21
0
def add_group(name):
    try:
        return Group.create(name=name)
    except IntegrityError:
        raise ConflictException("a group with the same name already exists")
Esempio n. 22
0
 def test_group_creation(self):
     newGroup = Group.create(name='chefs')
     Group.get(Group.name == newGroup.name)
     eq_(Group.select().count(), 1)
Esempio n. 23
0
def get_groups():
    return Group.select()
Esempio n. 24
0
 def test_group_unique_name(self):
     Group.create(name='cyclists')
     with self.assertRaises(IntegrityError):
         Group.create(name='cyclists')