Opened 7 years ago
Last modified 4 years ago
#29268 new Cleanup/optimization
Support passing None to test Client and RequestFactory request methods for default content_type
Reported by: | Chris Jerdonek | Owned by: | |
---|---|---|---|
Component: | Testing framework | Version: | 2.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently, passing content_type=None
to `test.Client.post()` results in the following error:
TypeError: expected string or bytes-like object
instead of causing the default content_type
value. It would be more user-friendly if passing None
resulted in the default value.
One reason is as follows. Currently, if one wants to create a wrapper function around post()
with the same default behavior, the user either needs to (1) duplicate / hard-code the default value in their wrapper function, or (2) special-case None
with a second invocation of post()
using a different function signature (i.e. one that doesn't pass any content_type
value). You can even see this happening in client.py
with the way that Client.post()
invokes RequestFactory.post()
-- the default needs to be hard-coded twice.
Change History (5)
comment:1 by , 7 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | New feature → Cleanup/optimization |
comment:2 by , 7 years ago
Oh, good observation. I didn't examine the other methods. Yes, I do.
Generally, I've found this type of style / pattern helpful anywhere an API has a default value. Perhaps other areas of Django could use a similar treatment. Might it be a candidate for the style guide?
comment:3 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Summary: | Support passing content_type=None to test.Client.post() to get the default value → Support passing None to test Client and RequestFactory request methods for default content_type |
comment:4 by , 7 years ago
I started working on this here: https://github.com/cjerdonek/django/tree/ticket_29268
comment:5 by , 4 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
Should the same design be used for the other HTTP methods that have
content_type='application/octet-stream'
?