Default all test API requests to JSON format
By default, DRF's APIClient
(provided as self.client
in an APITestCase
) uses the multipart/form-data
content type instead of JSON. While our API does support that format, we mostly use JSON. Multipart payloads are limited in that they do not support lists, and empty strings, dicts or lists are treated as if they were missing, which means we are not getting the results we should be getting in some unit tests.
For example, it is not possible to send "repository_url": ""
to CreateWorker
. If you try it through the API client, it won't work, as the API will state that the field cannot be blank. However, that's exactly what we do in unit tests, which means #1825 (closed) could not be detected.
It is possible to change the test client's default format, so we should do that instead. It looks like this might reveal a few minor bugs in some API endpoints' handling of empty, null or missing values.