Hi.
The Django Rest Framework encourages the use of put for uploading files. However, django.test.client.Client does not encode multipart data before simulating the server call. Does anyone know why this has been left out?
The code in django.test.client for put() is:
def put(self, path, data='', content_type='application/octet-stream', secure=False, **extra):
"""Construct a PUT request."""
data = self._encode_json(data, content_type)
return self.generic('PUT', path, data, content_type, secure=secure, **extra)
The code in for post() is:
def post(self, path, data=None, content_type=MULTIPART_CONTENT, secure=False, **extra):
"""Construct a POST request."""
data = self._encode_json({} if data is None else data, content_type)
post_data = self._encode_data(data, content_type)
return self.generic('POST', path, post_data, content_type, secure=secure, **extra)
As you can see the put method doesn't call _encode_data. So if the data happens to include a file and I'm trying to test a file upload, it doesn't work.
The last issue that I found related to this question appeared in the Django issues archive in 2009-10.
Thanks!