summaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
authorStefan Kögl <stefan@skoegl.net>2012-09-11 11:43:32 +0200
committerStefan Kögl <stefan@skoegl.net>2012-09-11 11:43:32 +0200
commit3829275ade689224dfe48ec503b9204e40a6723c (patch)
treebd409a6553ec357dda195ced6c61aa0155aa378b /tests.py
parent1e4abe62e8fba313f73b7d93f7002bd7647e58a9 (diff)
downloadpython-json-patch-3829275ade689224dfe48ec503b9204e40a6723c.tar.gz
add "copy" operation, fixes #7
Diffstat (limited to 'tests.py')
-rwxr-xr-xtests.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests.py b/tests.py
index b922e77..4cf0ff2 100755
--- a/tests.py
+++ b/tests.py
@@ -72,6 +72,20 @@ class ApplyPatchTestCase(unittest.TestCase):
res = jsonpatch.apply_patch(obj, [{'move': '/foo/1', 'to': '/foo/3'}])
self.assertEqual(res, {'foo': ['all', 'cows', 'eat', 'grass']})
+ def test_copy_object_key(self):
+ obj = {'foo': {'bar': 'baz', 'waldo': 'fred'},
+ 'qux': {'corge': 'grault'}}
+ res = jsonpatch.apply_patch(obj, [{'copy': '/foo/waldo',
+ 'to': '/qux/thud'}])
+ self.assertEqual(res, {'qux': {'thud': 'fred', 'corge': 'grault'},
+ 'foo': {'bar': 'baz', 'waldo': 'fred'}})
+
+ def test_copy_array_item(self):
+ obj = {'foo': ['all', 'grass', 'cows', 'eat']}
+ res = jsonpatch.apply_patch(obj, [{'copy': '/foo/1', 'to': '/foo/3'}])
+ self.assertEqual(res, {'foo': ['all', 'grass', 'cows', 'grass', 'eat']})
+
+
def test_test_success(self):
obj = {'baz': 'qux', 'foo': ['a', 2, 'c']}
jsonpatch.apply_patch(obj, [{'test': '/baz', 'value': 'qux'},