Ticket #12878: 12878-2.diff

File 12878-2.diff, 2.8 KB (added by matiasb, 15 years ago)

Updated previous patch to add general formset test

  • django/forms/formsets.py

     
    271271        try:
    272272            self.clean()
    273273        except ValidationError, e:
    274             self._non_form_errors = e.messages
     274            self._non_form_errors = self.error_class(e.messages)
    275275
    276276    def clean(self):
    277277        """
  • tests/regressiontests/admin_views/tests.py

     
    1111from django.contrib.admin.sites import LOGIN_FORM_KEY
    1212from django.contrib.admin.util import quote
    1313from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
     14from django.forms.util import ErrorList
    1415from django.utils import formats
    1516from django.utils.cache import get_max_age
    1617from django.utils.html import escape
     
    10281029        response = self.client.post('/test_admin/admin/admin_views/person/', data)
    10291030        self.assertContains(response, "Grace is not a Zombie")
    10301031
     1032    def test_non_form_errors_is_errorlist(self):
     1033        # test if non-form errors are correctly handled; ticket #12878
     1034        data = {
     1035            "form-TOTAL_FORMS": "1",
     1036            "form-INITIAL_FORMS": "1",
     1037            "form-MAX_NUM_FORMS": "0",
     1038
     1039            "form-0-id": "2",
     1040            "form-0-alive": "1",
     1041            "form-0-gender": "2",
     1042        }
     1043        response = self.client.post('/test_admin/admin/admin_views/person/', data)
     1044        non_form_errors = response.context['cl'].formset.non_form_errors()
     1045        self.assert_(isinstance(non_form_errors, ErrorList))
     1046        self.assertEqual(str(non_form_errors), str(ErrorList(["Grace is not a Zombie"])))
     1047
    10311048    def test_list_editable_ordering(self):
    10321049        collector = Collector.objects.create(id=1, name="Frederick Clegg")
    10331050
  • tests/regressiontests/forms/formsets.py

     
    621621>>> formset.management_form.prefix
    622622'form'
    623623
     624# Regression test for #12878 #################################################
     625
     626>>> data = {
     627...     'drinks-TOTAL_FORMS': '2', # the number of forms rendered
     628...     'drinks-INITIAL_FORMS': '0', # the number of forms with initial data
     629...     'drinks-MAX_NUM_FORMS': '0', # max number of forms
     630...     'drinks-0-name': 'Gin and Tonic',
     631...     'drinks-1-name': 'Gin and Tonic',
     632... }
     633
     634>>> formset = FavoriteDrinksFormSet(data, prefix='drinks')
     635>>> formset.is_valid()
     636False
     637>>> print formset.non_form_errors()
     638<ul class="errorlist"><li>You may only specify a drink once.</li></ul>
     639
    624640"""
Back to Top