title: Using Django's test client, make a request using an in-memory file
body: <p>I'm writing a test for a Django view, and I want to POST a file. It's a fairly trivial test, and I don't want to litter my <code>tests/</code> directory with different text files, so I'd like to use an in-memory file and create the content on the fly:</p>
  
  <pre><code>from StringIO import StringIO
  file = StringIO('content')
  client.post("/", data={'file': file})
  </code></pre>
  
  <p>Unfortunately this doesn't work:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/Users/brad/project/tests/files.py", line 57, in test_set_and_save
      'mgmt-current_step': 'Attachments',
    File "/Users/brad/django/test/client.py", line 423, in post
      response = super(Client, self).post(path, data=data, content_type=content_type, **extra)
    File "/Users/brad/django/test/client.py", line 245, in post
      post_data = self._encode_data(data, content_type)
    File "/Users/brad/django/test/client.py", line 211, in _encode_data
      return encode_multipart(BOUNDARY, data)
    File "/Users/brad/django/test/client.py", line 117, in encode_multipart
      lines.extend(encode_file(boundary, key, value))
    File "/Users/brad/django/test/client.py", line 145, in encode_file
      content_type = mimetypes.guess_type(file.name)[0]
  AttributeError: StringIO instance has no attribute 'name'
  </code></pre>