Exemple #1
0
    def test_error_when_some_paths_lead_to_different_object(self, sess):
        sess.add(Parent(parent_id=1))
        sess.add(Parent(parent_id=2))
        sess.add(ChildA(child_id=1, parent_id=1, name='A'))
        sess.add(ChildB(child_id=1, parent_id=1, name='B'))
        sess.add(ChildC(child_id=1, parent_id=2, name='C'))
        sess.commit()

        paths = [
            [TripleGrandChild.__table__, ChildA.__table__, Parent.__table__],
            [TripleGrandChild.__table__, ChildB.__table__, Parent.__table__],
            [TripleGrandChild.__table__, ChildC.__table__, Parent.__table__]
        ]
        cn = sut.MultiPathConstraint(paths)

        actual = cn.check({"parent_a_id": 1,
                           "parent_b_id": 1,
                           "parent_c_id": 1},
                          session=sess)

        unwrapped = actual.unwrap()
        assert len(unwrapped) == 1
        assert set(*unwrapped[0].keys()) == {"parent_a_id", "parent_b_id",
                                             "parent_c_id"}
        assert unwrapped[0].values() == [["mismatch (parent)"]]
Exemple #2
0
    def test_find_all_multi_path_constraints(self):
        # pylint: disable=protected-access
        actual = sut.create_multi_path_constraints(GrandChild.__table__)
        expected = sut.MultiPathConstraint(
            [[GrandChild.__table__, ChildA.__table__, Parent.__table__],
             [GrandChild.__table__, ChildB.__table__, Parent.__table__]])

        assert len(actual) == 1
        assert actual[0]._foreign_keys == expected._foreign_keys
Exemple #3
0
    def test_no_error_when_paths_lead_to_identical_object(self, sess):
        sess.add(Parent(parent_id=1))
        sess.add(ChildA(child_id=1, parent_id=1, name='A'))
        sess.add(ChildB(child_id=1, parent_id=1, name='B'))
        sess.commit()
        paths = [[GrandChild.__table__, ChildA.__table__, Parent.__table__],
                 [GrandChild.__table__, ChildB.__table__, Parent.__table__]]
        cn = sut.MultiPathConstraint(paths)

        actual = cn.check({"parent_a_id": 1, "parent_b_id": 1}, session=sess)

        assert not actual
Exemple #4
0
    def test_that_key_map_is_applied_appropriately(self, sess):
        def key_map(attr):
            if attr == "parent_a_id":
                return "A"
            elif attr == "parent_b_id":
                return "B"

        sess.add(Parent(parent_id=1))
        sess.add(ChildA(child_id=1, parent_id=1, name='A'))
        sess.add(ChildB(child_id=1, parent_id=1, name='B'))
        sess.commit()
        paths = [[GrandChild.__table__, ChildA.__table__, Parent.__table__],
                 [GrandChild.__table__, ChildB.__table__, Parent.__table__]]
        cn = sut.MultiPathConstraint(paths, key_map=key_map)

        actual = cn.check({"A": 1, "B": 1}, session=sess)

        assert not actual