Ejemplo n.º 1
0
def test_fieldwalker_value_get_4():
    # array value
    doc = {"a": [1]}
    path = "a"
    value = [1, [1]]
    field_value = FieldWalker(doc).go(path).get().value
    assert list(field_value.iter_full()) == value
Ejemplo n.º 2
0
def test_fieldwalker_value_get_19():
    doc = {"a": [{"b": [0, {"c": [1, "x"]}]},
                 {"b": [2, {"c": [3, "y"]}]},
                 {"b": [4, {"c": [5, "z"]}]}]}
    path = "a.b.1.c"
    value = [1, "x", [1, "x"], 3, "y", [3, "y"], 5, "z", [5, "z"]]
    field_value = FieldWalker(doc).go(path).get().value
    assert list(field_value.iter_full()) == value
Ejemplo n.º 3
0
def test_fieldwalker_value_set_7():
    doc = {"a": [{"b": 0}, {"b": 1}]}
    path = "a.b"
    value = 10

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        with pytest.raises(FieldWriteError):
            fieldwalker.set(value)
Ejemplo n.º 4
0
def test_fieldwalker_value_set_8():
    doc = {}

    fieldwalker = FieldWalker(doc)
    with fieldwalker:
        fieldwalker.go("a.b")
        fieldwalker.set(1)
        fieldwalker.go("a")
        with pytest.raises(FieldWriteError):
            fieldwalker.set(2)
Ejemplo n.º 5
0
def test_fieldwalker_clean_result_1():
    doc = {"a": 5, "b": 8}

    fieldwalker = FieldWalker(doc)

    with fieldwalker:
        fieldwalker.go("b").get()
        fieldwalker.go("a").get()

        assert fieldwalker.value == [5]
Ejemplo n.º 6
0
def test_fieldwalker_value_get_20():
    doc = {"a": [{"b": [{"c": [0, {"d": [1, "x"]}]},
                        {"c": [2, {"d": [3, "y"]}]},
                        {"c": [4, {"d": [5, "z"]}]}]},
                 {"b": [{"c": [10, {"d": [11, "i"]}]},
                        {"c": [12, {"d": [13, "j"]}]},
                        {"c": [14, {"d": [15, "k"]}]}]}
                 ]}
    path = "a.b.c.1.d"
    value = [
        1, "x", [1, "x"], 3, "y", [3, "y"], 5, "z", [5, "z"],
        11, "i", [11, "i"], 13, "j", [13, "j"], 15, "k", [15, "k"]
    ]
    field_value = FieldWalker(doc).go(path).get().value
    assert list(field_value.iter_full()) == value
Ejemplo n.º 7
0
def test_fieldwalker_value_get_22():
    # array opsitioned and embedded documents and digit-str field
    doc = {"a": [{"b": [0, {"c": 1}, {"1": 99}]},
                 {"b": [2, {"c": 3}]}]}
    path = "a.b.1.c"
    value = [1, 3]
    assert FieldWalker(doc).go(path).get().value == value
Ejemplo n.º 8
0
def test_fieldwalker_value_get_18():
    # array opsitioned and embedded documents
    doc = {"a": [{"b": [0, {"c": 1}]},
                 {"b": [2, {"c": 3}]},
                 {"b": [4, {"c": 5}]}]}
    path = "a.b.1.c"
    value = [1, 3, 5]
    assert FieldWalker(doc).go(path).get().value == value
Ejemplo n.º 9
0
def test_fieldwalker_value_get_25():
    doc = {"a": [{"b": [{"c": [0, {"d": [1, "x"]}]},
                        {"X": [2, {"d": [3, "y"]}]},
                        {"c": [4, {"d": [5, "z"]}]}]},
                 {"b": [{"c": [10, {"d": [11, "i"]}]},
                        {"c": [12, {"d": [13, "j"]}]},
                        {"c": [14, {"d": [15, "k"]}]}]}
                 ]}
    path = "a.b.c.1.d.1"
    value = ["x", "z", "i", "j", "k"]
    assert FieldWalker(doc).go(path).get().value == value
Ejemplo n.º 10
0
def test_fieldwalker_value_set_6():
    doc = {"a": [1]}
    path = "a.2.b"
    value = 20

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        fieldwalker.set(value)
        fieldwalker.commit()
    assert fieldwalker.doc == {"a": [1, None, {"b": 20}]}
Ejemplo n.º 11
0
def test_fieldwalker_value_set_2():
    doc = {"a": {"b": 1}}
    path = "a.b"
    value = 10

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        fieldwalker.set(value)
        fieldwalker.commit()
    assert fieldwalker.doc == {"a": {"b": 10}}
Ejemplo n.º 12
0
def test_fieldwalker_value_get_27():
    doc = {"a": [{"b": [{"c": [{"0": [{"d": [0, 1]}]}, {"d": [1]}]},
                        {"c": [{"0": [{"d": [0, 2]}]}, {"d": [3, "y"]}]},
                        {"c": [{"d": [5, "z"]}, {"0": [{"d": [0, 3]}]}]}]},
                 {"b": [{"c": [{"0": [{"d": [0, 4]}]}, {"d": [11, "i"]}]},
                        {"c": [{"0": [{"d": [0, 5]}]}, {"d": [13, "j"]}]},
                        {"c": [{"0": [{"d": [0, 6]}]}, {"d": [15, "k"]}]}]}
                 ]}
    path = "a.b.c.0.d.1"
    value = [1, 2, 3, "z", 4, 5, 6]
    fw = FieldWalker(doc).go(path).get()
    assert fw.value == value
Ejemplo n.º 13
0
def test_fieldwalker_value_set_3():
    doc = {"a": [1, 2, 3]}
    path = "a.1"
    value = 20

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        fieldwalker.set(value)
        fieldwalker.commit()
    assert fieldwalker.doc == {"a": [1, 20, 3]}
Ejemplo n.º 14
0
def test_fieldwalker_value_get_26():
    # array element shortage
    doc = {"a": [{"b": [{"c": [0, {"d": [1]}]},
                        {"c": [2, {"d": [3, "y"]}]},
                        {"c": [4, {"d": [5, "z"]}]}]},
                 {"b": [{"c": [10, {"d": [11, "i"]}]},
                        {"c": [12, {"d": [13, "j"]}]},
                        {"c": [14, {"d": [15, "k"]}]}]}
                 ]}
    path = "a.b.c.1.d.1"
    value = ["y", "z", "i", "j", "k"]
    assert FieldWalker(doc).go(path).get().value == value
Ejemplo n.º 15
0
def test_fieldwalker_value_set_4():
    doc = {"a": [1, 2, 3]}
    path = "a.5"
    value = 9

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        fieldwalker.set(value)
        assert doc == {"a": [1, 2, 3]}
        fieldwalker.commit()
    assert fieldwalker.doc == {"a": [1, 2, 3, None, None, 9]}
Ejemplo n.º 16
0
def test_fieldwalker_value_set_1():
    # single value
    doc = {"a": 1}
    path = "a"
    value = 10

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        fieldwalker.set(value)
        fieldwalker.commit()
    assert fieldwalker.doc == {"a": 10}
Ejemplo n.º 17
0
def test_fieldwalker_value_get_7():
    doc = {"a": {"b": [1]}}
    path = "a.b"
    value = [1, [1]]
    field_value = FieldWalker(doc).go(path).get().value
    assert list(field_value.iter_full()) == value
Ejemplo n.º 18
0
def test_fieldwalker_value_get_6():
    doc = {"a": [0, [1], 2]}
    path = "a"
    value = [0, [1], 2, [0, [1], 2]]
    field_value = FieldWalker(doc).go(path).get().value
    assert list(field_value.iter_full()) == value
Ejemplo n.º 19
0
def test_fieldwalker_value_get_1():
    # single value
    doc = {"a": 1}
    path = "a"
    value = [1]
    assert FieldWalker(doc).go(path).get().value == value
Ejemplo n.º 20
0
def test_fieldwalker_value_get_29():
    doc = {"a": [True, True, {"2": True, "3": True}]}
    path = "a.3"
    value = [True]
    fw = FieldWalker(doc).go(path).get()
    assert fw.value == value
Ejemplo n.º 21
0
def test_fieldwalker_value_get_16():
    doc = {"a": [{"1": 0}, 1, {"1": 2}, 3, {"1": 4}]}
    path = "a.1"
    value = [0, 2, 4, 1]  # notice that doc values are before array element
    assert FieldWalker(doc).go(path).get().value == value
Ejemplo n.º 22
0
def test_fieldwalker_value_get_12():
    doc = {"a": [[0, 1], 1]}
    path = "a.0.1"
    value = [1]
    assert FieldWalker(doc).go(path).get().value == value
Ejemplo n.º 23
0
def test_fieldwalker_value_get_14():
    doc = {"a": [{"b": [0, 1]}, {"b": [2, 3]}, {"b": [4, 5]}]}
    path = "a.b.1"
    value = [1, 3, 5]
    assert FieldWalker(doc).go(path).get().value == value
Ejemplo n.º 24
0
def test_fieldwalker_value_get_2():
    doc = {"a": {"b": 1}}
    path = "a"
    value = [{"b": 1}]
    assert FieldWalker(doc).go(path).get().value == value
Ejemplo n.º 25
0
def test_fieldwalker_value_get_15():
    # array opsitioned and digit-str field
    doc = {"a": [{"1": 0}, 1]}
    path = "a.1"
    value = [0, 1]
    assert FieldWalker(doc).go(path).get().value == value
Ejemplo n.º 26
0
def test_fieldwalker_value_get_8():
    doc = {"a": [{"b": [0, 1]}, {"b": [2, 3]}, {"b": [4, 5]}]}
    path = "a.b"
    value = [0, 1, [0, 1], 2, 3, [2, 3], 4, 5, [4, 5]]
    field_value = FieldWalker(doc).go(path).get().value
    assert list(field_value.iter_full()) == value
Ejemplo n.º 27
0
def test_fieldwalker_value_get_9():
    # array opsitioned
    doc = {"a": {"b": [1]}}
    path = "a.b.0"
    value = [1]
    assert FieldWalker(doc).go(path).get().value == value
Ejemplo n.º 28
0
def test_fieldwalker_value_get_28():
    doc = {"a": [{"1": {"b": 5}}, 1]}
    path = "a.1.b"
    value = [5]
    fw = FieldWalker(doc).go(path).get()
    assert fw.value == value
Ejemplo n.º 29
0
def test_fieldwalker_value_get_13():
    doc = {"a": [{"1": 0}, 1]}
    path = "a.0.1"
    value = [0]
    assert FieldWalker(doc).go(path).get().value == value
Ejemplo n.º 30
0
def test_fieldwalker_value_get_17():
    doc = {"a": [{"b": [0, 1, {"1": 99}]},
                 {"b": [2, 3]}]}
    path = "a.b.1"
    value = [99, 1, 3]  # doc value (99) are before array elements (1, 3)
    assert FieldWalker(doc).go(path).get().value == value