Skip to content

Commit aa83809

Browse files
committed
Support jsonpointer >= 0.6. Closes peritus#11.
1 parent 60ca9fa commit aa83809

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ mostly a wrapper supposed to have a nice API)!
7474
Changelog
7575
---------
7676

77+
**v0.3.4**
78+
79+
- Add support for python-json-pointer >= 0.6 (if you experienced
80+
"``AttributeError: 'module' object has no attribute 'set_pointer'``", you
81+
should upgrade to this version).
82+
7783
**v0.3.3**
7884

7985
- add HTTPS support

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
zip_safe = False,
2525
classifiers = CLASSIFIERS.splitlines(),
2626
package_dir = {'' : 'src'},
27-
install_requires = ['robotframework', 'webtest', 'jsonpointer'],
27+
install_requires = ['robotframework', 'webtest', 'jsonpatch==0.12', 'jsonpointer==0.7'],
2828
packages = ['HttpLibrary']
2929
)

src/HttpLibrary/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import livetest
88
import json
99
import jsonpointer
10+
import jsonpatch
1011

1112
def load_json(json_string):
1213
try:
@@ -581,9 +582,11 @@ def set_json_value(self, json_string, json_pointer, json_value):
581582
| ${result}= | Set Json Value | {"foo": {"bar": [1,2,3]}} | /foo | 12 |
582583
| Should Be Equal | ${result} | {"foo": 12} | | |
583584
"""
584-
value = load_json(json_value)
585-
p = jsonpointer.set_pointer(json_string, json_pointer, value)
586-
return json_string
585+
return jsonpatch.apply_patch(json_string, [{
586+
'op': 'add',
587+
'path': json_pointer,
588+
'value': load_json(json_value)
589+
}])
587590

588591
@_with_json
589592
def log_json(self, json_string, log_level='INFO'):

tests/json.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Get Json Value OK
2121
Get Json Value Fail
2222
Set Test Variable ${obj} {"foo":{"another prop":{"baz":"A string"}}}
2323
Run Keyword And Expect Error
24-
... JsonPointerException: 'bar' not found in {u'baz': u'A string'}
24+
... JsonPointerException: member 'bar' not found in {u'baz': u'A string'}
2525
... Get Json Value ${obj} /foo/another%20prop/bar
2626

2727
Get Json Value Documentation
@@ -94,7 +94,7 @@ Json Value Should Be Fail
9494
Json Value Should Be Fail Invalid Pointer
9595
Set Test Variable ${doc} {"foo": {"bar": [4,5,6]}}
9696
Run Keyword And Expect Error
97-
... JsonPointerException: 'baz' not found in {u'foo': {u'bar': [4, 5, 6]}}
97+
... JsonPointerException: member 'baz' not found in {u'foo': {u'bar': [4, 5, 6]}}
9898
... Json Value Should Equal ${doc} /baz [7,8,9]
9999

100100
Stringify Documentation Example

0 commit comments

Comments
 (0)