summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Kögl <stefan@skoegl.net>2013-07-12 19:29:22 +0200
committerStefan Kögl <stefan@skoegl.net>2013-07-12 19:29:22 +0200
commita7add82366eaed40c72c5ce8eb35dad40f833319 (patch)
tree1d9359bd53409fcba182de8428b7ad505205b0fe
parentb9924bccf1e8e6a9edae6d278556316b532eac34 (diff)
downloadpython-json-patch-a7add82366eaed40c72c5ce8eb35dad40f833319.tar.gz
add various tests
-rwxr-xr-xtests.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests.py b/tests.py
index 266ed2a..7049055 100755
--- a/tests.py
+++ b/tests.py
@@ -7,6 +7,7 @@ import json
import doctest
import unittest
import jsonpatch
+import jsonpointer
import sys
@@ -112,6 +113,11 @@ class ApplyPatchTestCase(unittest.TestCase):
jsonpatch.apply_patch(obj, [{'op': 'test', 'path': '/baz', 'value': 'qux'},
{'op': 'test', 'path': '/foo/1', 'value': 2}])
+ def test_test_whole_obj(self):
+ obj = {'baz': 1}
+ jsonpatch.apply_patch(obj, [{'op': 'test', 'path': '', 'value': obj}])
+
+
def test_test_error(self):
obj = {'bar': 'qux'}
self.assertRaises(jsonpatch.JsonPatchTestFailed,
@@ -284,6 +290,31 @@ class InvalidInputTests(unittest.TestCase):
self.assertRaises(jsonpatch.JsonPatchException, jsonpatch.apply_patch, src, patch_obj)
+class ConflictTests(unittest.TestCase):
+
+ def test_remove_indexerror(self):
+ src = {"foo": [1, 2]}
+ patch_obj = [ { "op": "remove", "path": "/foo/10"} ]
+ self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, src, patch_obj)
+
+ def test_remove_keyerror(self):
+ src = {"foo": [1, 2]}
+ patch_obj = [ { "op": "remove", "path": "/foo/b"} ]
+ self.assertRaises(jsonpointer.JsonPointerException, jsonpatch.apply_patch, src, patch_obj)
+
+ def test_insert_oob(self):
+ src = {"foo": [1, 2]}
+ patch_obj = [ { "op": "add", "path": "/foo/10", "value": 1} ]
+ self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, src, patch_obj)
+
+ def test_move_into_child(self):
+ src = {"foo": {"bar": {"baz": 1}}}
+ patch_obj = [ { "op": "move", "from": "/foo", "path": "/foo/bar" } ]
+ self.assertRaises(jsonpatch.JsonPatchException, jsonpatch.apply_patch, src, patch_obj)
+
+
+
+
modules = ['jsonpatch']
@@ -294,6 +325,7 @@ def get_suite():
suite.addTest(unittest.makeSuite(EqualityTestCase))
suite.addTest(unittest.makeSuite(MakePatchTestCase))
suite.addTest(unittest.makeSuite(InvalidInputTests))
+ suite.addTest(unittest.makeSuite(ConflictTests))
return suite