def test_permissions_failure(self):
        map = DomainGroupMap()

        with self.assertRaises(ValueError) as cm1:
            map.has_perm('foobar')

        with self.assertRaises(ValueError) as cm2:
            map.set_perm('boofar', True)
    def test_permissions_success(self):
        map = DomainGroupMap()

        self.assertTrue(map.has_perm(map.READ_PERM))
        self.assertTrue(map.has_perm(map.WRITE_PERM))
        self.assertFalse(map.has_perm(map.DELETE_PERM))

        self.assertEquals(map.validate(), None)

        my_dict = map.to_dict()
        self.assertTrue(my_dict["can_read"])
        self.assertTrue(my_dict["can_write"])
        self.assertFalse(my_dict["can_delete"])

        self.assertEquals(map.validate(), None)

        map.set_perm(map.READ_PERM, True)
        self.assertTrue(map.has_perm(map.READ_PERM))
        self.assertTrue(map.has_perm(map.WRITE_PERM))
        self.assertFalse(map.has_perm(map.DELETE_PERM))

        self.assertEquals(map.validate(), None)

        map.set_perm(map.READ_PERM, False)
        map.set_perm(map.WRITE_PERM, True)
        self.assertFalse(map.has_perm(map.READ_PERM))
        self.assertTrue(map.has_perm(map.WRITE_PERM))
        self.assertFalse(map.has_perm(map.DELETE_PERM))

        self.assertEquals(map.validate(), None)

        map.set_perm(map.WRITE_PERM, False)
        map.set_perm(map.DELETE_PERM, True)
        self.assertFalse(map.has_perm(map.READ_PERM))
        self.assertFalse(map.has_perm(map.WRITE_PERM))
        self.assertTrue(map.has_perm(map.DELETE_PERM))

        self.assertEquals(map.validate(), None)

        map.set_perm(map.DELETE_PERM, False)
        self.assertFalse(map.has_perm(map.READ_PERM))
        self.assertFalse(map.has_perm(map.WRITE_PERM))
        self.assertFalse(map.has_perm(map.DELETE_PERM))

        self.assertEquals(map.validate(), None)

        my_dict = map.to_dict()
        self.assertFalse(my_dict["can_read"])
        self.assertFalse(my_dict["can_write"])
        self.assertFalse(my_dict["can_delete"])
Example #3
0
    def create_map(self, domain_id, group_id, can_read, can_write, can_delete):
        map = ModelMap()
        map.domain_id = domain_id
        map.group_id = group_id
        map.set_perm(map.READ_PERM, can_read)
        map.set_perm(map.WRITE_PERM, can_write)
        map.set_perm(map.DELETE_PERM, can_delete)
        map.save()

        return map
Example #4
0
    def create_map(self, domain_id, group_id, can_read, can_write, can_delete):
        map = ModelMap()
        map.domain_id = domain_id
        map.group_id = group_id
        map.set_perm(map.READ_PERM, can_read)
        map.set_perm(map.WRITE_PERM, can_write)
        map.set_perm(map.DELETE_PERM, can_delete)
        map.save()

        return map