title: Test that user was logged in successfully
body: <p>How can I test that a user is logged in after submitting the registration form?</p>
  
  <p>I tried the following but it returns <code>True</code> even before I added the login logic to my registration view.</p>
  
  <pre><code>def test_that_user_gets_logged_in(self):
      response = self.client.post(reverse('auth-registration'), 
                                  { 'username':'foo', 
                                    'password1':'bar', 
                                    'password2':'bar' } )
  
      user = User.objects.get(username='foo')
      assert user.is_authenticated()
  </code></pre>
  
  <p>The code that's being tested:</p>
  
  <pre><code>class RegistrationView(CreateView):
      template_name = 'auth/registration.html'
      form_class = UserCreationForm
      success_url = '/'
  
      def auth_login(self, request, username, password):
          '''
          Authenticate always needs to be called before login because it
          adds which backend did the authentication which is required by login.
          '''
  
          user = authenticate(username=username, password=password)
          login(request, user)
  
      def form_valid(self, form):
          '''
          Overwrite form_valid to login.
          '''
  
          #save the user
          response = super(RegistrationView, self).form_valid(form)
  
          #Get the user creditials
          username = form.cleaned_data['username']
          password = form.cleaned_data['password1']
  
          #authenticate and login
          self.auth_login(self.request, username, password)
  
          return response
  </code></pre>