From d6d51c9546a8734683c75bddc2cab93e05247f1e Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 17 Feb 2007 00:23:09 +0000 Subject: Fixed #3160 -- Added the ability to control the content type in a test client POST request. This is to allow easier testing of json-rpc/xml-rpc/soap etc interfaces. Thanks to Mikeal Rogers for the suggestion, and Ben for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4529 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/testing.txt | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'docs') diff --git a/docs/testing.txt b/docs/testing.txt index 6b6aecba38..33014723cd 100644 --- a/docs/testing.txt +++ b/docs/testing.txt @@ -217,15 +217,21 @@ can be invoked on the ``Client`` instance. http://yoursite.com/customers/details/?name=fred&age=7 -``post(path, data={})`` - Make a POST request on the provided ``path``. The key-value pairs in the - data dictionary will be used to create the POST data payload. This payload - will be transmitted with the mimetype ``multipart/form-data``. - - However submitting files is a special case. To POST a file, you need only +``post(path, data={}, content_type=MULTIPART_CONTENT)`` + Make a POST request on the provided ``path``. If you provide a content type + (e.g., ``text/xml`` for an XML payload), the contents of ``data`` will be + sent as-is in the POST request, using the content type in the HTTP + ``Content-Type`` header. + + If you do not provide a value for ``content_type``, the values in + ``data`` will be transmitted with a content type of ``multipart/form-data``. + The key-value pairs in the data dictionary will be encoded as a multipart + message and used to create the POST data payload. + + Submitting files is a special case. To POST a file, you need only provide the file field name as a key, and a file handle to the file you wish to upload as a value. The Test Client will populate the two POST fields (i.e., - ``field`` and ``field_file``) required by FileField. For example:: + ``field`` and ``field_file``) required by Django's FileField. For example:: c = Client() f = open('wishlist.doc') -- cgit v1.3