#34074 closed New feature (fixed)
'headers' argument for test RequestFactory/Client
| Reported by: | Adam Johnson | Owned by: | David Wobrock |
|---|---|---|---|
| Component: | Testing framework | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | David Wobrock | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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 django-upgrade issue to rewrite request factory and client invocations.)
Change History (10)
comment:1 by , 3 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 3 years ago
| Cc: | added |
|---|---|
| Has patch: | set |
| Owner: | changed from to |
| Status: | new → assigned |
I agree that it would come in handy!
Here's a draft PR.
comment:3 by , 3 years ago
| Patch needs improvement: | set |
|---|
comment:4 by , 3 years ago
| Needs documentation: | set |
|---|---|
| Patch needs improvement: | unset |
comment:5 by , 3 years ago
| Needs documentation: | unset |
|---|
comment:6 by , 3 years ago
| Patch needs improvement: | set |
|---|
comment:7 by , 3 years ago
| Patch needs improvement: | unset |
|---|
comment:8 by , 3 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Note:
See TracTickets
for help on using tickets.
Sounds good.