Example #1
0
 def test_with_dict(self, acl_list):
     """Test access_control_list setter with a basic dict object
 This is the format the frontend uses"""
     obj = all_models.Control(title="New Control",
                              access_control_list=acl_list(self))
     self.assertIsNotNone(obj.access_control_list)
     acl = obj.access_control_list[0]
     self.assertIsNotNone(acl)
     self.assertIsInstance(acl, all_models.AccessControlList)
     self.assertEqual(acl.person.id, self.person.id)
     self.assertEqual(acl.ac_role.id, self.role.id)
     self.assertEqual(acl.object, obj)
Example #2
0
  def test_with_dict_objs_multiple(self):
    """Test access_control_list setter without ids"""
    role = factories.AccessControlRoleFactory(object_type="Control")
    person_1 = factories.PersonFactory(name="Frodo", email="*****@*****.**")
    person_2 = factories.PersonFactory(name="Bilbo", email="*****@*****.**")
    person_3 = factories.PersonFactory(name="Merry", email="*****@*****.**")
    obj = all_models.Control(title="Test Control")
    obj.access_control_list = [{
        "person": {
            "id": person_1.id,
        },
        "ac_role_id": role.id,
    }, {
        "person": {
            "id": person_2.id,
        },
        "ac_role_id": role.id,
    }]
    db.session.commit()

    acls = db.session.query(
        all_models.AccessControlPerson.person_id,
    ).join(
        all_models.AccessControlList
    ).filter(
        all_models.AccessControlList.object_id == obj.id,
        all_models.AccessControlList.object_type == "Control"
    )

    self.assertItemsEqual([
        (person_1.id, ),
        (person_2.id, ),
    ], acls.all())

    obj.access_control_list = [{
        "person": {
            "id": person_2.id,
        },
        "ac_role_id": role.id,
    }, {
        "person": {
            "id": person_3.id,
        },
        "ac_role_id": role.id,
    }]
    db.session.commit()

    self.assertItemsEqual([
        (person_2.id, ),
        (person_3.id, ),
    ], acls.all())
Example #3
0
    def test_with_dict_objs_multiple(self):
        """Test access_control_list setter without ids"""
        def acl_query():
            return db.session.query(
                all_models.AccessControlList.person_id,
                all_models.AccessControlList.ac_role_id).filter(
                    all_models.AccessControlList.object_id == obj.id,
                    all_models.AccessControlList.object_type ==
                    "Control").all()

        person_1 = all_models.Person(name="Frodo", email="*****@*****.**")
        person_2 = all_models.Person(name="Bilbo", email="*****@*****.**")
        person_3 = factories.PersonFactory(name="Merry",
                                           email="*****@*****.**")
        role = all_models.AccessControlRole(name="Hobbit")
        obj = all_models.Control(title="Test Control",
                                 access_control_list=[{
                                     "person": person_1,
                                     "ac_role": self.role,
                                 }, {
                                     "person": person_2,
                                     "ac_role": role,
                                 }])
        db.session.commit()
        self.assertIsNotNone(obj.access_control_list)
        self.assertEqual(len(obj.access_control_list), 2)
        self.assertEqual(obj.access_control_list[0].person, person_1)
        self.assertEqual(obj.access_control_list[1].person, person_2)

        acls = acl_query()
        self.assertItemsEqual([(person_1.id, self.role.id),
                               (person_2.id, role.id)], acls)

        obj.access_control_list = [{
            "person": {
                "id": person_2.id,
            },
            "ac_role_id": role.id,
        }, {
            "person": {
                "id": person_3.id,
            },
            "ac_role_id": role.id,
        }]
        db.session.commit()

        acls = acl_query()
        self.assertItemsEqual([(person_2.id, role.id), (person_3.id, role.id)],
                              acls)
Example #4
0
    def test_with_dict(self):
        """Test access_control_list setter with a basic dict object.

    This test ensures frontend API compatibility.
    """
        acl_list = [{
            "ac_role_id": self.role.id,
            "person": {
                "id": self.person.id
            }
        }]
        obj = all_models.Control(title="New Control",
                                 access_control_list=acl_list)
        self.assertIsNotNone(obj.access_control_list)
        person, acl = obj.access_control_list[0]
        self.assertIsNotNone(acl)
        self.assertIsInstance(acl, all_models.AccessControlList)
        self.assertEqual(person.id, self.person.id)
        self.assertEqual(acl.ac_role.id, self.role.id)
        self.assertEqual(acl.object, obj)