title: django - how to unit test a post request using request.FILES
body: <p>I have the following logic in my view:</p>
  
  <pre><code>def view_function(request):
      if request.method == 'POST':
          uploadform = UploadFileForm(request.POST, request.FILES)
          if uploadform.is_valid():
              #do stuff
  </code></pre>
  
  <p>Where UploadFileForm equals to:</p>
  
  <pre><code>class UploadFileForm(forms.Form):
      file = forms.FileField()
  </code></pre>
  
  <p>I am trying to write unit tests for this view.  Looking in Django docs, the suggested way is this:</p>
  
  <pre><code>class test_stuffTest(TestCase):
      def setUp(self):
          self.client = django.test.client.Client()
      ...
      def test_stuff(self):
          myfile = open('....\file.csv','r')
          response = self.client.post('/', {'name':'file.csv','attachment':myfile})
          #check response
  </code></pre>
  
  <p>My goal is to get uploadform.is_valid() to evaluate to True, so I can test the code which follows the form validation.  When I run the test above, uploadform.is_valid() evaluates to False.  Is there anything I am missing?  Is the code in my test adding the file to request.FILES, or is it doing something else?  </p>