File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010import jsonpatch
1111import jsonpointer
1212import sys
13+ try :
14+ from types import MappingProxyType
15+ except ImportError :
16+ # Python < 3.3
17+ MappingProxyType = dict
1318
1419
1520class ApplyPatchTestCase (unittest .TestCase ):
@@ -938,6 +943,26 @@ def test_json_patch_with_prefix_pointer(self):
938943 self .assertEqual (res , {'foo' : {'bar' : {'baz' : 'qux' }}})
939944
940945
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+
941966if __name__ == '__main__' :
942967 modules = ['jsonpatch' ]
943968
@@ -956,6 +981,7 @@ def get_suite():
956981 suite .addTest (unittest .makeSuite (JsonPatchCreationTest ))
957982 suite .addTest (unittest .makeSuite (UtilityMethodTests ))
958983 suite .addTest (unittest .makeSuite (CustomJsonPointerTests ))
984+ suite .addTest (unittest .makeSuite (CustomOperationTests ))
959985 return suite
960986
961987
You can’t perform that action at this time.
0 commit comments