title: django test RequestFactory does not include request.user
body: <p>Whenever I use the requestFactory during testing like:</p>
  
  <pre><code>from django.contrib.auth.models import User
  from django.test import TestCase
  from django.test.client import RequestFactory
  from django.test.client import Client
  import nose.tools as nt
  
  class TestSomeTestCaseWithUser(TestCase):
  
      def setUp(self):
          # Every test needs access to the request factory.
          self.factory = RequestFactory()
          self.client = Client()
          self.user_foo = User.objects.create_user('foo', 'foo@bar.com', 'bar')
  
      def tearDown(self):
          # Delete those objects that are saved in setup
          self.user_foo.delete()
  
      def test_request_user(self):
          self.client.login( username='foo', password='bar')
          request = self.factory.post('/my/url/', {"somedata": "data"})
          nt.assert_equal(request.user,self.user_foo)
  </code></pre>
  
  <p>on everything I try with request.user:</p>
  
  <pre><code>AttributeError: 'dict' object has no attribute 'user'
  </code></pre>
  
  <p>this won't work, so I Added a workaround:</p>
  
  <pre><code>def test_request_user(self):
      # Create an instance of a GET request.
      self.client.login( username='foo', password='bar')
      request = self.factory.post('/my/url/', {"somedata": "data"})
      # a little workaround, because factory does not add the logged in user
      request.user = self.user_foo
      nt.assert_equal(request.user,self.user_foo)
  </code></pre>
  
  <p>I use request.user a lot in my code... so also in the things I want to (unit)test...</p>
  
  <p>Thanks to this question and answer I found out you need to add the user to the request manually: <a href="https://stackoverflow.com/questions/10094727/why-does-a-context-processor-in-django-1-4-raise-attributeerror-when-trying-to-a">How to access request.user while testing?</a> and I added this as a workaround.</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li>Why is this? </li>
  <li>It feels like a bug in the request factory, is it? (so is it a workaround, or just an undocumented feature)  </li>
  <li>Or am I doing something else wrong? (combination of test client and factory)</li>
  <li>Is there a better way to test with logged on users in a request?</li>
  </ul>
  
  <p>I tried this as well: same issue</p>
  
  <pre><code>    response = self.client.post("/my/url/")
      request = response.request
  </code></pre>
  
  <p>By the way, this answer: <a href="https://stackoverflow.com/questions/9448038/accessing-the-request-user-object-when-testing-django">Accessing the request.user object when testing Django</a> suggests to use</p>
  
  <pre><code>response.context['user'] 
  </code></pre>
  
  <p>in stead of</p>
  
  <pre><code>request.user
  </code></pre>
  
  <p>But in my code this is not the case, and as far as I know request.user is quit normal to use, and to explain my problem, i put the request.user in a test... in my real life, it's not in the tests... it's in the code I want to test.</p>