PUT with the test client

574 views
Skip to first unread message

Malcolm Box

unread,
Jan 13, 2010, 9:55:41 AM1/13/10
to django...@googlegroups.com
Hi,

I'm writing some tests using the Django test client for a REST API.  This API uses the PUT method and I'm running into problems with the test client, as it appears to wish to URL encode the data into the query string.

Code is:

r = self.client.put('/json/api/endpoint', json.dumps(params), content_type='application/json')

and the error is "ValueError: need more than 1 value to unpack" from urlencode() in http.py

Since the data is JSON encoded it needs to go a Content-Type: application/json in the body, without any further processing.  If the put method is replaced with the post method all works fine - the client leaves the content alone and just puts it into the body.

The code paths in test.client.Client.put and test.client.Client.post are different and I don't understand why - the docs (and my understanding of HTTP) is that they should behave exactly the same in terms of entity encoding.

Am I missing something, or is this just a bug?

Cheers,

Malcolm

Karen Tracey

unread,
Jan 13, 2010, 10:05:13 AM1/13/10
to django...@googlegroups.com
On Wed, Jan 13, 2010 at 9:55 AM, Malcolm Box <malco...@gmail.com> wrote:
Hi,

I'm writing some tests using the Django test client for a REST API.  This API uses the PUT method and I'm running into problems with the test client, as it appears to wish to URL encode the data into the query string.

Code is:

r = self.client.put('/json/api/endpoint', json.dumps(params), content_type='application/json')

and the error is "ValueError: need more than 1 value to unpack" from urlencode() in http.py


Searching the tracker turns up:

http://code.djangoproject.com/ticket/11371

Does that sounds like the same problem to you?  If so, it has been fixed in the 1.1.X branch and trunk.  (The fix was made subsequent to the 1.1.1 release, so it is not in 1.1.1.)

Karen

Malcolm Box

unread,
Jan 13, 2010, 12:05:20 PM1/13/10
to django...@googlegroups.com
On Wed, Jan 13, 2010 at 3:05 PM, Karen Tracey <kmtr...@gmail.com> wrote:
On Wed, Jan 13, 2010 at 9:55 AM, Malcolm Box <malco...@gmail.com> wrote:
I'm writing some tests using the Django test client for a REST API.  This API uses the PUT method and I'm running into problems with the test client, as it appears to wish to URL encode the data into the query string.

Searching the tracker turns up:

http://code.djangoproject.com/ticket/11371

Does that sounds like the same problem to you?  If so, it has been fixed in the 1.1.X branch and trunk.  (The fix was made subsequent to the 1.1.1 release, so it is not in 1.1.1.)


Yes, that's exactly the problem I'm seeing, and the fix fixes it.  Should have thought to search the tracker first <hangs head>

Thanks!

Malcolm
Reply all
Reply to author
Forward
0 new messages