File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 10
10
import jsonpatch
11
11
import jsonpointer
12
12
import sys
13
+ try :
14
+ from types import MappingProxyType
15
+ except ImportError :
16
+ # Python < 3.3
17
+ MappingProxyType = dict
13
18
14
19
15
20
class ApplyPatchTestCase (unittest .TestCase ):
@@ -938,6 +943,26 @@ def test_json_patch_with_prefix_pointer(self):
938
943
self .assertEqual (res , {'foo' : {'bar' : {'baz' : 'qux' }}})
939
944
940
945
946
+ class CustomOperationTests (unittest .TestCase ):
947
+
948
+ def test_custom_operation (self ):
949
+
950
+ class IdentityOperation (jsonpatch .PatchOperation ):
951
+ def apply (self , obj ):
952
+ return obj
953
+
954
+ class JsonPatch (jsonpatch .JsonPatch ):
955
+ operations = MappingProxyType (
956
+ identity = IdentityOperation ,
957
+ ** jsonpatch .JsonPatch .operations
958
+ )
959
+
960
+ patch = JsonPatch ([{'op' : 'identity' , 'path' : '/' }])
961
+ self .assertIn ('identity' , patch .operations )
962
+ res = patch .apply ({})
963
+ self .assertEqual (res , {})
964
+
965
+
941
966
if __name__ == '__main__' :
942
967
modules = ['jsonpatch' ]
943
968
@@ -956,6 +981,7 @@ def get_suite():
956
981
suite .addTest (unittest .makeSuite (JsonPatchCreationTest ))
957
982
suite .addTest (unittest .makeSuite (UtilityMethodTests ))
958
983
suite .addTest (unittest .makeSuite (CustomJsonPointerTests ))
984
+ suite .addTest (unittest .makeSuite (CustomOperationTests ))
959
985
return suite
960
986
961
987
You can’t perform that action at this time.
0 commit comments