diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-10 13:43:21 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-17 11:49:15 +0100 |
commit | 182d25eb7a227206746bfa30aab13aaa34d1de84 (patch) | |
tree | 8a438dfb1e7401dfc00773cff16fc781de648040 /tests/forms_tests | |
parent | 4982958ec0c359908566fc1f34ef71297ea4337d (diff) | |
download | django-182d25eb7a227206746bfa30aab13aaa34d1de84.tar.gz |
Refs #31026 -- Removed BaseForm._html_output() per deprecation timeline.
Diffstat (limited to 'tests/forms_tests')
-rw-r--r-- | tests/forms_tests/tests/test_deprecation_forms.py | 135 |
1 files changed, 1 insertions, 134 deletions
diff --git a/tests/forms_tests/tests/test_deprecation_forms.py b/tests/forms_tests/tests/test_deprecation_forms.py index 2a4fb6b0e1..dbc751bae8 100644 --- a/tests/forms_tests/tests/test_deprecation_forms.py +++ b/tests/forms_tests/tests/test_deprecation_forms.py @@ -1,11 +1,9 @@ # RemovedInDjango50 -from django.forms import CharField, EmailField, Form, HiddenInput +from django.forms import CharField, EmailField, Form from django.forms.utils import ErrorList from django.test import SimpleTestCase, ignore_warnings from django.utils.deprecation import RemovedInDjango50Warning -from .test_forms import Person - class DivErrorList(ErrorList): def __str__(self): @@ -20,21 +18,6 @@ class DivErrorList(ErrorList): class DeprecationTests(SimpleTestCase): - def test_deprecation_warning_html_output(self): - msg = ( - "django.forms.BaseForm._html_output() is deprecated. Please use " - ".render() and .get_context() instead." - ) - with self.assertRaisesMessage(RemovedInDjango50Warning, msg): - form = Person() - form._html_output( - normal_row='<p id="p_%(field_name)s"></p>', - error_row="%s", - row_ender="</p>", - help_text_html=" %s", - errors_on_separate_row=True, - ) - def test_deprecation_warning_error_list(self): class EmailForm(Form): email = EmailField() @@ -70,119 +53,3 @@ class DeprecatedTests(SimpleTestCase): '<div class="error">This field is required.</div></div>' '<p>Comment: <input type="text" name="comment" required></p>', ) - - def test_field_name(self): - """#5749 - `field_name` may be used as a key in _html_output().""" - - class SomeForm(Form): - some_field = CharField() - - def as_p(self): - return self._html_output( - normal_row='<p id="p_%(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 id="p_some_field"></p>') - - def test_field_without_css_classes(self): - """ - `css_classes` may be used as a key in _html_output() (empty classes). - """ - - class SomeForm(Form): - some_field = CharField() - - def as_p(self): - return self._html_output( - normal_row='<p class="%(css_classes)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 class=""></p>') - - def test_field_with_css_class(self): - """ - `css_classes` may be used as a key in _html_output() (class comes - from required_css_class in this case). - """ - - class SomeForm(Form): - some_field = CharField() - required_css_class = "foo" - - def as_p(self): - return self._html_output( - normal_row='<p class="%(css_classes)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 class="foo"></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" required> 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" required> custom</p>\n' - '<input id="id_hidden1" name="hidden1" type="hidden">' - '<input id="id_hidden2" name="hidden2" type="hidden"><hr><hr>', - ) |