From a2e51fb518e02eef9622d00b0009edc6098b1d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Tue, 24 Jun 2014 20:33:47 +0200 Subject: Fix make_patch() when root is an array (fixes #28) --- jsonpatch.py | 2 +- tests.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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.""" diff --git a/tests.py b/tests.py index 88012de..8dff801 100755 --- a/tests.py +++ b/tests.py @@ -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): -- cgit v1.2.1