Friday, October 8, 2010

Testing formset validation

I have a pretty simple form, defined below, that I am setting
according to some initial data, and no matter what I try, I can't seem
to get it to validate in a test.

I have created some test data, which is an array with one dictionary
element, where the dictionary corresponds to the form. If I create a
singular from from the dictionary element, it is valid, but if I
create a formset from the list which contains only that very same
dictionary, it's not valid.

###

class FormulaRow(forms.Form):
ingredient_number = forms.CharField(label="")
amount = forms.DecimalField(label="", max_digits=9,
decimal_places=5)

###

>>> initial = [{'amount': '1000.000', 'ingredient_number': '100'}]
>>> initial_singular= initial[0]
>>> form = FormulaRow(initial_singular)
>>> form.is_valid()
True
>>> FormulaFormSet = formset_factory(FormulaRow)
>>> formset = FormulaFormSet(initial=initial)
>>> formset.is_valid()
False

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate