@@ -671,6 +671,22 @@ def test_create_with_pointer(self):
671671 self .assertEqual (result , expected )
672672
673673
674+ class JsonPatchCreationTest (unittest .TestCase ):
675+
676+ def test_creation_fails_with_invalid_patch (self ):
677+ invalid_patches = [
678+ { 'path' : '/foo' , 'value' : 'bar' },
679+ {'op' : 0xADD , 'path' : '/foo' , 'value' : 'bar' },
680+ {'op' : 'boo' , 'path' : '/foo' , 'value' : 'bar' },
681+ {'op' : 'add' , 'value' : 'bar' },
682+ ]
683+ for patch in invalid_patches :
684+ with self .assertRaises (jsonpatch .InvalidJsonPatch ):
685+ jsonpatch .JsonPatch ([patch ])
686+
687+ with self .assertRaises (jsonpointer .JsonPointerException ):
688+ jsonpatch .JsonPatch ([{'op' : 'add' , 'path' : 'foo' , 'value' : 'bar' }])
689+
674690
675691if __name__ == '__main__' :
676692 modules = ['jsonpatch' ]
@@ -687,6 +703,7 @@ def get_suite():
687703 suite .addTest (unittest .makeSuite (ConflictTests ))
688704 suite .addTest (unittest .makeSuite (OptimizationTests ))
689705 suite .addTest (unittest .makeSuite (JsonPointerTests ))
706+ suite .addTest (unittest .makeSuite (JsonPatchCreationTest ))
690707 return suite
691708
692709
0 commit comments