Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 342517000cedefef6c0e9f92945362fef3d2e39b 1 parent 12d40a9
@jezdez jezdez authored
View
15 tests/regressiontests/admin_views/models.py
@@ -8,6 +8,8 @@
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 @@ def __unicode__(self):
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
14 tests/regressiontests/admin_views/tests.py
@@ -992,6 +992,20 @@ def test_post_submission(self):
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")
Please sign in to comment.
Something went wrong with that request. Please try again.