title: How do I get the user in Django test?
body: <p>I have some external services. My Django app is built on top of my external service APIs. In order to talk to my external service, I have to pass in an auth cookies, which I can get by reading <code>User</code> (that cookie != django cookies).</p>
  
  <p>Using test tools like <code>webtests</code>, <code>requests</code>, I have trouble writing my tests.</p>
  
  <pre><code>class MyTestCase(WebTest):
      def test_my_view(self):
          #client = Client()
          #response = client.get(reverse('create')).form
          form = self.app.get(reverse('create'), user='dummy').form
          print form.fields.values()
          form['name'] = 'omghell0'
          print form
  
          response = form.submit()
  </code></pre>
  
  <p>I need to submit a form, which creates, say, a user on my external service. But to do that, I normally would pass in <code>request.user</code> (in order to authenticate my privilege to external service). But I don't have <code>request.user</code>. </p>
  
  <p>What options do I have for this kind of stuff?</p>
  
  <p>Thanks...</p>
  
  <hr>
  
  <p>Suppose this is my tests.py</p>
  
  <pre><code>import unittest
  from django.test.client import Client
  from django.core.urlresolvers import reverse
  from django_webtest import WebTest
  from django.contrib.auth.models import User
  
  
  class SimpleTest(unittest.TestCase):
      def setUp(self):
          self.usr = User.objects.get(username='dummy')
          print self.usr
      .......
  </code></pre>
  
  <p>I get </p>
  
  <pre><code>Traceback (most recent call last):
    File "/var/lib/graphyte-webclient/webclient/apps/codebundles/tests.py", line 10, in setUp
      self.usr = User.objects.get(username='dummy')
    File "/var/lib/graphyte-webclient/graphyte-webenv/lib/python2.6/site-packages/django/db/models/manager.py", line 132, in get
      return self.get_query_set().get(*args, **kwargs)
    File "/var/lib/graphyte-webclient/graphyte-webenv/lib/python2.6/site-packages/django/db/models/query.py", line 341, in get
      % self.model._meta.object_name)
  DoesNotExist: User matching query does not exist
  </code></pre>
  
  <p>But if I test the <code>User.objects</code> in views, I am okay.</p>