title: How to test Django redirect from view class
body: <p>I'm learning Django atm and I am stuck with creating a simple test case.</p>
  
  <p>How I can test the following view? If the user is already logged in it redirects him to list view.</p>
  
  <pre><code>from django.shortcuts import render
  from django.contrib.auth import authenticate, login, logout
  from django.contrib.auth.forms import AuthenticationForm
  from django.views.generic import TemplateView
  from django.core.urlresolvers import reverse
  from django.shortcuts import redirect
  
  class LoginView(TemplateView):
      """
      Base class for client area login.
      """
      def get(self, request, *args, **kwargs):
          """
          Display login form, only if user is not yet authenticated.
          Otherwise redirect to tickets index.
          :param request:
          :param args:
          :param kwargs:
          :return:
          """
          if request.user.is_authenticated():
              return redirect(reverse('tickets:index'))
  
          form = AuthenticationForm()
  
          return render(request, 'login.html', {'form': form})
  </code></pre>
  
  <p>So far the test I have created looks like this:</p>
  
  <pre><code>from django.test import TestCase, RequestFactory
  from django.core.urlresolvers import reverse
  from django.contrib.auth.models import User, AnonymousUser
  from app.account.views import LoginView
  
  
  class TestLoginForm(TestCase):
  
      def setUp(self):
          """
          Set up environment
          :return:
          """
          self.user = User.objects.create_user(username="test", password="test123", email="test@gmail.com")
          self.factory = RequestFactory()
  
      def tearDown(self):
          """
          Clean created user object
          :return:
          """
          self.user.delete()
          self.factory = None
  
      def test_login_form_redirect(self):
          """
          Test login redirect
          :return:
          """
  
  
          request = self.factory.get(reverse('account:login'))
          request.user = AnonymousUser()
  
          view = LoginView()
          response = view.get(request=request)
          self.assertEqual(response.status_code, 200)
  
          request.user = self.user
          response = view.get(request=request)
          self.assertRedirects(response, expected_url=reverse('tickets:index'), status_code=302, target_status_code=200)
  </code></pre>
  
  <p>The first assertation passed, but the second where the user should be redirected if already has logged in throws this error</p>
  
  <pre><code>AttributeError: 'HttpResponseRedirect' object has no attribute 'client'
  </code></pre>
  
  <p>What am I doing wrong?</p>