Coverage for cheese/users/tests/test_forms.py: 100.00%
15 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-16 16:36 -0700
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-16 16:36 -0700
1import pytest
3from cheese.users.forms import UserCreationForm
4from cheese.users.tests.factories import UserFactory
6pytestmark = pytest.mark.django_db
9class TestUserCreationForm:
10 def test_clean_username(self):
11 # A user with proto_user params does not exist yet.
12 proto_user = UserFactory.build() 1a
14 form = UserCreationForm( 1a
15 # fmt: off
16 {
17 "username": proto_user.username,
18 "password1": proto_user._password,
19 "password2": proto_user._password,
20 }
21 # fmt: on
22 )
24 assert form.is_valid() 1a
25 assert form.clean_username() == proto_user.username 1a
27 # Creating a user.
28 form.save() 1a
30 # The user with proto_user params already exists,
31 # hence cannot be created.
32 form = UserCreationForm( 1a
33 # fmt: off
34 {
35 "username": proto_user.username,
36 "password1": proto_user._password,
37 "password2": proto_user._password,
38 }
39 # fmt: on
40 )
42 assert not form.is_valid() 1a
43 assert len(form.errors) == 1 1a
44 assert "username" in form.errors 1a