title: Login, Register and Logout test failed AssertionError: 200 != 302 django
body: <p>I am trying to create a test for my login, logout and register views but I keep on getting this error <strong>AssertionError: 200 != 302</strong>. Here are the codes:</p>
  <p><strong>MODEL</strong>
  Here is the User model</p>
  <pre><code>from django.db import models
  from django.contrib.auth.models import AbstractUser
  
  class User(AbstractUser):
      full_name = models.CharField(max_length=300, null=True, blank=True)
      username = models.CharField(max_length=150)
      email = models.EmailField(unique=True)
      avatar = models.ImageField(upload_to='user-profile-images/', null=True)
  
      USERNAME_FIELD = 'email'
      
      REQUIRED_FIELDS = ['username']
  </code></pre>
  <p><strong>VIEWS</strong>
  Here is the login and register function view</p>
  <pre><code>def loginPage(request):
      context = {}
      if request.user.is_authenticated:
          return redirect('home')
  
      if request.method == 'POST':
          email = request.POST.get('email')
          password = request.POST.get('password')
  
          try:
              user = User.objects.get(email=email)
          except:
              messages.error(request, 'User does not exist')
  
          user = authenticate(request, email=email, password=password)
  
          if user is not None:
              login(request, user)
              return redirect('home')
               
      return render(request,'registration/login.html', context)
  
  def registerPage(request):
      form = SignupForm
      if request.method == 'POST':
          form = SignupForm(request.POST)
          if form.is_valid():
              user = form.save(commit=False)
              user.username = user.username.lower()
              user.save()
              login(request, user)
              return redirect ('home')
          else:
              messages.error(request, 'An error occured during registration')
  
      return render(request, 'registration/register.html', {'form':form})
  
  def logoutPage(request):
      logout(request)
      return redirect('home')
  
  </code></pre>
  <p><strong>URLS</strong></p>
  <pre><code>from django.urls import path
  from . import views
  
  urlpatterns = [
      path('login/', views.loginPage, name='login'),
      path('logout/', views.logoutPage, name='logout'),
      path('register/', views.registerPage, name='register'),
  
  ]
  </code></pre>
  <p><strong>TEST</strong></p>
  <pre><code>from django.test import TestCase, Client
  from django.urls import reverse
  from mydp_app.models import User
  
  class TestViews(TestCase):
  
      def setUp(self):
          self.client = Client()
          self.login_url = reverse('login')
          self.logout_url = reverse('logout')
          self.register_url = reverse('register')
  
     def test_register_post(self):
          response = self.client.post(reverse('register'), {
              'full_name': 'Test User',
              'username': 'testuser',
              'email': 'testuser@gmail.com',
              'password': 'testpassword',
              'password2': 'testpassword',
          })
          self.assertEquals(response.status_code, 302)
  
      def test_login_post(self):
          response = self.client.post(reverse('login'), {
              'email': 'testuser@gmail.com',
              'password': 'testpassword',
          })
          self.assertEquals(response.status_code, 302)
  
      def test_logout(self):
          self.client.login(email='testuser@gmail.com', password='testpassword')
          response = self.client.post(reverse('logout'), follow=True)
          self.assertEquals(response.status_code, 302)
  </code></pre>
  <p>The test expects the status code to be <strong>200</strong> but it is to be redirected. I keep getting this error <code>self.assertEquals(response.status_code, 302) AssertionError: 200 != 302</code></p>