title: how to unit test file upload in django
body: <p>In my django app, I have a view which accomplishes file upload.The  core snippet is like this</p>
  
  <pre><code>...
  if  (request.method == 'POST'):
      if request.FILES.has_key('file'):
          file = request.FILES['file']
          with open(settings.destfolder+'/%s' % file.name, 'wb+') as dest:
              for chunk in file.chunks():
                  dest.write(chunk)
  </code></pre>
  
  <p>I would like to unit test the view.I am planning to test the happy path as well as the fail path..ie,the case where the <code>request.FILES</code> has no key 'file'  , case where <code>request.FILES['file']</code> has <code>None</code>..</p>
  
  <p>How do I set up the post data for the happy path?Can somebody tell me?</p>