diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-01-19 15:57:06 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-01-19 15:57:06 +0000 |
commit | 9d76a3c52b8310726ec09e0262813f0438c21df6 (patch) | |
tree | 4acf47dce6c3aa75f8ad7c5cb56fe6486c2d64a7 /ctrack/users/tests/test_forms.py |
init commit - from cookiecutter
Diffstat (limited to '')
-rw-r--r-- | ctrack/users/tests/test_forms.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/ctrack/users/tests/test_forms.py b/ctrack/users/tests/test_forms.py new file mode 100644 index 0000000..11ef251 --- /dev/null +++ b/ctrack/users/tests/test_forms.py @@ -0,0 +1,40 @@ +import pytest + +from ctrack.users.forms import UserCreationForm +from ctrack.users.tests.factories import UserFactory + +pytestmark = pytest.mark.django_db + + +class TestUserCreationForm: + def test_clean_username(self): + # A user with proto_user params does not exist yet. + proto_user = UserFactory.build() + + form = UserCreationForm( + { + "username": proto_user.username, + "password1": proto_user._password, + "password2": proto_user._password, + } + ) + + assert form.is_valid() + assert form.clean_username() == proto_user.username + + # Creating a user. + form.save() + + # The user with proto_user params already exists, + # hence cannot be created. + form = UserCreationForm( + { + "username": proto_user.username, + "password1": proto_user._password, + "password2": proto_user._password, + } + ) + + assert not form.is_valid() + assert len(form.errors) == 1 + assert "username" in form.errors |