#34074: 'headers' argument for test RequestFactory/Client
---------------------------------------------+------------------------
Reporter: Adam Johnson | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
We have `request.headers` since Django 2.2, but `RequestFactory`, and thus
`Client`, still require using the awkward meta syntax for setting headers:
{{{
self.client.get("/", HTTP_ACCEPT_LANGUAGE="en")
}}}
I propose we add support for a `headers` argument that takes a dictionary
like `request.headers`:
{{{
self.client.get("/", headers={"accept-language": "en"})
}}}
This would make tests easier to read and write, since they’d be consistent
with `HttpRequest`.
(If this is accepted and merged, open a [https://github.com/adamchainz
/django-upgrade/ django-upgrade] issue to rewrite request factory and
client invocations.)
--
Ticket URL: <https://code.djangoproject.com/ticket/34074>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070183b17ed419-4924fa1b-5a35-4954-b6d5-938c8772cc98-000000%40eu-central-1.amazonses.com.