mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-30 05:24:01 +03:00
Refactored test_views to test only the required characteristics of the UserCreationForm.
This commit is contained in:
parent
4a48b1725e
commit
47768d495f
|
@ -1,37 +1,33 @@
|
||||||
|
"""
|
||||||
|
Module for all Form Tests.
|
||||||
|
"""
|
||||||
import pytest
|
import pytest
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from {{ cookiecutter.project_slug }}.users.forms import UserCreationForm
|
from {{ cookiecutter.project_slug }}.users.forms import UserCreationForm
|
||||||
from {{ cookiecutter.project_slug }}.users.tests.factories import UserFactory
|
from {{ cookiecutter.project_slug }}.users.models import User
|
||||||
|
|
||||||
pytestmark = pytest.mark.django_db
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
|
|
||||||
class TestUserCreationForm:
|
class TestUserCreationForm:
|
||||||
def test_clean_username(self):
|
"""
|
||||||
# A user with proto_user params does not exist yet.
|
Test class for all tests related to the UserCreationForm
|
||||||
proto_user = UserFactory.build()
|
"""
|
||||||
|
def test_username_validation_error_msg(self, user: User):
|
||||||
|
"""
|
||||||
|
Tests UserCreation Form's unique validator functions correctly by testing:
|
||||||
|
1) Only 1 error is raised by the UserCreation Form
|
||||||
|
2) The desired error message is raised
|
||||||
|
"""
|
||||||
|
|
||||||
form = UserCreationForm(
|
# The user already exists,
|
||||||
{
|
|
||||||
"username": proto_user.username,
|
|
||||||
"password1": proto_user._password,
|
|
||||||
"password2": proto_user._password,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
assert form.is_valid()
|
|
||||||
|
|
||||||
# Creating a user.
|
|
||||||
form.save()
|
|
||||||
|
|
||||||
# The user with proto_user params already exists,
|
|
||||||
# hence cannot be created.
|
# hence cannot be created.
|
||||||
form = UserCreationForm(
|
form = UserCreationForm(
|
||||||
{
|
{
|
||||||
"username": proto_user.username,
|
"username": user.username,
|
||||||
"password1": proto_user._password,
|
"password1": user.password,
|
||||||
"password2": proto_user._password,
|
"password2": user.password,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user