#24773: Add a JSON response to the test client
-----------------------------------+--------------------
     Reporter:  andymckay          |      Owner:  nobody
         Type:  New feature        |     Status:  new
    Component:  Testing framework  |    Version:  1.8
     Severity:  Normal             |   Keywords:
 Triage Stage:  Unreviewed         |  Has patch:  0
Easy pickings:  0                  |      UI/UX:  0
-----------------------------------+--------------------
 I've got a few Django projects that are just JSON APIs and return JSON. If
 you want to test those in the test client, you have to parse the response
 into JSON. Each and every test call. For example:

 {{{
 def test_ok(self):
    assert json.loads(self.client.get(url).content)['modified']
 }}}

 What would be nice is to have json on the test client, which can be parsed
 if the response is application/json. We can mimic the requests interface
 here:

 http://docs.python-
 requests.org/en/latest/api/?highlight=json#requests.Response.json

 So it would look like this:

 {{{
 def test_ok(self):
    assert self.client.get(url).json()['modified']
 }}}

 I wouldn't suggest we do this for every content type, but JSON is
 everywhere. Like glitter.

--
Ticket URL: <https://code.djangoproject.com/ticket/24773>
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/052.d4fd830d6d36e9fb822073e2dcfe32b7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to