summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2008-08-25 16:55:57 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2008-08-25 16:55:57 +0000
commit15ed0d65b0d036629dade79114093845daaa6f52 (patch)
tree1c87e3e8cb6169a48c2a2b4783fbbb899279f2d8
parente3df35478d5066972b0ef8ef5bb44acf5b0fb982 (diff)
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
-rw-r--r--django/contrib/auth/forms.py2
-rw-r--r--django/contrib/auth/tests/forms.py46
2 files changed, 33 insertions, 15 deletions
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
index 13647865d4..8df749c403 100644
--- a/django/contrib/auth/forms.py
+++ b/django/contrib/auth/forms.py
@@ -30,7 +30,7 @@ class UserCreationForm(forms.ModelForm):
raise forms.ValidationError(_("A user with that username already exists."))
def clean_password2(self):
- password1 = self.cleaned_data["password1"]
+ password1 = self.cleaned_data.get("password1", "")
password2 = self.cleaned_data["password2"]
if password1 != password2:
raise forms.ValidationError(_("The two password fields didn't match."))
diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py
index 01f4995bb7..797f6bdb3e 100644
--- a/django/contrib/auth/tests/forms.py
+++ b/django/contrib/auth/tests/forms.py
@@ -4,7 +4,7 @@ FORM_TESTS = """
>>> from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
>>> from django.contrib.auth.forms import PasswordChangeForm, SetPasswordForm
-The user already exists.
+# The user already exists.
>>> user = User.objects.create_user("jsmith", "jsmith@example.com", "test123")
>>> data = {
@@ -18,7 +18,7 @@ False
>>> form["username"].errors
[u'A user with that username already exists.']
-The username contains invalid data.
+# The username contains invalid data.
>>> data = {
... 'username': 'jsmith@example.com',
@@ -31,7 +31,7 @@ False
>>> form["username"].errors
[u'This value must contain only letters, numbers and underscores.']
-The verification password is incorrect.
+# The verification password is incorrect.
>>> data = {
... 'username': 'jsmith2',
@@ -44,7 +44,25 @@ False
>>> form["password2"].errors
[u"The two password fields didn't match."]
-The success case.
+# One (or both) passwords weren't given
+
+>>> data = {'username': 'jsmith2'}
+>>> form = UserCreationForm(data)
+>>> form.is_valid()
+False
+>>> form['password1'].errors
+[u'This field is required.']
+>>> form['password2'].errors
+[u'This field is required.']
+
+>>> data['password2'] = 'test123'
+>>> form = UserCreationForm(data)
+>>> form.is_valid()
+False
+>>> form['password1'].errors
+[u'This field is required.']
+
+# The success case.
>>> data = {
... 'username': 'jsmith2',
@@ -57,7 +75,7 @@ True
>>> form.save()
<User: jsmith2>
-The user submits an invalid username.
+# The user submits an invalid username.
>>> data = {
... 'username': 'jsmith_does_not_exist',
@@ -70,7 +88,7 @@ False
>>> form.non_field_errors()
[u'Please enter a correct username and password. Note that both fields are case-sensitive.']
-The user is inactive.
+# The user is inactive.
>>> data = {
... 'username': 'jsmith',
@@ -87,7 +105,7 @@ False
>>> user.is_active = True
>>> user.save()
-The success case
+# The success case
>>> form = AuthenticationForm(None, data)
>>> form.is_valid()
@@ -95,9 +113,9 @@ True
>>> form.non_field_errors()
[]
-SetPasswordForm:
+### SetPasswordForm:
-The two new passwords do not match.
+# The two new passwords do not match.
>>> data = {
... 'new_password1': 'abc123',
@@ -109,7 +127,7 @@ False
>>> form["new_password2"].errors
[u"The two password fields didn't match."]
-The success case.
+# The success case.
>>> data = {
... 'new_password1': 'abc123',
@@ -119,7 +137,7 @@ The success case.
>>> form.is_valid()
True
-PasswordChangeForm:
+### PasswordChangeForm:
The old password is incorrect.
@@ -134,7 +152,7 @@ False
>>> form["old_password"].errors
[u'Your old password was entered incorrectly. Please enter it again.']
-The two new passwords do not match.
+# The two new passwords do not match.
>>> data = {
... 'old_password': 'test123',
@@ -147,7 +165,7 @@ False
>>> form["new_password2"].errors
[u"The two password fields didn't match."]
-The success case.
+# The success case.
>>> data = {
... 'old_password': 'test123',
@@ -158,7 +176,7 @@ The success case.
>>> form.is_valid()
True
-Regression test - check the order of fields:
+# Regression test - check the order of fields:
>>> PasswordChangeForm(user, {}).fields.keys()
['old_password', 'new_password1', 'new_password2']