summaryrefslogtreecommitdiff
path: root/tests
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:44:00 +0200
commitbe29329ccd49a84d3f7238111aebf97c4aaac581 (patch)
treea28703c990cb40466fc0cbec4851ca5ad89edd82 /tests
parent90c76564669fa03caefcf4318ffdf9ba8fa4d40b (diff)
Fixed #16820 -- Treated '0' value as True for checkbox inputs
Thanks Dan Fairs for the report and the initial patch.
Diffstat (limited to 'tests')
-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))