Example #1
0
def test_create_array():
    doc = {'a': 1}
    p = [{'add': '$.b[5]', 'value': 1}]
    assert patch(doc, p) == {'a': 1, 'b': [None] * 5 + [1]}

    doc = {}
    p = [{'add': '/b/2/1/3/a', 'value': 2}]
    assert patch(doc, p) == {'b': [None, None, [None, [None, None, None, {'a': 2}]]]}
Example #2
0
def test_create_array():
    doc = {'a': 1}
    p = [{'add': '$.b[5]', 'value': 1}]
    assert patch(doc, p) == {'a': 1, 'b': [None] * 5 + [1]}

    doc = {}
    p = [{'add': '/b/2/1/3/a', 'value': 2}]
    assert patch(doc, p) == {
        'b': [None, None, [None, [None, None, None, {
            'a': 2
        }]]]
    }
Example #3
0
def test_nested_patch():
    local = {'foo': {'bar': 1, 'baz': 2}}
    other = {'foo': {'bar': 2, 'qux': 3}}
    delta = diff(local, other)
    patched = patch(local, delta)
    logging.debug('patched == %s', pprint.pformat(patched))
    assert patched == other
Example #4
0
def test_nested_patch():
    local = {'foo': {'bar': 1, 'baz': 2}}
    other = {'foo': {'bar': 2, 'qux': 3}}
    delta = diff(local, other)
    patched = patch(local, delta)
    logging.debug('patched == %s', pprint.pformat(patched))
    assert patched == other
Example #5
0
def test_nested_array_patch():
    local = {'foo': [{'bar': 1, 'baz': 2}, {'qux': 3, 'quux': 4}]}
    other = {'foo': [{'bar': 2, 'qux': 3}, {'quux': 4, 'corge': 5}]}
    delta = diff(local, other)
    logging.debug('delta == %s', pprint.pformat(delta))
    patched = patch(local, delta)
    logging.debug('patched == %s', pprint.pformat(patched))
    assert patched == other
Example #6
0
def test_simple_patch():
    local = {'foo': 1, 'bar': 2}
    other = {'foo': 2, 'baz': 3}
    delta = diff(local, other)
    patched = patch(local, delta)
    logging.debug('delta == %s', pprint.pformat(delta))
    logging.debug('patched == %s', pprint.pformat(patched))
    assert patched == other
Example #7
0
def test_nested_array_patch():
    local = {'foo': [{'bar': 1, 'baz': 2}, {'qux': 3, 'quux': 4}]}
    other = {'foo': [{'bar': 2, 'qux': 3}, {'quux': 4, 'corge': 5}]}
    delta = diff(local, other)
    logging.debug('delta == %s', pprint.pformat(delta))
    patched = patch(local, delta)
    logging.debug('patched == %s', pprint.pformat(patched))
    assert patched == other
Example #8
0
def test_simple_patch():
    local = {'foo': 1, 'bar': 2}
    other = {'foo': 2, 'baz': 3}
    delta = diff(local, other)
    patched = patch(local, delta)
    logging.debug('delta == %s', pprint.pformat(delta))
    logging.debug('patched == %s', pprint.pformat(patched))
    assert patched == other
Example #9
0
def test_root_array():
    doc = [1, {'a': 2}]
    p = [{'add': '/1/b', 'value': 'test'}]
    assert patch(doc, p) == [1, {'a': 2, 'b': 'test'}]
Example #10
0
def test_root_array():
    doc = [1, {'a': 2}]
    p = [{'add': '/1/b', 'value': 'test'}]
    assert patch(doc, p) == [1, {'a': 2, 'b': 'test'}]