This project aims to be a library for facilitating REST API testing.
I've been trying to find a library for testing APIs in python, which in my point of view requires to compare expected jsons with given jsons, as libraries like PHP Matcher or JSONassert do. My impossibility to find a library with these features, encourage me to do my own.
from pyjsonassert import assert_json
expected = {"animal": "dog"}
current = {"animal": "cat"}
# Will fail
assert_json(expected, current)
You can also use some flags for strict comparison:
from pyjsonassert import assert_json
expected = {"animal": "dog", "place": "home"}
current = {"animal": "dog", "object": "table"}
# Will assert
assert_json(expected, current, allow_unexpected_fields=True, allow_missing_fields=False)
In several scenarios it is not known all the specific values in an response json, but still is required to test that an specific field with a value is returned.
For that cases, the patterns are introduced:
-
@string@
expected = {"animal": "@string@"} current = {"animal": "dog"} # Will assert assert_json(expected, current)
-
@uuid
python -m unittest discover tests
This packages has configured an CI delivery flow using travis. For publishing new releases correctly in travis, it will be necessary to tag the release appropriately.
NOTICE: Remember to update the version manually in the pyjsonassert/__init__.py
file.
Steps:
- Change version in
pyjsonassert/__init__.py
manually. git push origin master
git tag <version>
.<version>
should correspond to the indicated in step 1.git push --tags
. Travis will only publish new package version in Pypi when processing a pushed tag.
Build the distributions:
python setup.py sdist bdist_wheel
Upload to pypi:
twine upload dist/*
Upload to test.pypi:
twine upload -r test dist/*
- Add custom message parameter in the assertion
- Add more patterns for being able to match types, besides the exact value (like PHP Matcher patterns)