<gh_stars>0
from django.contrib.auth import get_user_model
from django.test import Client, TestCase
from django.urls import reverse

User = get_user_model()


class FormTest(TestCase):
    def setUp(self):
        self.guest_client = Client()

    def test_create_user(self):
        users_count = User.objects.count()
        username = 'user'
        password = '<PASSWORD>'
        form_data = {
            'first_name': 'Иван',
            'last_name': 'Иванов',
            'username': username,
            'email': '<EMAIL>',
            'password1': password,
            'password2': password
        }

        response = self.guest_client.post(
            reverse('users:signup'),
            data=form_data,
        )

        self.assertRedirects(response, reverse('posts:index'))
        self.assertEqual(users_count + 1, User.objects.count())
        self.assertTrue(
            User.objects.filter(
                username=username,
            ).exists()
        )

from django.contrib.auth import get_user_model
from django.test import Client, TestCase
from django.urls import reverse

User = get_user_model()


class FormTest(TestCase):
    def setUp(self):
        self.guest_client = Client()

    def test_create_user(self):
        users_count = User.objects.count()
        username = 'user'
        password = '<PASSWORD>'
        form_data = {
            'first_name': 'Иван',
            'last_name': 'Иванов',
            'username': username,
            'email': '<EMAIL>',
            'password1': password,
            'password2': password
        }

        response = self.guest_client.post(
            reverse('users:signup'),
            data=form_data,
        )

        self.assertRedirects(response, reverse('posts:index'))
        self.assertEqual(users_count + 1, User.objects.count())
        self.assertTrue(
            User.objects.filter(
                username=username,
            ).exists()
        )