Zenpy uses Betamax recordings to speed up daily tests. Therefore, there are two testing modes - using records and with a live Zendesk account.
Now you can use two unittest libraries - nose or pytest:
# pip install -r requirements.dev
Nose is obsolete and doesn't work with Python 3.9+.
Pytest supports Python 2.7 until version 4.6.
You don't need any other things for using recordings.
# cd /dir/zenpy
# make unittest
or
# make pytest
Partial testing:
# nosetests -v --stop --exe tests/test_api/test_create_update_delete_zendesk.py
# nosetests -v --stop --exe tests/test_api/test_create_update_delete_zendesk.py:TestUserCreateUpdateDelete
# nosetests -v --stop --exe tests/test_api/test_create_update_delete_zendesk.py:TestUserCreateUpdateDelete.test_multiple_update_full_objects
or
# pytest tests/test_api/test_create_update_delete_zendesk.py::TestUserCreateUpdateDelete.test_multiple_update_full_objects
To test on a live account you need to carry out the steps below:
- Put zenpy-test-credentials.json to a home directory (~).
- Delete all files in ./tests/test_api/betamax/. (
scripts/clean_betamax.sh
) - Then start testing as usual.
- If a test fails, delete its files in betamax before restarting.
zenpy-test-credentials.json:
{
"subdomain": "subdomain",
"email": "email",
"token": "token"
}
To pass all the tests successfully, please provide some things:
- In ./zenpy/cache.py:ZenpyCacheManager.init temporary change ttl for ticket cache to 300. Some tests take too much time and fail on expired cache elements.
- In ./zenpy/tests/test_api/test_incremental_object_update.py:TestIncrementalObjectUpdate.setUp provide an existing ticket id.
- In ./zenpy/tests/test_api/test_webhooks_api.py:TestWebhooks.test_invocations and .test_invocation_attempts put a real webhook id with a non-empty list of invocations.
- in ./zenpy/tests/test_api/test_calls_pe.py put a real TEST_APP_ID for TalkPE Calls API. (You can just call "https://{{subdomain}}.zendesk.com/api/v2/apps/installations" and choose an ID you like the most).
- In the scripts folder, you can remove all betamax outputs with
clean_betamax.sh
- Look for all TESTING_CHANGE in the source and REVERT ones that say it's NOT OK TO COMMIT.
Notes:
- Testing webhooks on a live account may take a lot of time and could result with an error because of rate limits. Consider to test it separately.