Getting response 200 instead of 302 in django test

I'm using django-pytest there's a signup/ route in urls which when accessed in browser, a signup form is rendered which expects the fields below

['first_name', 'last_name', 'username', 'email', 'password1', 'password2']

Here's the SignUpView and SignupForm

import uuid

from django import forms
from django.contrib import messages
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.core.mail import send_mail
from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic import FormView


class SignUpForm(UserCreationForm):
    first_name = forms.CharField(
        widget=forms.TextInput(
            attrs={'class': 'form-control', 'placeholder': 'First name'}
        ),
        label='',
    )
    last_name = forms.CharField(
        widget=forms.TextInput(
            attrs={'class': 'form-control', 'placeholder': 'Last name'}
        ),
        label='',
    )
    username = forms.CharField(
        widget=forms.TextInput(
            attrs={'class': 'form-control', 'placeholder': 'Username'}
        ),
        label='',
    )
    email = forms.EmailField(
        widget=forms.EmailInput(
            attrs={'class': 'form-control', 'placeholder': 'Email'}
        ),
        label='',
    )
    password1 = forms.CharField(
        widget=forms.PasswordInput(
            attrs={'class': 'form-control', 'placeholder': 'Password'}
        ),
        label='',
    )
    password2 = forms.CharField(
        widget=forms.PasswordInput(
            attrs={'class': 'form-control', 'placeholder': 'Confirm password'}
        ),
        label='',
    )


class SignUpView(FormView):
    template_name = 'center-form.html'
    form_class = SignUpForm

    def form_valid(self, form):
        if form.is_valid():
            user = User.objects.create_user(
                first_name=form.cleaned_data['first_name'],
                last_name=form.cleaned_data['last_name'],
                username=form.cleaned_data['username'],
                email=form.cleaned_data['email'],
                password=form.cleaned_data['password1'],
                is_active=False,
            )
            activation_code = uuid.uuid4().hex
            Activation.objects.create(code=activation_code, user=user)
            activation_url = self.request.build_absolute_uri(
                reverse('activate', kwargs={'code': activation_code})
            )
            send_mail(
                'Activate translation account',
                f'To activate your account, please follow the link below\n{activation_url}',
                'Translation services',
                [form.cleaned_data['email']],
                fail_silently=False,
            )
            messages.success(
                self.request,
                'Please check your email for a message with the activation code.',
            )
        return redirect('index')

Both work as expected when accessed in browser and a user is eventually created. Here's the test that I'm expecting to pass.

import pytest
from django.urls import reverse


@pytest.mark.django_db
class TestSignup:
    def test_valid(self, client, valid_user_data, django_user_model):
        url = reverse('signup')
        client.get(url)
        response = client.post(url, valid_user_data)
        assert django_user_model.objects.count() and response.status_code == 302

It doesn't. The response's status code is 200 and django_user_model.objects.count() is still 0 after the response.

Here's valid_user_data

{
        'first_name': 'First',
        'last_name': 'Last',
        'username': 'username',
        'email': 'email@domain.com',
        'password1': 'HJGcutcu23TYCUhtxfy5ex',
        'password2': 'HJGcutcu23TYCUhtxfy5ex',
}

<TemplateResponse status_code=200, "text/html; charset=utf-8">
Back to Top