diff options
author | Brian Rosmaita <rosmaita.fossdev@gmail.com> | 2017-12-04 15:53:59 -0500 |
---|---|---|
committer | Brian Rosmaita <rosmaita.fossdev@gmail.com> | 2017-12-04 15:53:59 -0500 |
commit | e500b4d90e53468a0b51201ec1df51867ce67736 (patch) | |
tree | cc0768b7e1cd73918ec6769f72cebfbe017cc628 /tests.py | |
parent | df0c56d592c9f1d0fada201b7fa66d9d359ac7a3 (diff) | |
download | python-json-patch-e500b4d90e53468a0b51201ec1df51867ce67736.tar.gz |
Remove extraneous 'value' field for op:remove (#76)
RFC 6902 section 4.2 [0] does not define a 'value' field for
the 'remove' operation. The commit "Merge _op_base classes
into PatchOperation classes" [1] introduced a 'value' field
in _item_removed() in the DiffBuilder class. This patch
removes the 'value' field from the 'remove' operation, adds
a new test, and revises some other tests.
[0] https://tools.ietf.org/html/rfc6902#section-4.2
[1] https://github.com/stefankoegl/python-json-patch/commit/03aa14e8209d59522476726d55bfabf86a28929e
Diffstat (limited to 'tests.py')
-rwxr-xr-x | tests.py | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -368,6 +368,17 @@ class MakePatchTestCase(unittest.TestCase): dest = [7, 2, 1, 0, 9, 4, 3, 6, 5, 8] patch = jsonpatch.make_patch(src, dest) + def test_issue76(self): + """ Make sure op:remove does not include a 'value' field """ + + src = { "name": "fred", "friend": "barney", "spouse": "wilma" } + dst = { "name": "fred", "spouse": "wilma" } + expected = [{"path": "/friend", "op": "remove"}] + patch = jsonpatch.make_patch(src, dst) + self.assertEqual(patch.patch, expected) + res = jsonpatch.apply_patch(src, patch) + self.assertEqual(res, dst) + def test_json_patch(self): old = { 'queue': {'teams_out': [{'id': 3, 'reason': 'If tied'}, {'id': 5, 'reason': 'If tied'}]}, @@ -424,7 +435,7 @@ class OptimizationTests(unittest.TestCase): dst = {'foo': [{'bar': 1}, {'bar': 2, 'baz': 3}]} patch = list(jsonpatch.make_patch(src, dst)) - exp = [{'op': 'remove', 'value': 2, 'path': '/foo/0/baz'}] + exp = [{'op': 'remove', 'path': '/foo/0/baz'}] self.assertEqual(patch, exp) res = jsonpatch.apply_patch(src, patch) @@ -481,11 +492,14 @@ class OptimizationTests(unittest.TestCase): src = [{"a": 1, "b": 2}] dst = [{"b": 2, "c": 2}] exp = [ - {'path': '/0/a', 'op': 'remove', 'value': 1}, + {'path': '/0/a', 'op': 'remove'}, {'path': '/0/c', 'op': 'add', 'value': 2} ] patch = jsonpatch.make_patch(src, dst) self.assertEqual(patch.patch, exp) + # verify that this patch does what we expect + res = jsonpatch.apply_patch(src, patch) + self.assertEqual(res, dst) def test_minimal_patch(self): """ Test whether a minimal patch is created, see #36 """ |