title: Django: set cookie on test client?
body: <p>My Django site is set up with some middleware that on each request, checks for a cookie, and if it is not set, forwards the user elsewhere.</p>
  
  <p>I now want to run some tests on the site. This is my code:</p>
  
  <pre><code>def test_contactform(self):
      response = self.client.get('/contact/')
      self.assertEqual(response.status_code, 200)
      print response
      self.assertTrue('Contact me' in response.content)
  </code></pre>
  
  <p>Unfortunately, this fails with:</p>
  
  <pre><code>Vary: Cookie
  Content-Type: text/html; charset=utf-8
  Location: http://testserver/ldap/?next=/contact/
  Traceback (most recent call last):
    File "tests.py", line 43, in test_contactform
      self.assertEqual(response.status_code, 200)
  AssertionError: 302 != 200
  </code></pre>
  
  <p>Can I either (i) set a cookie on the Django test client (and if so how) or (ii) require the Django test client to follow the redirect and test against the final page?</p>