Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7833: the user creation form now works when password1 isn't set.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8542 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 15ed0d65b0d036629dade79114093845daaa6f52 1 parent e3df354
Jacob Kaplan-Moss authored August 25, 2008
2  django/contrib/auth/forms.py
@@ -30,7 +30,7 @@ def clean_username(self):
30 30
         raise forms.ValidationError(_("A user with that username already exists."))
31 31
 
32 32
     def clean_password2(self):
33  
-        password1 = self.cleaned_data["password1"]
  33
+        password1 = self.cleaned_data.get("password1", "")
34 34
         password2 = self.cleaned_data["password2"]
35 35
         if password1 != password2:
36 36
             raise forms.ValidationError(_("The two password fields didn't match."))
46  django/contrib/auth/tests/forms.py
@@ -4,7 +4,7 @@
4 4
 >>> from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
5 5
 >>> from django.contrib.auth.forms import PasswordChangeForm, SetPasswordForm
6 6
 
7  
-The user already exists.
  7
+# The user already exists.
8 8
 
9 9
 >>> user = User.objects.create_user("jsmith", "jsmith@example.com", "test123")
10 10
 >>> data = {
@@ -18,7 +18,7 @@
18 18
 >>> form["username"].errors
19 19
 [u'A user with that username already exists.']
20 20
 
21  
-The username contains invalid data.
  21
+# The username contains invalid data.
22 22
 
23 23
 >>> data = {
24 24
 ...     'username': 'jsmith@example.com',
@@ -31,7 +31,7 @@
31 31
 >>> form["username"].errors
32 32
 [u'This value must contain only letters, numbers and underscores.']
33 33
 
34  
-The verification password is incorrect.
  34
+# The verification password is incorrect.
35 35
 
36 36
 >>> data = {
37 37
 ...     'username': 'jsmith2',
@@ -44,7 +44,25 @@
44 44
 >>> form["password2"].errors
45 45
 [u"The two password fields didn't match."]
46 46
 
47  
-The success case.
  47
+# One (or both) passwords weren't given
  48
+
  49
+>>> data = {'username': 'jsmith2'}
  50
+>>> form = UserCreationForm(data)
  51
+>>> form.is_valid()
  52
+False
  53
+>>> form['password1'].errors
  54
+[u'This field is required.']
  55
+>>> form['password2'].errors
  56
+[u'This field is required.']
  57
+
  58
+>>> data['password2'] = 'test123'
  59
+>>> form = UserCreationForm(data)
  60
+>>> form.is_valid()
  61
+False
  62
+>>> form['password1'].errors
  63
+[u'This field is required.']
  64
+
  65
+# The success case.
48 66
 
49 67
 >>> data = {
50 68
 ...     'username': 'jsmith2',
@@ -57,7 +75,7 @@
57 75
 >>> form.save()
58 76
 <User: jsmith2>
59 77
 
60  
-The user submits an invalid username.
  78
+# The user submits an invalid username.
61 79
 
62 80
 >>> data = {
63 81
 ...     'username': 'jsmith_does_not_exist',
@@ -70,7 +88,7 @@
70 88
 >>> form.non_field_errors()
71 89
 [u'Please enter a correct username and password. Note that both fields are case-sensitive.']
72 90
 
73  
-The user is inactive.
  91
+# The user is inactive.
74 92
 
75 93
 >>> data = {
76 94
 ...     'username': 'jsmith',
@@ -87,7 +105,7 @@
87 105
 >>> user.is_active = True
88 106
 >>> user.save()
89 107
 
90  
-The success case
  108
+# The success case
91 109
 
92 110
 >>> form = AuthenticationForm(None, data)
93 111
 >>> form.is_valid()
@@ -95,9 +113,9 @@
95 113
 >>> form.non_field_errors()
96 114
 []
97 115
 
98  
-SetPasswordForm:
  116
+### SetPasswordForm:
99 117
 
100  
-The two new passwords do not match.
  118
+# The two new passwords do not match.
101 119
 
102 120
 >>> data = {
103 121
 ...     'new_password1': 'abc123',
@@ -109,7 +127,7 @@
109 127
 >>> form["new_password2"].errors
110 128
 [u"The two password fields didn't match."]
111 129
 
112  
-The success case.
  130
+# The success case.
113 131
 
114 132
 >>> data = {
115 133
 ...     'new_password1': 'abc123',
@@ -119,7 +137,7 @@
119 137
 >>> form.is_valid()
120 138
 True
121 139
 
122  
-PasswordChangeForm:
  140
+### PasswordChangeForm:
123 141
 
124 142
 The old password is incorrect.
125 143
 
@@ -134,7 +152,7 @@
134 152
 >>> form["old_password"].errors
135 153
 [u'Your old password was entered incorrectly. Please enter it again.']
136 154
 
137  
-The two new passwords do not match.
  155
+# The two new passwords do not match.
138 156
 
139 157
 >>> data = {
140 158
 ...     'old_password': 'test123',
@@ -147,7 +165,7 @@
147 165
 >>> form["new_password2"].errors
148 166
 [u"The two password fields didn't match."]
149 167
 
150  
-The success case.
  168
+# The success case.
151 169
 
152 170
 >>> data = {
153 171
 ...     'old_password': 'test123',
@@ -158,7 +176,7 @@
158 176
 >>> form.is_valid()
159 177
 True
160 178
 
161  
-Regression test - check the order of fields:
  179
+# Regression test - check the order of fields:
162 180
 
163 181
 >>> PasswordChangeForm(user, {}).fields.keys()
164 182
 ['old_password', 'new_password1', 'new_password2']

0 notes on commit 15ed0d6

Please sign in to comment.
Something went wrong with that request. Please try again.