Ticket #13878: 02-formset-refactoring-cleaned-data-tests.diff

File 02-formset-refactoring-cleaned-data-tests.diff, 1.9 KB (added by Petr Marhoun <petr.marhoun@…>, 14 years ago)
  • tests/regressiontests/forms/formsets.py

    diff --git a/tests/regressiontests/forms/formsets.py b/tests/regressiontests/forms/formsets.py
    a b  
    304304
    305305If we fill a form with something and then we check the can_delete checkbox for
    306306that form, that form's errors should not make the entire formset invalid since
    307 it's going to be deleted.
     307it's going to be deleted. Some forms are invalid so we cannot use cleaned_data.
    308308
    309309>>> class CheckForm(Form):
    310310...    field = IntegerField(min_value=100)
     
    324324>>> formset = CheckFormSet(data, prefix='check')
    325325>>> formset.is_valid()
    326326True
     327>>> [form.cleaned_data for form in formset.forms]
     328Traceback (most recent call last):
     329...
     330AttributeError: 'CheckForm' object has no attribute 'cleaned_data'
    327331
    328332If we remove the deletion flag now we will have our validation back.
    329333
     
    513517[{'votes': 900, 'DELETE': True, 'ORDER': 2, 'choice': u'Fergie'}]
    514518
    515519Should be able to get ordered forms from a valid formset even if a
    516 deleted form would have been invalid.
     520deleted form would have been invalid and without cleaned_data.
    517521
    518522>>> class Person(Form):
    519523...     name = CharField()
     
    525529
    526530>>> p = PeopleForm(
    527531...     {'form-0-name': u'', 'form-0-DELETE': u'on', # no name!
    528 ...      'form-TOTAL_FORMS': 1, 'form-INITIAL_FORMS': 1,
    529 ...      'form-MAX_NUM_FORMS': 1})
     532...      'form-1-name': u'John Smith', 'form-1-DELETE': u'',
     533...      'form-TOTAL_FORMS': 2, 'form-INITIAL_FORMS': 2,
     534...      'form-MAX_NUM_FORMS': 2})
    530535
    531536>>> p.is_valid()
    532537True
    533 >>> p.ordered_forms
    534 []
     538>>> for form in p.ordered_forms:
     539...    print form.cleaned_data
     540{'DELETE': False, 'name': u'John Smith', 'ORDER': None}
     541>>> [form.cleaned_data for form in p.forms]
     542Traceback (most recent call last):
     543...
     544AttributeError: 'Person' object has no attribute 'cleaned_data'
    535545
    536546# FormSet clean hook ##########################################################
    537547
Back to Top