[Django] #24773: Add a JSON response to the test client

24 views
Skip to first unread message

Django

unread,
May 9, 2015, 12:10:34 AM5/9/15
to django-...@googlegroups.com
#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.

Django

unread,
May 9, 2015, 1:23:49 AM5/9/15
to django-...@googlegroups.com
#24773: Add a JSON response to the test client
-----------------------------------+--------------------------------------
Reporter: andymckay | Owner: andymckay
Type: New feature | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by andymckay):

* status: new => assigned
* needs_better_patch: => 0
* needs_tests: => 0
* version: 1.8 => master
* owner: nobody => andymckay
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/24773#comment:1>

Django

unread,
May 11, 2015, 11:37:45 AM5/11/15
to django-...@googlegroups.com
#24773: Add a JSON response to the test client
-----------------------------------+-------------------------------------

Reporter: andymckay | Owner: andymckay
Type: New feature | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+-------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/24773#comment:2>

Django

unread,
May 12, 2015, 12:02:24 PM5/12/15
to django-...@googlegroups.com
#24773: Add a JSON response to the test client
-----------------------------------+-------------------------------------
Reporter: andymckay | Owner: andymckay
Type: New feature | Status: assigned
Component: Testing framework | Version: master
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 timgraham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/24773#comment:3>

Django

unread,
May 25, 2015, 10:43:58 AM5/25/15
to django-...@googlegroups.com
#24773: Add a JSON response to the test client
-----------------------------------+-------------------------------------
Reporter: andymckay | Owner: andymckay
Type: New feature | Status: closed

Component: Testing framework | Version: master
Severity: Normal | Resolution: fixed

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 Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"4525a0c4669dccb3a4c5d865184f8bb8e4a89ec8" 4525a0c4]:
{{{
#!CommitTicketReference repository=""
revision="4525a0c4669dccb3a4c5d865184f8bb8e4a89ec8"
Fixed #24773 -- Added a json() method on test client responses.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24773#comment:4>

Reply all
Reply to author
Forward
0 new messages