コード例 #1
0
def test_it_create_child():
    from alchemyjsonschema.tests import models as m
    from alchemyjsonschema import SchemaFactory, StructuralWalker
    from alchemyjsonschema.dictify import ModelLookup

    factory = SchemaFactory(StructuralWalker)
    a_schema = factory(m.A0)
    modellookup = ModelLookup(m)

    a0 = m.A0(
        pk=1, name="a0", children=[m.A1(pk=1, name="a00"), m.A1(pk=2, name=("a01"))]
    )

    assert len(a0.children) == 2
    params = {
        "pk": 1,
        "name": "a0",
        "children": [
            {"name": "new"},
            {"name": "a00", "pk": 1},
            {"name": "update", "pk": 2},
        ],
    }
    _callFUT(a0, params, a_schema, modellookup)
    assert len(a0.children) == 3
コード例 #2
0
def test_it_update_parent__full():
    from alchemyjsonschema.tests import models as m
    from alchemyjsonschema import SchemaFactory, AlsoChildrenWalker
    from alchemyjsonschema.dictify import ModelLookup

    factory = SchemaFactory(AlsoChildrenWalker)
    a_schema = factory(m.A0)
    modellookup = ModelLookup(m)

    a0 = m.A0(pk=1,
              name="a0",
              children=[m.A1(pk=1, name="a00"),
                        m.A1(pk=2, name=("a01"))])

    assert a0.name == "a0"
    params = {
        "pk": 1,
        "name": "updated",
        "children": [{
            "name": "a00",
            "pk": 1
        }, {
            "name": "a01",
            "pk": 2
        }]
    }
    _callFUT(a0, params, a_schema, modellookup)
    assert a0.name == "updated"
コード例 #3
0
def test_it_reverse_update():
    from alchemyjsonschema.tests import models as m
    from alchemyjsonschema import SchemaFactory, StructuralWalker
    from alchemyjsonschema.dictify import ModelLookup

    factory = SchemaFactory(StructuralWalker)
    a_schema = factory(m.A1)
    modellookup = ModelLookup(m)

    a0 = m.A0(pk=1, name="a0", children=[m.A1(pk=1, name="a00"), m.A1(pk=2, name=("a01"))])

    assert a0.name == "a0"
    params = {"pk": 1, "name": "a00", "parent": {"name": "updated", "pk": 1}}
    _callFUT(a0.children[0], params, a_schema, modellookup)
    assert a0.name == "updated"
コード例 #4
0
def test_it_update_parent__onlyone():
    from alchemyjsonschema.tests import models as m
    from alchemyjsonschema import SchemaFactory, NoForeignKeyWalker
    from alchemyjsonschema.dictify import ModelLookup

    factory = SchemaFactory(NoForeignKeyWalker)
    a_schema = factory(m.A0)
    modellookup = ModelLookup(m)

    a0 = m.A0(pk=1, name="a0", children=[m.A1(pk=1, name="a00"), m.A1(pk=2, name=("a01"))])

    assert a0.name == "a0"
    params = {"pk": 1, "name": "updated"}
    _callFUT(a0, params, a_schema, modellookup)
    assert a0.name == "updated"
    assert len(a0.children) == 2
コード例 #5
0
def test_it_delete_child():
    from alchemyjsonschema.tests import models as m
    from alchemyjsonschema import SchemaFactory, AlsoChildrenWalker
    from alchemyjsonschema.dictify import ModelLookup

    factory = SchemaFactory(AlsoChildrenWalker)
    a_schema = factory(m.A0)
    modellookup = ModelLookup(m)

    a0 = m.A0(pk=1,
              name="a0",
              children=[m.A1(pk=1, name="a00"),
                        m.A1(pk=2, name=("a01"))])

    assert len(a0.children) == 2
    params = {"pk": 1, "name": "a0", "children": [{"name": "a00", "pk": 1}]}
    _callFUT(a0, params, a_schema, modellookup)
    assert len(a0.children) == 1