diff options
author | Stefan Kögl <stefan@skoegl.net> | 2014-06-24 20:33:47 +0200 |
---|---|---|
committer | Stefan Kögl <stefan@skoegl.net> | 2014-06-24 20:33:47 +0200 |
commit | a2e51fb518e02eef9622d00b0009edc6098b1d7a (patch) | |
tree | 7d831ab9bf72caad4604ceb2140ba11f393f388b | |
parent | 036045d79a46df894983dffc0641f535f5cf8d99 (diff) | |
download | python-json-patch-a2e51fb518e02eef9622d00b0009edc6098b1d7a.tar.gz |
Fix make_patch() when root is an array (fixes #28)
-rw-r--r-- | jsonpatch.py | 2 | ||||
-rwxr-xr-x | tests.py | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/jsonpatch.py b/jsonpatch.py index 58fdfe8..219de6c 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -308,7 +308,7 @@ class JsonPatch(object): def compare_lists(path, src, dst): return _compare_lists(path, src, dst) - return cls(list(compare_dicts([], src, dst))) + return cls(list(compare_values([], src, dst))) def to_string(self): """Returns patch set as JSON string.""" @@ -341,6 +341,14 @@ class MakePatchTestCase(unittest.TestCase): res = patch.apply(src) self.assertEqual(res, dst) + def test_root_list(self): + """ Test making and applying a patch of the root is a list """ + src = [{'foo': 'bar', 'boo': 'qux'}] + dst = [{'baz': 'qux', 'foo': 'boo'}] + patch = jsonpatch.make_patch(src, dst) + res = patch.apply(src) + self.assertEqual(res, dst) + class InvalidInputTests(unittest.TestCase): |