svanoort / pyresttest

Python Rest Testing
Apache License 2.0
1.15k stars 325 forks source link

Jsonschema validator with python3 #173

Closed b4nst closed 8 years ago

b4nst commented 8 years ago

When validated extracted data against a json schema file with this kind of test :

- validators:
    - json_schema: {schema: {file: '../json-schema-folder/schema-file.json'}}

Works fine on python2.7, but with python 3.4 got this stacktrace :

Traceback (most recent call last):
  File "/usr/local/bin/resttest.py", line 4, in <module>
    resttest.command_line_run(sys.argv[1:])
  File "/usr/local/lib/python3.4/dist-packages/pyresttest/resttest.py", line 911, in command_line_run
    main(args)
  File "/usr/local/lib/python3.4/dist-packages/pyresttest/resttest.py", line 853, in main
    failures = run_testsets(tests)
  File "/usr/local/lib/python3.4/dist-packages/pyresttest/resttest.py", line 654, in run_testsets
    result = run_test(test, test_config=myconfig, context=context, curl_handle=curl_handle)
  File "/usr/local/lib/python3.4/dist-packages/pyresttest/resttest.py", line 409, in run_test
    body=body, headers=head, context=my_context)
  File "/usr/local/lib/python3.4/dist-packages/pyresttest/ext/validator_jsonschema.py", line 30, in validate
    jsonschema.validate(json.loads(body), schema)
  File "/usr/lib/python3.4/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'
svanoort commented 8 years ago

Hi @BastienAr - Thank you for reporting the issue - I've fixed the bug, added a testcase to cover it, verified it against the environments, and released it to the public. You have, of course, received credit in the changelog for spotting this. ;)

v1.7.1 includes the fix (also on the master & stable brancesh if you're cloning from source).

Thanks! Sam

b4nst commented 8 years ago

Wow, such reactivity ! I confirm it works fine now, thank you very much.

Bastien.