3
>>> from django.contrib.auth.models import User
4
>>> from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
5
>>> from django.contrib.auth.forms import PasswordChangeForm
7
The user already exists.
9
>>> user = User.objects.create_user("jsmith", "jsmith@example.com", "test123")
11
... 'username': 'jsmith',
12
... 'password1': 'test123',
13
... 'password2': 'test123',
15
>>> form = UserCreationForm(data)
18
>>> form["username"].errors
19
[u'A user with that username already exists.']
21
The username contains invalid data.
24
... 'username': 'jsmith@example.com',
25
... 'password1': 'test123',
26
... 'password2': 'test123',
28
>>> form = UserCreationForm(data)
31
>>> form["username"].errors
32
[u'This value must contain only letters, numbers and underscores.']
34
The verification password is incorrect.
37
... 'username': 'jsmith2',
38
... 'password1': 'test123',
39
... 'password2': 'test',
41
>>> form = UserCreationForm(data)
44
>>> form["password2"].errors
45
[u"The two password fields didn't match."]
50
... 'username': 'jsmith2',
51
... 'password1': 'test123',
52
... 'password2': 'test123',
54
>>> form = UserCreationForm(data)
60
The user submits an invalid username.
63
... 'username': 'jsmith_does_not_exist',
64
... 'password': 'test123',
67
>>> form = AuthenticationForm(None, data)
70
>>> form.non_field_errors()
71
[u'Please enter a correct username and password. Note that both fields are case-sensitive.']
76
... 'username': 'jsmith',
77
... 'password': 'test123',
79
>>> user.is_active = False
81
>>> form = AuthenticationForm(None, data)
84
>>> form.non_field_errors()
85
[u'This account is inactive.']
87
>>> user.is_active = True
92
>>> form = AuthenticationForm(None, data)
95
>>> form.non_field_errors()
98
The old password is incorrect.
101
... 'old_password': 'test',
102
... 'new_password1': 'abc123',
103
... 'new_password2': 'abc123',
105
>>> form = PasswordChangeForm(user, data)
108
>>> form["old_password"].errors
109
[u'Your old password was entered incorrectly. Please enter it again.']
111
The two new passwords do not match.
114
... 'old_password': 'test123',
115
... 'new_password1': 'abc123',
116
... 'new_password2': 'abc',
118
>>> form = PasswordChangeForm(user, data)
121
>>> form["new_password2"].errors
122
[u"The two password fields didn't match."]
127
... 'old_password': 'test123',
128
... 'new_password1': 'abc123',
129
... 'new_password2': 'abc123',
131
>>> form = PasswordChangeForm(user, data)