From a6ccc8cc06e6b304e35f7a16f6067e6fa09b63ce Mon Sep 17 00:00:00 2001 From: Julien Phalip Date: Tue, 15 Nov 2011 09:36:08 +0000 Subject: 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 --- tests/regressiontests/forms/tests/fields.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests') 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): -- cgit v1.3