diff options
| author | Alexander Shorin <kxepal@gmail.com> | 2011-12-25 21:32:06 +0400 |
|---|---|---|
| committer | Alexander Shorin <kxepal@gmail.com> | 2011-12-25 21:32:06 +0400 |
| commit | d20e3a6f2512df428aed7c029c52bd1e973a72dd (patch) | |
| tree | d2da2819f486daa53b775d71bcba6f3a54483b38 /tests.py | |
| parent | a1729beaa196b65ddcbaa78dcc28c89db724603d (diff) | |
| download | python-json-patch-d20e3a6f2512df428aed7c029c52bd1e973a72dd.tar.gz | |
Add make_patch function to generate JsonPatch by comparing of two documents.
Diffstat (limited to 'tests.py')
| -rwxr-xr-x | tests.py | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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__': |
