diff options
author | selurvedu <selurvedu@users.noreply.github.com> | 2016-04-08 04:39:58 +0000 |
---|---|---|
committer | selurvedu <selurvedu@users.noreply.github.com> | 2016-04-08 04:39:58 +0000 |
commit | a2cd6da7e4418c1012fbed76aefc983971fc4808 (patch) | |
tree | 228247fe5a45e6a108e2adea64be563cddb02c4d /tests.py | |
parent | b15d8f1ec18e4f3191ba668e63520018a47e37de (diff) | |
parent | 73acf7ff2a83c411217aff024d35cc8b602180ed (diff) | |
download | python-json-patch-a2cd6da7e4418c1012fbed76aefc983971fc4808.tar.gz |
Merge branch 'list_tests@v1.9' into list_tests@v1.13
Conflicts:
tests.py
Diffstat (limited to 'tests.py')
-rwxr-xr-x | tests.py | 55 |
1 files changed, 48 insertions, 7 deletions
@@ -327,13 +327,18 @@ class MakePatchTestCase(unittest.TestCase): self.assertEqual(res, dst) def test_use_move_instead_of_add_remove(self): - src = {'foo': [1, 2, 3]} - dst = {'foo': [3, 1, 2]} - patch = list(jsonpatch.make_patch(src, dst)) - self.assertEqual(len(patch), 1) - self.assertEqual(patch[0]['op'], 'move') - res = jsonpatch.apply_patch(src, patch) - self.assertEqual(res, dst) + def fn(_src, _dst): + patch = list(jsonpatch.make_patch(_src, _dst)) + # Check if there are only 'move' operations + for p in patch: + self.assertEqual(p['op'], 'move') + res = jsonpatch.apply_patch(_src, patch) + self.assertEqual(res, _dst) + + fn({'foo': [1, 2, 3]}, {'foo': [3, 1, 2]}) + fn({'foo': [1, 2, 3]}, {'foo': [3, 2, 1]}) + fn([1, 2, 3], [3, 1, 2]) + fn([1, 2, 3], [3, 2, 1]) def test_escape(self): src = {"x/y": 1} @@ -383,6 +388,41 @@ class MakePatchTestCase(unittest.TestCase): self.assertEqual(patch.patch, exp) +class ListTests(unittest.TestCase): + + def test_fail_prone_list_1(self): + """ Test making and applying a patch of the root is a list """ + src = ['a', 'r', 'b'] + dst = ['b', 'o'] + patch = jsonpatch.make_patch(src, dst) + res = patch.apply(src) + self.assertEqual(res, dst) + + def test_fail_prone_list_2(self): + """ Test making and applying a patch of the root is a list """ + src = ['a', 'r', 'b', 'x', 'm', 'n'] + dst = ['b', 'o', 'm', 'n'] + patch = jsonpatch.make_patch(src, dst) + res = patch.apply(src) + self.assertEqual(res, dst) + + def test_fail_prone_list_3(self): + """ Test making and applying a patch of the root is a list """ + src = ['boo1', 'bar', 'foo1', 'qux'] + dst = ['qux', 'bar'] + patch = jsonpatch.make_patch(src, dst) + res = patch.apply(src) + self.assertEqual(res, dst) + + def test_fail_prone_list_4(self): + """ Test making and applying a patch of the root is a list """ + src = ['bar1', 59, 'foo1', 'foo'] + dst = ['foo', 'bar', 'foo1'] + patch = jsonpatch.make_patch(src, dst) + res = patch.apply(src) + self.assertEqual(res, dst) + + class InvalidInputTests(unittest.TestCase): def test_missing_op(self): @@ -447,6 +487,7 @@ if __name__ == '__main__': suite.addTest(unittest.makeSuite(ApplyPatchTestCase)) suite.addTest(unittest.makeSuite(EqualityTestCase)) suite.addTest(unittest.makeSuite(MakePatchTestCase)) + suite.addTest(unittest.makeSuite(ListTests)) suite.addTest(unittest.makeSuite(InvalidInputTests)) suite.addTest(unittest.makeSuite(ConflictTests)) return suite |