diff options
| author | Stefan Kögl <stefan@skoegl.net> | 2012-09-17 20:13:01 +0200 |
|---|---|---|
| committer | Stefan Kögl <stefan@skoegl.net> | 2012-09-17 20:13:01 +0200 |
| commit | d27ea8ca4595f6b7298b274aa8637fc17662c0e2 (patch) | |
| tree | 93070ae942d85c4d1bb2b038614f4f9d6a124d28 /jsonpatch.py | |
| parent | 46334177e5e84b9772bb527ccea3128f6ad29dcd (diff) | |
| download | python-json-patch-d27ea8ca4595f6b7298b274aa8637fc17662c0e2.tar.gz | |
update "test" behaviour according to latest spec
Diffstat (limited to 'jsonpatch.py')
| -rw-r--r-- | jsonpatch.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/jsonpatch.py b/jsonpatch.py index d102e7e..4dc73d7 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -31,7 +31,7 @@ # """Apply JSON-Patches according to -http://tools.ietf.org/html/draft-ietf-appsawg-json-patch-03""" +http://tools.ietf.org/html/draft-ietf-appsawg-json-patch-04""" # Will be parsed by setup.py to determine package metadata __author__ = 'Stefan Kögl <stefan@skoegl.net>' @@ -63,6 +63,9 @@ class JsonPatchConflict(JsonPatchException): - etc. """ +class JsonPatchTestFailed(JsonPatchException, AssertionError): + """ A Test operation failed """ + def apply_patch(doc, patch, in_place=False): """Apply list of patches to specified json document. @@ -412,9 +415,17 @@ class TestOperation(PatchOperation): """Test value by specified location.""" def apply(self, obj): - value = self.operation['value'] - subobj, part = self.locate(obj, self.location) - assert subobj[part] == value + try: + subobj, part = self.locate(obj, self.location) + except JsonPatchConflict, c: + raise JsonPatchTestFailed(str(c)) + + val = subobj[part] + + if 'value' in self.operation: + value = self.operation['value'] + if val != value: + raise JsonPatchTestFailed('%s is not equal to tested value %s' % (val, value)) class CopyOperation(PatchOperation): |
