def test_field_not_found():
    operation = append(["offer"], explode("offer"))
    (res, err) = operation({"one": 1})
    assert res is None
    assert err is not None
    assert "offer" in err
    assert err["offer"] == "offer not found"
def test_field_list_two_rows_two_different_fields():
    operation = append(["nested"], explode("nested"))
    (res, err) = operation(
        {"nested": [{
            "one": 1,
            "two": 2
        }, {
            "one": 1,
            "three": 3
        }]})

    expected = {
        "nested_one": 1,
        "nested_one_1": 1,
        "nested_two": 2,
        "nested_three_1": 3
    }
    check_dict_by_field(res, expected)
def test_field_list_two_rows_one_field():
    operation = append(["nested"], explode("nested"))
    (res, err) = operation({"nested": [{"one": 1}, {"one": 1}]})

    expected = {"nested_one": 1, "nested_one_1": 1}
    check_dict_by_field(res, expected)
def test_field_object_two_fields():
    operation = append(["nested"], explode("nested"))
    (res, err) = operation({"nested": {"one": 1, "two": 2}})

    expected = {"nested_one": 1, "nested_two": 2}
    check_dict_by_field(res, expected)
def test_empty():
    operation = append(["a"], explode("a"))
    (res, err) = operation(None)
    assert res is None