Bug 1453482 - Use d-r-f's APIClient instead of WebTest's TestApp #3439
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To avoid unnecessary dependencies, and use a more conventional django-rest-framework testing approach:
http://www.django-rest-framework.org/api-guide/testing/#apiclient
APIClient has a few API differences:
.json
->.json()
.status_int
->.status_code
data
notparams
http://testserver
nothttp://localhost
headers
property.expect_errors
..post_json()
and.put_json()
methods don't exist.See also the docs for the Django test client (which APIClient wraps):
https://docs.djangoproject.com/en/1.11/topics/testing/tools/#the-test-client
Whilst making these changes, I also cleaned up the session fetching in
test_auth.py
andtest_backends.py
, and added astatus_code
check inconftest.py
'smock_post_json()
- which makes the root cause of test failures clearer.