From 342517000cedefef6c0e9f92945362fef3d2e39b Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Tue, 16 Feb 2010 12:17:37 +0000 Subject: [PATCH] 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 --- tests/regressiontests/admin_views/models.py | 15 +++++++++++++++ tests/regressiontests/admin_views/tests.py | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index 384a6d92a6..b5d8f94988 100644 --- a/tests/regressiontests/admin_views/models.py +++ b/tests/regressiontests/admin_views/models.py @@ -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 diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index d52a57f9ee..0f6f79d85c 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -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")