#29082: Make the test client automatically encode JSON data
--------------------------------------+------------------------------------
Reporter: Nick Sarbicki | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Testing framework | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Carlton Gibson):
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
Comment:
Even if using a custom encoder, it's not something I want to pass every
time, either calling the request method, or encoding the data explicitly.
Can we make it an attribute on `RequestFactory` (and so `Client`)?
`_encode_json` will use this directly, rather than take a parameter: `...
json.dumps(data, cls=self.json_encoder_class)`
When testing I set my custom encoder at the point of use (or subclass if I
prefer):
{{{
factory = test.RequestFactory()
factory.json_encoder_class = MyCustomEncoder
req = factory.post('/', content_type='application/json', ...)
}}}
If we do this then we just need a test that the user **can** set a custom
encoder.
--
Ticket URL: <https://code.djangoproject.com/ticket/29082#comment:16>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.2eca4ec6902ce90403db5e8408f03159%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.