On Jan 23, 1:39 am, Julien Phalip <jpha...@gmail.com> wrote:
> I have a view which processes a multi-part form and whose behaviour
> varies depending on the content types of the uploaded files. I've
> written some tests for that view as follows:
>
>         post_data = {
>             'name1': 'blah',
>             'file_field1': image_data,
>         }
>         response = self.client.post('/upload/', post_data)
>
> But the problem is that (apparently by design) all files are
> systematically encoded with the content type 'application/octet-
> stream'.
>

> Is there a more concise or more elegant way to do?
>

The UploadedFile[1] object has a field called content_type. So if you
have this in a form:

myfile = request.FILES['some_file']
if myfile.content_type != 'application/zip':
     #raise error

I don't know if this will help you in your test. I hope it does.

[1] 
http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#uploadedfile-objects

John
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to