On Jan 24, 12:57 pm, Malcolm Tredinnick <malc...@pointy-stick.com> wrote: > On Fri, 2009-01-23 at 12:15 -0800, Julien Phalip wrote: > > On Jan 24, 2:45 am, varikin <vari...@gmail.com> wrote: > > > 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/#upload... > > > > John > > > Hi John, > > > Thanks for your reply. The snippet you've given is the kind of things > > my view already does. The problem is that, when testing with > > self.client.post(), all files are systematically encoded as > > 'application/octet-stream'. To test the behaviour of my view I need to > > control the content type of each uploaded files. And it doesn't seem > > like there's another way than creating a custom request from scratch > > to achieve that. Is that correct? > > That sounds quite believable. After all, you are simulating what a > browser (or other HTTP client) has to do, which includes setting the > content type. You'll probably want to write a utility function for > creating your requests to make your code shorter, but it seems > reasonable that this is something you have construct. Asking Django's > test framework to do MIME-type detection by default would take time and > remove an element of predictability (and even correctness) from the > tests. > > If you come up with a neat, unobtrusive helper function, you might want > to consider creating a patch for Django's test module.
Just for the record, I created a ticket with patch here: http://code.djangoproject.com/ticket/10115 Regards, Julien --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---