summaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
authorAlexander Shorin <kxepal@gmail.com>2011-12-25 21:32:06 +0400
committerAlexander Shorin <kxepal@gmail.com>2011-12-25 21:32:06 +0400
commitd20e3a6f2512df428aed7c029c52bd1e973a72dd (patch)
treed2da2819f486daa53b775d71bcba6f3a54483b38 /tests.py
parenta1729beaa196b65ddcbaa78dcc28c89db724603d (diff)
downloadpython-json-patch-d20e3a6f2512df428aed7c029c52bd1e973a72dd.tar.gz
Add make_patch function to generate JsonPatch by comparing of two documents.
Diffstat (limited to 'tests.py')
-rwxr-xr-xtests.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests.py b/tests.py
index e958576..e175ce6 100755
--- a/tests.py
+++ b/tests.py
@@ -63,10 +63,39 @@ class ApplyPatchTestCase(unittest.TestCase):
obj, [{'test': '/bar', 'value': 'bar'}])
+class MakePatchTestCase(unittest.TestCase):
+
+ def test_objects(self):
+ src = {'foo': 'bar', 'boo': 'qux'}
+ dst = {'baz': 'qux', 'foo': 'boo'}
+ patch = jsonpatch.make_patch(src, dst)
+ patch.apply(src)
+ self.assertEqual(src, dst)
+
+ def test_arrays(self):
+ src = {'numbers': [1, 2, 3], 'other': [1, 3, 4, 5]}
+ dst = {'numbers': [1, 3, 4, 5], 'other': [1, 3, 4]}
+ patch = jsonpatch.make_patch(src, dst)
+ patch.apply(src)
+ self.assertEqual(src, dst)
+
+ def test_complex_object(self):
+ src = {'data': [
+ {'foo': 1}, {'bar': [1, 2, 3]}, {'baz': {'1': 1, '2': 2}}
+ ]}
+ dst = {'data': [
+ {'foo': [42]}, {'bar': []}, {'baz': {'boo': 'oom!'}}
+ ]}
+ patch = jsonpatch.make_patch(src, dst)
+ patch.apply(src)
+ self.assertEqual(src, dst)
+
+
def suite():
suite = unittest.TestSuite()
suite.addTest(doctest.DocTestSuite(jsonpatch))
suite.addTest(unittest.makeSuite(ApplyPatchTestCase))
+ suite.addTest(unittest.makeSuite(MakePatchTestCase))
return suite
if __name__ == '__main__':