summaryrefslogtreecommitdiff
path: root/tests/regressiontests/forms
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-10-26 20:44:00 +0200
committerClaude Paroz <claude@2xlibre.net>2012-10-26 20:48:57 +0200
commitfbb664066f8970279af020cf163cb364156290c3 (patch)
tree062ae36f631dc02177c27952dce93b6419d15295 /tests/regressiontests/forms
parent02b66f161f3b27e31a93527eac32504125de576a (diff)
[1.5.x] Fixed #16820 -- Treated '0' value as True for checkbox inputs
Thanks Dan Fairs for the report and the initial patch. Backport of be29329cc from master.
Diffstat (limited to 'tests/regressiontests/forms')
-rw-r--r--tests/regressiontests/forms/tests/forms.py5
-rw-r--r--tests/regressiontests/forms/tests/widgets.py4
2 files changed, 9 insertions, 0 deletions
diff --git a/tests/regressiontests/forms/tests/forms.py b/tests/regressiontests/forms/tests/forms.py
index a8a28ba806..1c83ed04d4 100644
--- a/tests/regressiontests/forms/tests/forms.py
+++ b/tests/regressiontests/forms/tests/forms.py
@@ -269,6 +269,11 @@ class FormsTestCase(TestCase):
f = SignupForm({'email': 'test@example.com', 'get_spam': 'false'}, auto_id=False)
self.assertHTMLEqual(str(f['get_spam']), '<input type="checkbox" name="get_spam" />')
+ # A value of '0' should be interpreted as a True value (#16820)
+ f = SignupForm({'email': 'test@example.com', 'get_spam': '0'})
+ self.assertTrue(f.is_valid())
+ self.assertTrue(f.cleaned_data.get('get_spam'))
+
def test_widget_output(self):
# Any Field can have a Widget class passed to its constructor:
class ContactForm(Form):
diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py
index 4bdd3f76ea..88469a79e8 100644
--- a/tests/regressiontests/forms/tests/widgets.py
+++ b/tests/regressiontests/forms/tests/widgets.py
@@ -225,6 +225,10 @@ class FormsWidgetTestCase(TestCase):
# checkboxes).
self.assertFalse(w.value_from_datadict({}, {}, 'testing'))
+ value = w.value_from_datadict({'testing': '0'}, {}, 'testing')
+ self.assertIsInstance(value, bool)
+ self.assertTrue(value)
+
self.assertFalse(w._has_changed(None, None))
self.assertFalse(w._has_changed(None, ''))
self.assertFalse(w._has_changed('', None))