diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-03-04 14:12:13 +0000 |
---|---|---|
committer | Claude Paroz <claude@2xlibre.net> | 2014-03-05 20:09:28 +0100 |
commit | 95c74b9d699c29fe808684774548e2864d64665a (patch) | |
tree | 8edba19c8beba0a514b65f2f28a2c8c02e47b91f /tests | |
parent | ac699cdc174a825e6b78c6f3c6e967bc961413c8 (diff) | |
download | django-95c74b9d699c29fe808684774548e2864d64665a.tar.gz |
Fixed #22206 -- Passed models.TextField.max_length to forms.CharField.maxlength
Diffstat (limited to 'tests')
-rw-r--r-- | tests/forms_tests/tests/test_fields.py | 9 | ||||
-rw-r--r-- | tests/model_fields/tests.py | 15 | ||||
-rw-r--r-- | tests/model_forms/tests.py | 2 |
3 files changed, 20 insertions, 6 deletions
diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py index 8cea26c37c..5a42e4b95d 100644 --- a/tests/forms_tests/tests/test_fields.py +++ b/tests/forms_tests/tests/test_fields.py @@ -38,7 +38,7 @@ from django.forms import ( DecimalField, EmailField, Field, FileField, FilePathField, FloatField, Form, forms, HiddenInput, IntegerField, MultipleChoiceField, NullBooleanField, NumberInput, PasswordInput, RadioSelect, RegexField, - SplitDateTimeField, TextInput, TimeField, TypedChoiceField, + SplitDateTimeField, TextInput, Textarea, TimeField, TypedChoiceField, TypedMultipleChoiceField, URLField, ValidationError, Widget, ) from django.test import SimpleTestCase @@ -148,14 +148,13 @@ class FieldsTests(SimpleTestCase): # 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()), {}) + self.assertEqual(f.widget_attrs(Textarea()), {}) # Otherwise, return a maxlength attribute equal to max_length + f = CharField(max_length=10) self.assertEqual(f.widget_attrs(TextInput()), {'maxlength': '10'}) self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '10'}) + self.assertEqual(f.widget_attrs(Textarea()), {'maxlength': '10'}) # IntegerField ################################################################ diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index f9d1a76078..194219a114 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -203,6 +203,21 @@ class BooleanFieldTests(unittest.TestCase): def test_nullbooleanfield_to_python(self): self._test_to_python(models.NullBooleanField()) + def test_charfield_textfield_max_length_passed_to_formfield(self): + """ + Test that CharField and TextField pass their max_length attributes to + form fields created using their .formfield() method (#22206). + """ + cf1 = models.CharField() + cf2 = models.CharField(max_length=1234) + self.assertIsNone(cf1.formfield().max_length) + self.assertEqual(1234, cf2.formfield().max_length) + + tf1 = models.TextField() + tf2 = models.TextField(max_length=2345) + self.assertIsNone(tf1.formfield().max_length) + self.assertEqual(2345, tf2.formfield().max_length) + def test_booleanfield_choices_blank(self): """ Test that BooleanField with choices and defaults doesn't generate a diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index ba72db6bdc..c75921c6e3 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -533,7 +533,7 @@ class TestFieldOverridesByFormMeta(TestCase): form = FieldOverridesByFormMetaForm() self.assertHTMLEqual( str(form['name']), - '<textarea id="id_name" rows="10" cols="40" name="name"></textarea>', + '<textarea id="id_name" rows="10" cols="40" name="name" maxlength="20"></textarea>', ) self.assertHTMLEqual( str(form['url']), |