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

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

    # HG changeset patch
    # Parent 898f33efebdafb0a13ab8b69dc3b835ab2da9c0e
    
    diff --git a/tests/regressiontests/forms/formsets.py b/tests/regressiontests/forms/formsets.py
    a b  
    308308
    309309If we fill a form with something and then we check the can_delete checkbox for
    310310that form, that form's errors should not make the entire formset invalid since
    311 it's going to be deleted.
     311it's going to be deleted. Some forms are invalid so we cannot use cleaned_data.
    312312
    313313>>> class CheckForm(Form):
    314314...    field = IntegerField(min_value=100)
     
    328328>>> formset = CheckFormSet(data, prefix='check')
    329329>>> formset.is_valid()
    330330True
     331>>> [form.cleaned_data for form in formset.forms]
     332Traceback (most recent call last):
     333...
     334AttributeError: 'CheckForm' object has no attribute 'cleaned_data'
    331335
    332336If we remove the deletion flag now we will have our validation back.
    333337
     
    517521[{'votes': 900, 'DELETE': True, 'ORDER': 2, 'choice': u'Fergie'}]
    518522
    519523Should be able to get ordered forms from a valid formset even if a
    520 deleted form would have been invalid.
     524deleted form would have been invalid and without cleaned_data.
    521525
    522526>>> class Person(Form):
    523527...     name = CharField()
     
    529533
    530534>>> p = PeopleForm(
    531535...     {'form-0-name': u'', 'form-0-DELETE': u'on', # no name!
    532 ...      'form-TOTAL_FORMS': 1, 'form-INITIAL_FORMS': 1,
    533 ...      'form-MAX_NUM_FORMS': 1})
     536...      'form-1-name': u'John Smith', 'form-1-DELETE': u'',
     537...      'form-TOTAL_FORMS': 2, 'form-INITIAL_FORMS': 2,
     538...      'form-MAX_NUM_FORMS': 2})
    534539
    535540>>> p.is_valid()
    536541True
    537 >>> p.ordered_forms
    538 []
     542>>> for form in p.ordered_forms:
     543...    print form.cleaned_data
     544{'DELETE': False, 'name': u'John Smith', 'ORDER': None}
     545>>> [form.cleaned_data for form in p.forms]
     546Traceback (most recent call last):
     547...
     548AttributeError: 'Person' object has no attribute 'cleaned_data'
    539549
    540550# FormSet clean hook ##########################################################
    541551
Back to Top