diff options
author | Matthew Lemon <y@yulqen.org> | 2024-10-15 21:01:31 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-10-15 21:01:31 +0100 |
commit | eeaddb27560d723ca7d61359744ceb2709fccd2d (patch) | |
tree | 04ddbc49ae7b73d5f5a9e1716d7227aecd3b9f85 /alphabetlearning/users/tests/test_forms.py | |
parent | 7a3044c859043837e6c7c95bb4894d04e9b2cbc2 (diff) |
Renamed from pyblackbird_cc to alphabetlearning - everywhere
Diffstat (limited to 'alphabetlearning/users/tests/test_forms.py')
-rw-r--r-- | alphabetlearning/users/tests/test_forms.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/alphabetlearning/users/tests/test_forms.py b/alphabetlearning/users/tests/test_forms.py new file mode 100644 index 0000000..9ab1f7e --- /dev/null +++ b/alphabetlearning/users/tests/test_forms.py @@ -0,0 +1,35 @@ +"""Module for all Form Tests.""" + +from django.utils.translation import gettext_lazy as _ + +from alphabetlearning.users.forms import UserAdminCreationForm +from alphabetlearning.users.models import User + + +class TestUserAdminCreationForm: + """ + Test class for all tests related to the UserAdminCreationForm + """ + + def test_username_validation_error_msg(self, user: User): + """ + Tests UserAdminCreation Form's unique validator functions correctly by testing: + 1) A new user with an existing username cannot be added. + 2) Only 1 error is raised by the UserCreation Form + 3) The desired error message is raised + """ + + # The user already exists, + # hence cannot be created. + form = UserAdminCreationForm( + { + "email": user.email, + "password1": user.password, + "password2": user.password, + }, + ) + + assert not form.is_valid() + assert len(form.errors) == 1 + assert "email" in form.errors + assert form.errors["email"][0] == _("This email has already been taken.") |