summaryrefslogtreecommitdiff
path: root/tests/regressiontests/forms
diff options
context:
space:
mode:
authorJulien Phalip <jphalip@gmail.com>2011-11-15 09:36:08 +0000
committerJulien Phalip <jphalip@gmail.com>2011-11-15 09:36:08 +0000
commita6ccc8cc06e6b304e35f7a16f6067e6fa09b63ce (patch)
tree317847d7f4a0b205415653f04ce9ea9e710ea877 /tests/regressiontests/forms
parentfae75a32eed227454873f8715bb0d11d6fc3ad39 (diff)
Fixed #15912 -- Ensured that `forms.CharField.widget_attrs()` always returns a dictionary. Thanks to tsabi and rubyruy for the report and to mmcnickle and prestontimmons for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17096 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/forms')
-rw-r--r--tests/regressiontests/forms/tests/fields.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
index 0f9e91a55e..7dd3a27dc1 100644
--- a/tests/regressiontests/forms/tests/fields.py
+++ b/tests/regressiontests/forms/tests/fields.py
@@ -136,6 +136,23 @@ class FieldsTests(SimpleTestCase):
self.assertEqual(f.max_length, None)
self.assertEqual(f.min_length, 10)
+ def test_charfield_widget_attrs(self):
+ """
+ Ensure that CharField.widget_attrs() always returns a dictionary.
+ Refs #15912
+ """
+ # Return an empty dictionary if max_length is None
+ f = CharField()
+ self.assertEqual(f.widget_attrs(TextInput()), {})
+
+ # Or if the widget is not TextInput or PasswordInput
+ f = CharField(max_length=10)
+ self.assertEqual(f.widget_attrs(HiddenInput()), {})
+
+ # Otherwise, return a maxlength attribute equal to max_length
+ self.assertEqual(f.widget_attrs(TextInput()), {'maxlength': '10'})
+ self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '10'})
+
# IntegerField ################################################################
def test_integerfield_1(self):