Code

Ticket #17360: patch_17360.diff

File patch_17360.diff, 1.7 KB (added by zsiciarz, 2 years ago)

Patch updated to reflect raw_post_data renamed to body.

Line 
1diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt
2index 181b4ff..40413a3 100644
3--- a/docs/topics/testing.txt
4+++ b/docs/topics/testing.txt
5@@ -846,6 +846,36 @@ arguments at time of construction:
6 
7         The ``extra`` argument acts the same as for :meth:`Client.get`.
8 
9+    .. admonition:: Testing RESTful web services
10+
11+       Since web browsers are only designed to perform **GET** and **POST**
12+       requests, the :attr:`~django.http.HttpRequest.POST` variable won't be accessible if you
13+       performed a request with a http verb that is not **POST**, even if the
14+       request body is url encoded.
15+
16+       To access the submitted data, you need to use the
17+       :attr:`~django.http.HttpRequest.body`, which contains the
18+       raw body of the HTTP request.
19+
20+       If you know the incoming request will be **x-www-form-urlencoded** or
21+       **multipart/form-data** encoded, you can use the following method::
22+
23+            from cStringIO import StringIO
24+            from django.http import QueryDict
25+            from django.http.multipartparser import MultiPartParser
26+
27+
28+            def parse_put_data(request):
29+                content_type = request.META.get('CONTENT_TYPE')
30+                if content_type.startswith('multipart'):
31+                    parser = MultiPartParser(request.META, StringIO(request.body), [], request.encoding)
32+                    post, files = parser.parse()
33+                else:
34+                    post = QueryDict(request.body)
35+                return post
36+
37+
38+
39     .. method:: Client.login(**credentials)
40 
41         If your site uses Django's :doc:`authentication system</topics/auth>`