summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Kögl <stefan@skoegl.net>2014-06-24 20:33:47 +0200
committerStefan Kögl <stefan@skoegl.net>2014-06-24 20:33:47 +0200
commita2e51fb518e02eef9622d00b0009edc6098b1d7a (patch)
tree7d831ab9bf72caad4604ceb2140ba11f393f388b
parent036045d79a46df894983dffc0641f535f5cf8d99 (diff)
downloadpython-json-patch-a2e51fb518e02eef9622d00b0009edc6098b1d7a.tar.gz
Fix make_patch() when root is an array (fixes #28)
-rw-r--r--jsonpatch.py2
-rwxr-xr-xtests.py8
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."""
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):