summaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests.py')
-rwxr-xr-xtests.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests.py b/tests.py
index b5b7b9a..28fde9b 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,28 @@ 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(
+ dict(
+ 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 +983,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