diff options
author | Dave Shawley <daveshawley@gmail.com> | 2020-11-17 08:15:25 -0500 |
---|---|---|
committer | Dave Shawley <daveshawley@gmail.com> | 2020-11-17 08:19:29 -0500 |
commit | a7ef7e80d0024b71794c22fd09e35389c04de964 (patch) | |
tree | 392b67f67257e4bd8ef75431e8ff4383c144d03d /tests.py | |
parent | bfc0f5a68fc45a1335488c953fd055750528f16e (diff) | |
download | python-json-patch-a7ef7e80d0024b71794c22fd09e35389c04de964.tar.gz |
fix #110: Validate patch documents during creation.
Diffstat (limited to 'tests.py')
-rwxr-xr-x | tests.py | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -671,6 +671,22 @@ class JsonPointerTests(unittest.TestCase): self.assertEqual(result, expected) +class JsonPatchCreationTest(unittest.TestCase): + + def test_creation_fails_with_invalid_patch(self): + invalid_patches = [ + { 'path': '/foo', 'value': 'bar'}, + {'op': 0xADD, 'path': '/foo', 'value': 'bar'}, + {'op': 'boo', 'path': '/foo', 'value': 'bar'}, + {'op': 'add', 'value': 'bar'}, + ] + for patch in invalid_patches: + with self.assertRaises(jsonpatch.InvalidJsonPatch): + jsonpatch.JsonPatch([patch]) + + with self.assertRaises(jsonpointer.JsonPointerException): + jsonpatch.JsonPatch([{'op': 'add', 'path': 'foo', 'value': 'bar'}]) + if __name__ == '__main__': modules = ['jsonpatch'] @@ -687,6 +703,7 @@ if __name__ == '__main__': suite.addTest(unittest.makeSuite(ConflictTests)) suite.addTest(unittest.makeSuite(OptimizationTests)) suite.addTest(unittest.makeSuite(JsonPointerTests)) + suite.addTest(unittest.makeSuite(JsonPatchCreationTest)) return suite |