The content_type refers to the http header being set by this parameter. Providing a shortcut for one single value - when that value is easily specified by the proper parameter - seems like too much a niche benefit.
If it’s a real issue, you could always subclass the test.Client class to make that setting the default for your test cases, then you don’t need to supply that parameter at all.
Although I imagine it might not be the API described in this proposal but something a bit more flexible, which of course might not be any change at all.
I (too) would be -1 for this change: it expands the API surface area for no real gain.
The suggested workarounds seem more than sufficient if this is desired. I don’t think that should be part of core, but rather something folks add in their own projects.
Would there be interest in passing the data directly to a json kwarg? This will put Django in line with django-ninja and FastAPI.
response = client.post(json={"foo": "bar"})
In the meantime, here’s my current workaround for anyone interested:
from django.test import Client as _Client
def take_json(method):
"""Wrap `Client` methods to accept a `json` kwarg."""
def inner(self, *args, json=None, **kwargs):
if json is not None:
kwargs["content_type"] = "application/json"
kwargs["data"] = json
return method(self, *args, **kwargs)
return inner
class Client(_Client):
patch = take_json(_Client.patch)
post = take_json(_Client.post)
put = take_json(_Client.put)