Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit d216ff9b922aa246be5d199401494946f4a37ff7 1 parent 81e05a4
Andrew Godwin authored January 08, 2011
15  tests/regressiontests/forms/tests/formsets.py
@@ -29,6 +29,11 @@ def clean(self):
29 29
             seen_drinks.append(drink['name'])
30 30
 
31 31
 
  32
+class EmptyFsetWontValidate(BaseFormSet):
  33
+    def clean(self):
  34
+        raise ValidationError("Clean method called")
  35
+
  36
+
32 37
 # Let's define a FormSet that takes a list of favorite drinks, but raises an
33 38
 # error if there are any duplicates. Used in ``test_clean_hook``,
34 39
 # ``test_regression_6926`` & ``test_regression_12878``.
@@ -872,3 +877,13 @@ def test_form_errors_are_cought_by_formset(self):
872 877
         formset = ArticleFormSet(data)
873 878
         self.assertFalse(formset.is_valid())
874 879
         self.assertEquals([{}, {'pub_date': [u'This field is required.']}], formset.errors)
  880
+
  881
+class TestEmptyFormSet(TestCase): 
  882
+    "Test that an empty formset still calls clean()"
  883
+    def test_empty_formset_is_valid(self): 
  884
+        EmptyFsetWontValidateFormset = formset_factory(FavoriteDrinkForm, extra=0, formset=EmptyFsetWontValidate) 
  885
+        formset = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'0'},prefix="form") 
  886
+        formset2 = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'1', 'form-0-name':'bah' },prefix="form") 
  887
+        self.assertFalse(formset.is_valid()) 
  888
+        self.assertFalse(formset2.is_valid()) 
  889
+

0 notes on commit d216ff9

Please sign in to comment.
Something went wrong with that request. Please try again.