@@ -671,6 +671,22 @@ def test_create_with_pointer(self):
671
671
self .assertEqual (result , expected )
672
672
673
673
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
+
674
690
675
691
if __name__ == '__main__' :
676
692
modules = ['jsonpatch' ]
@@ -687,6 +703,7 @@ def get_suite():
687
703
suite .addTest (unittest .makeSuite (ConflictTests ))
688
704
suite .addTest (unittest .makeSuite (OptimizationTests ))
689
705
suite .addTest (unittest .makeSuite (JsonPointerTests ))
706
+ suite .addTest (unittest .makeSuite (JsonPatchCreationTest ))
690
707
return suite
691
708
692
709
0 commit comments