diff options
author | Lucas Alvares Gomes <lucasagomes@gmail.com> | 2014-01-22 17:02:42 +0000 |
---|---|---|
committer | Lucas Alvares Gomes <lucasagomes@gmail.com> | 2014-02-03 17:21:05 +0000 |
commit | ad66344ad6ec13403d90a12e959e980a4f1933dd (patch) | |
tree | af2d0e410837980e1f165d304db11cbd817f30f2 /tests.py | |
parent | d725141a0d5bbd0f9446cc9e3820ccd2ff78cbcd (diff) | |
download | python-json-patch-ad66344ad6ec13403d90a12e959e980a4f1933dd.tar.gz |
Catch KeyError when accessing the sub-doc items
Diffstat (limited to 'tests.py')
-rwxr-xr-x | tests.py | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -75,6 +75,12 @@ class ApplyPatchTestCase(unittest.TestCase): 'value': 'boo'}]) self.assertEqual(res['foo'], ['bar', 'boo', 'baz']) + def test_move_object_keyerror(self): + obj = {'foo': {'bar': 'baz'}, + 'qux': {'corge': 'grault'}} + patch_obj = [ {'op': 'move', 'from': '/foo/non-existent', 'path': '/qux/thud'} ] + self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, obj, patch_obj) + def test_move_object_key(self): obj = {'foo': {'bar': 'baz', 'waldo': 'fred'}, 'qux': {'corge': 'grault'}} @@ -94,6 +100,12 @@ class ApplyPatchTestCase(unittest.TestCase): res = jsonpatch.apply_patch(obj, patch) self.assertEqual(res, [{'bar': [{"foo": []}]}]) + def test_copy_object_keyerror(self): + obj = {'foo': {'bar': 'baz'}, + 'qux': {'corge': 'grault'}} + patch_obj = [{'op': 'copy', 'from': '/foo/non-existent', 'path': '/qux/thud'}] + self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, obj, patch_obj) + def test_copy_object_key(self): obj = {'foo': {'bar': 'baz', 'waldo': 'fred'}, 'qux': {'corge': 'grault'}} @@ -314,6 +326,11 @@ class ConflictTests(unittest.TestCase): patch_obj = [ { "op": "remove", "path": "/foo/b"} ] self.assertRaises(jsonpointer.JsonPointerException, jsonpatch.apply_patch, src, patch_obj) + def test_remove_keyerror_dict(self): + src = {'foo': {'bar': 'barz'}} + patch_obj = [ { "op": "remove", "path": "/foo/non-existent"} ] + self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, src, patch_obj) + def test_insert_oob(self): src = {"foo": [1, 2]} patch_obj = [ { "op": "add", "path": "/foo/10", "value": 1} ] |