title: What is the correct way to simulate filedata for testing a form?
body: <p>I'm trying to test a self written FormField AudioFileFormField, which checks if a file is an audiofile before storing it. For that i have overwritten the to_python method. Trying to test this FormField i ran into some difficulties.</p>
  
  <p>This is my TestCase so far:</p>
  
  <pre><code>from django import forms
  from django.core.files.uploadedfile import SimpleUploadedFile
  from django.test import TestCase
  
  class TestAudioFileFormField(TestCase):
      """ test the formfield to use for AudioFile Uploads """
  
      class TestForm(forms.Form):
          audiofilefield = AudioFileFormField()
  
  
      def setUp(self):
  
          self.AUDIOFILE_TEST_ROOT = os.path.dirname(__file__) + '/data/'
          self.files = audiofile_files
  
  
      def test_to_python(self):
          """ assign some files to a form and validate the form """
  
          f = file(self.AUDIOFILE_TEST_ROOT + self.files[0]) 
          file_data = {'audiofilefield':SimpleUploadedFile( self.files[0],f.read() )}
          data = {}
  
          form = self.TestForm(data,f)
          form.is_valid()
  </code></pre>
  
  <p>The line form.is_valid() raises an AttributeError: 'file' object has no attribute 'get'</p>
  
  <p>When i insert a debug trace right before form.is_valid(), this is what i get in that interactive session:</p>
  
  <pre><code>ipdb&gt; form.is_valid()
  AttributeError: 'file' object has no attribute 'get'
  ipdb&gt; suf = file_data['audiofilefield']
  ipdb&gt; suf
  &lt;SimpleUploadedFile: invalid_format.mp3 (text/plain)&gt;
  ipdb&gt; dir(suf)
  [lots of info here]
  ipdb&gt; form.is_valid()
  True
  </code></pre>
  
  <p>What exactly did i change in the interactive session, so that the form validation is working? What would be the correct way to pass the file to SimpleUploadedFile to avoid the AttributeError?</p>