diff options
| author | Joseph Kocherhans <joseph@jkocherhans.com> | 2010-01-12 02:29:45 +0000 |
|---|---|---|
| committer | Joseph Kocherhans <joseph@jkocherhans.com> | 2010-01-12 02:29:45 +0000 |
| commit | 2f9853b2dc90f30317e0374396f08e3d142844d2 (patch) | |
| tree | 6f5ade3551fbc6ac7caa11eae3b2087e94a0e975 /tests/regressiontests/admin_views | |
| parent | 26279c572101ac1b277fc3947897cb8e840ea42e (diff) | |
Fixed #12512. Changed ModelForm to stop performing model validation on fields that are not part of the form. Thanks, Honza Kral and Ivan Sagalaev.
This reverts some admin and test changes from [12098] and also fixes #12507, #12520, #12552 and #12553.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12206 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/admin_views')
| -rw-r--r-- | tests/regressiontests/admin_views/tests.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 0c7fbc0876..c580491486 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -4,7 +4,8 @@ import re import datetime from django.core.files import temp as tempfile from django.test import TestCase -from django.contrib.auth.models import User, Permission +from django.contrib.auth import admin # Register auth models with the admin. +from django.contrib.auth.models import User, Permission, UNUSABLE_PASSWORD from django.contrib.contenttypes.models import ContentType from django.contrib.admin.models import LogEntry, DELETION from django.contrib.admin.sites import LOGIN_FORM_KEY @@ -1766,3 +1767,37 @@ class ReadonlyTest(TestCase): self.assertEqual(Post.objects.count(), 2) p = Post.objects.order_by('-id')[0] self.assertEqual(p.posted, datetime.date.today()) + +class IncompleteFormTest(TestCase): + """ + Tests validation of a ModelForm that doesn't explicitly have all data + corresponding to model fields. Model validation shouldn't fail + such a forms. + """ + fixtures = ['admin-views-users.xml'] + + def setUp(self): + self.client.login(username='super', password='secret') + + def tearDown(self): + self.client.logout() + + def test_user_creation(self): + response = self.client.post('/test_admin/admin/auth/user/add/', { + 'username': 'newuser', + 'password1': 'newpassword', + 'password2': 'newpassword', + }) + new_user = User.objects.order_by('-id')[0] + self.assertRedirects(response, '/test_admin/admin/auth/user/%s/' % new_user.pk) + self.assertNotEquals(new_user.password, UNUSABLE_PASSWORD) + + def test_password_mismatch(self): + response = self.client.post('/test_admin/admin/auth/user/add/', { + 'username': 'newuser', + 'password1': 'newpassword', + 'password2': 'mismatch', + }) + self.assertEquals(response.status_code, 200) + self.assert_('password' not in response.context['form'].errors) + self.assertFormError(response, 'form', 'password2', ["The two password fields didn't match."]) |
