summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtyom Nikitin <a.nikitin@edadeal.ru>2020-11-23 23:53:48 +0300
committerArtyom Nikitin <a.nikitin@edadeal.ru>2020-11-23 23:53:48 +0300
commit1268e09ffaead08f22184b63b3ad34bb41ab8bab (patch)
treeb2e81170f2289cfd3fe2537ee365bf2d1c1d11aa
parentb8083d703c3aacf52429a06dc5b482a1f9acf54f (diff)
downloadpython-json-patch-1268e09ffaead08f22184b63b3ad34bb41ab8bab.tar.gz
test: custom operations
-rwxr-xr-xtests.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests.py b/tests.py
index b5b7b9a..0788d48 100755
--- a/tests.py
+++ b/tests.py
@@ -10,6 +10,11 @@ import unittest
import jsonpatch
import jsonpointer
import sys
+try:
+ from types import MappingProxyType
+except ImportError:
+ # Python < 3.3
+ MappingProxyType = dict
class ApplyPatchTestCase(unittest.TestCase):
@@ -938,6 +943,26 @@ class CustomJsonPointerTests(unittest.TestCase):
self.assertEqual(res, {'foo': {'bar': {'baz': 'qux'}}})
+class CustomOperationTests(unittest.TestCase):
+
+ def test_custom_operation(self):
+
+ class IdentityOperation(jsonpatch.PatchOperation):
+ def apply(self, obj):
+ return obj
+
+ class JsonPatch(jsonpatch.JsonPatch):
+ operations = MappingProxyType(
+ identity=IdentityOperation,
+ **jsonpatch.JsonPatch.operations
+ )
+
+ patch = JsonPatch([{'op': 'identity', 'path': '/'}])
+ self.assertIn('identity', patch.operations)
+ res = patch.apply({})
+ self.assertEqual(res, {})
+
+
if __name__ == '__main__':
modules = ['jsonpatch']
@@ -956,6 +981,7 @@ if __name__ == '__main__':
suite.addTest(unittest.makeSuite(JsonPatchCreationTest))
suite.addTest(unittest.makeSuite(UtilityMethodTests))
suite.addTest(unittest.makeSuite(CustomJsonPointerTests))
+ suite.addTest(unittest.makeSuite(CustomOperationTests))
return suite