Added missing tests for fix committed in r12398. Thanks Karen for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12448 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2010-02-16 12:17:37 +00:00
parent 12d40a9fd6
commit 342517000c
2 changed files with 29 additions and 0 deletions

View File

@ -8,6 +8,8 @@ from django.core.files.storage import FileSystemStorage
from django.contrib.admin.views.main import ChangeList
from django.core.mail import EmailMessage
from django.db import models
from django import forms
from django.forms.models import BaseModelFormSet
class Section(models.Model):
@ -173,6 +175,14 @@ class Person(models.Model):
class Meta:
ordering = ["id"]
class BasePersonModelFormSet(BaseModelFormSet):
def clean(self):
for person_dict in self.cleaned_data:
person = person_dict.get('id')
alive = person_dict.get('alive')
if person and alive and person.name == "Grace Hopper":
raise forms.ValidationError, "Grace is not a Zombie"
class PersonAdmin(admin.ModelAdmin):
list_display = ('name', 'gender', 'alive')
list_editable = ('gender', 'alive')
@ -181,6 +191,11 @@ class PersonAdmin(admin.ModelAdmin):
ordering = ["id"]
save_as = True
def get_changelist_formset(self, request, **kwargs):
return super(PersonAdmin, self).get_changelist_formset(request,
formset=BasePersonModelFormSet, **kwargs)
class Persona(models.Model):
"""
A simple persona associated with accounts, to test inlining of related

View File

@ -992,6 +992,20 @@ class AdminViewListEditable(TestCase):
self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False)
def test_non_form_errors(self):
# test if non-form errors are handled; ticket #12716
data = {
"form-TOTAL_FORMS": "1",
"form-INITIAL_FORMS": "1",
"form-MAX_NUM_FORMS": "0",
"form-0-id": "2",
"form-0-alive": "1",
"form-0-gender": "2",
}
response = self.client.post('/test_admin/admin/admin_views/person/', data)
self.assertContains(response, "Grace is not a Zombie")
def test_list_editable_ordering(self):
collector = Collector.objects.create(id=1, name="Frederick Clegg")