#35247: Test Client constructor accepts headers that are ignored/overwitten
-----------------------------------------+------------------------
Reporter: Paul Garner | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 5.0
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 |
-----------------------------------------+------------------------
At first glance it seems like you could supply 'default' headers that are
applied to every request when instantiating a test Client...
{{{
class Client(ClientMixin, RequestFactory):
def __init__(
self,
enforce_csrf_checks=False,
raise_request_exception=True,
*,
headers=None,
query_params=None,
**defaults,
):
super().__init__(headers=headers, query_params=query_params,
**defaults)
self.handler = ClientHandler(enforce_csrf_checks)
self.raise_request_exception = raise_request_exception
self.exc_info = None
self.extra = None
self.headers = None
}}}
https://github.com/django/django/blob/main/django/test/client.py#L1059
However passing `headers` arg is completely useless, because the request
methods do this:
{{{
def get(
self,
path,
data=None,
follow=False,
secure=False,
*,
headers=None,
query_params=None,
**extra,
):
"""Request a response from the server using GET."""
self.extra = extra
self.headers = headers
response = super().get(
path,
data=data,
secure=secure,
headers=headers,
query_params=query_params,
**extra,
)
}}}
https://github.com/django/django/blob/main/django/test/client.py#L1121
This seems like a bad design? Shouldn't the `get` etc methods merge their
arg `headers` with `self.headers` without overwriting it? (and same for
`extra`)
I'm happy to submit a PR for this, assuming things aren't the way they are
for some necessary reason that I've missed.
--
Ticket URL: <https://code.djangoproject.com/ticket/35247>
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/0107018dd71a7172-a4bef140-5dcc-42ec-8f99-a418f93b5882-000000%40eu-central-1.amazonses.com.