Fixed #12295 -- Issue had already been fixed, but added test. Thanks tomevans222 and dpn.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15158 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Andrew Godwin 2011-01-08 14:37:26 +00:00
parent 81e05a418d
commit d216ff9b92
1 changed files with 15 additions and 0 deletions

View File

@ -29,6 +29,11 @@ class BaseFavoriteDrinksFormSet(BaseFormSet):
seen_drinks.append(drink['name']) seen_drinks.append(drink['name'])
class EmptyFsetWontValidate(BaseFormSet):
def clean(self):
raise ValidationError("Clean method called")
# Let's define a FormSet that takes a list of favorite drinks, but raises an # Let's define a FormSet that takes a list of favorite drinks, but raises an
# error if there are any duplicates. Used in ``test_clean_hook``, # error if there are any duplicates. Used in ``test_clean_hook``,
# ``test_regression_6926`` & ``test_regression_12878``. # ``test_regression_6926`` & ``test_regression_12878``.
@ -872,3 +877,13 @@ class TestIsBoundBehavior(TestCase):
formset = ArticleFormSet(data) formset = ArticleFormSet(data)
self.assertFalse(formset.is_valid()) self.assertFalse(formset.is_valid())
self.assertEquals([{}, {'pub_date': [u'This field is required.']}], formset.errors) self.assertEquals([{}, {'pub_date': [u'This field is required.']}], formset.errors)
class TestEmptyFormSet(TestCase):
"Test that an empty formset still calls clean()"
def test_empty_formset_is_valid(self):
EmptyFsetWontValidateFormset = formset_factory(FavoriteDrinkForm, extra=0, formset=EmptyFsetWontValidate)
formset = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'0'},prefix="form")
formset2 = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'1', 'form-0-name':'bah' },prefix="form")
self.assertFalse(formset.is_valid())
self.assertFalse(formset2.is_valid())