title: How to test file response in Django?
body: <p>I have an API that generates and returns a CSV file:</p>
  
  <pre><code>def getCSV():
      response = HttpResponse(content_type='text/csv')
      response['Content-Disposition'] = 'attachment; filename=export.csv'
      writer = csv.writer(response, csv.excel)
  
      # ... Write some CSV content ...
  
      return response
  </code></pre>
  
  <p>This works fine when I call it from the browser, but I cannot figure out how to write a test that calls the API and check that the CSV contents are what they should be.</p>
  
  <p>If I:</p>
  
  <pre><code>c = Client()
  r = c.get('/my/export/api')
  print(r.content)
  </code></pre>
  
  <p>That just prints three bytes and is most probably conceptually completely wrong.</p>
  
  <p>How can I get the contents of the CSV file response in my test?</p>