diff options
| author | Yang Liu <raully7@gmail.com> | 2015-01-06 17:07:40 +0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-01-15 20:19:53 -0500 |
| commit | 3f9ec12d9c9eff9a3b1a205d87c7e66587cf9967 (patch) | |
| tree | 3c39cb2dfca91b44e82c586daf58ac17d43f269c /tests/forms_tests | |
| parent | faf0d66a80e09be3656a337c33a8e70c7fbab7e3 (diff) | |
Fixed #23712 -- Fixed KeyError with BaseForm._html_output()
Diffstat (limited to 'tests/forms_tests')
| -rw-r--r-- | tests/forms_tests/tests/test_forms.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 5b1c85ce6a..c0ce912fe1 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -2191,6 +2191,60 @@ class FormsTestCase(TestCase): form = SomeForm() self.assertHTMLEqual(form.as_p(), '<p id="p_some_field"></p>') + def test_field_name_with_hidden_input(self): + """ + BaseForm._html_output() should merge all the hidden input fields and + put them in the last row. + """ + class SomeForm(Form): + hidden1 = CharField(widget=HiddenInput) + custom = CharField() + hidden2 = CharField(widget=HiddenInput) + + def as_p(self): + return self._html_output( + normal_row='<p%(html_class_attr)s>%(field)s %(field_name)s</p>', + error_row='%s', + row_ender='</p>', + help_text_html=' %s', + errors_on_separate_row=True, + ) + + form = SomeForm() + self.assertHTMLEqual( + form.as_p(), + '<p><input id="id_custom" name="custom" type="text" /> custom' + '<input id="id_hidden1" name="hidden1" type="hidden" />' + '<input id="id_hidden2" name="hidden2" type="hidden" /></p>' + ) + + def test_field_name_with_hidden_input_and_non_matching_row_ender(self): + """ + BaseForm._html_output() should merge all the hidden input fields and + put them in the last row ended with the specific row ender. + """ + class SomeForm(Form): + hidden1 = CharField(widget=HiddenInput) + custom = CharField() + hidden2 = CharField(widget=HiddenInput) + + def as_p(self): + return self._html_output( + normal_row='<p%(html_class_attr)s>%(field)s %(field_name)s</p>', + error_row='%s', + row_ender='<hr/><hr/>', + help_text_html=' %s', + errors_on_separate_row=True + ) + + form = SomeForm() + self.assertHTMLEqual( + form.as_p(), + '<p><input id="id_custom" name="custom" type="text" /> custom</p>\n' + '<input id="id_hidden1" name="hidden1" type="hidden" />' + '<input id="id_hidden2" name="hidden2" type="hidden" /><hr/><hr/>' + ) + def test_error_dict(self): class MyForm(Form): foo = CharField() |
