Closed
Bug 1453482
Opened 6 years ago
Closed 6 years ago
Use django.test.client or d-r-f APIClient instead of WebTest's TestApp
Categories
(Tree Management :: Treeherder, enhancement, P2)
Tree Management
Treeherder
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: emorley, Assigned: emorley)
Details
Attachments
(1 file)
Django has a built-in client for testing against the WSGI app, and d-r-f has a wrapper around that (called APIClient) which adds a few extra features. We should just use them instead of adding webtest+multiple other dependencies to our test suite.
Comment 1•6 years ago
|
||
Assignee | ||
Updated•6 years ago
|
Attachment #8967174 -
Flags: review?(cdawson)
Comment 2•6 years ago
|
||
Comment on attachment 8967174 [details] [review] Link to GitHub pull-request: https://github.com/mozilla/treeherder/pull/3439 Fantastic!
Attachment #8967174 -
Flags: review?(cdawson) → review+
Comment 3•6 years ago
|
||
Commit pushed to master at https://github.com/mozilla/treeherder https://github.com/mozilla/treeherder/commit/a5023192e9c852d563f2bb803f526bb6d9aab8e9 Bug 1453482 - Use d-r-f's APIClient instead of WebTest's TestApp (#3439) 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` * Get parameters are passed as keyword argument `data` not `params` * The default hostname is `http://testserver` not `http://localhost` * Additional HTTP headers are passed directly as keyword arguments, rather than nested under a `headers` property. * It doesn't check the status code itself, so explicit checks are required, along with removing `expect_errors`. * The `.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` and `test_backends.py`, and added a `status_code` check in `conftest.py`'s `mock_post_json()` - which makes the root cause of test failures clearer.
Assignee | ||
Updated•6 years ago
|
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Updated•2 years ago
|
Component: Treeherder: Docs & Development → TreeHerder
You need to log in
before you can comment on or make changes to this bug.
Description
•