don't conflate django rest framework with the django project. despite the name, they're two separate projects.
-- I would use DRF's test clients instead of django's.
On Thursday, October 18, 2018 at 8:54:12 AM UTC-4, SKisContent wrote:
On Thursday, October 18, 2018 at 8:54:12 AM UTC-4, SKisContent wrote:
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!
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1491cb85-4717-43f5-a826-66640f9ad49c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment