Skip to content

Commit 61b7412

Browse files
committed
test some invalid inputs
1 parent c84a556 commit 61b7412

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,22 @@ def test_add_nested(self):
262262
self.assertEqual(expected, res)
263263

264264

265+
class InvalidInputTests(unittest.TestCase):
266+
267+
def test_missing_op(self):
268+
# an "op" member is required
269+
src = {"foo": "bar"}
270+
patch_obj = [ { "path": "/child", "value": { "grandchild": { } } } ]
271+
self.assertRaises(jsonpatch.JsonPatchException, jsonpatch.apply_patch, src, patch_obj)
272+
273+
274+
def test_invalid_op(self):
275+
# "invalid" is not a valid operation
276+
src = {"foo": "bar"}
277+
patch_obj = [ { "op": "invalid", "path": "/child", "value": { "grandchild": { } } } ]
278+
self.assertRaises(jsonpatch.JsonPatchException, jsonpatch.apply_patch, src, patch_obj)
279+
280+
265281
modules = ['jsonpatch']
266282

267283

@@ -271,6 +287,7 @@ def get_suite():
271287
suite.addTest(unittest.makeSuite(ApplyPatchTestCase))
272288
suite.addTest(unittest.makeSuite(EqualityTestCase))
273289
suite.addTest(unittest.makeSuite(MakePatchTestCase))
290+
suite.addTest(unittest.makeSuite(InvalidInputTests))
274291
return suite
275292

276293

0 commit comments

Comments
 (0)