From 4ca508a68916dd43da45fd6e8b9004824a62d9c8 Mon Sep 17 00:00:00 2001 From: David Smith Date: Fri, 10 Sep 2021 08:04:05 +0100 Subject: [PATCH] Refs #31026 -- Added extra form render tests. --- tests/forms_tests/tests/test_forms.py | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 2513380286..b713cb1321 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -20,6 +20,7 @@ from django.forms.utils import ErrorList from django.http import QueryDict from django.template import Context, Template from django.test import SimpleTestCase +from django.test.utils import override_settings from django.utils.datastructures import MultiValueDict from django.utils.safestring import mark_safe @@ -1248,6 +1249,24 @@ value="Should escape < & > and <script>alert('xss')< self.assertEqual(f.errors, error_dict) f.as_table() self.assertEqual(f.errors, error_dict) + self.assertHTMLEqual( + f.as_table(), + '' + '', + ) + self.assertHTMLEqual( + f.as_ul(), + '
  • ' + '
  • ', + ) + self.assertHTMLEqual( + f.as_p(), + '' + '

    ', + ) def test_dynamic_construction(self): # It's possible to construct a Form dynamically by adding to the self.fields @@ -3637,6 +3656,23 @@ Password: self.assertIsInstance(field_copy, CustomCharField) self.assertIsNot(field_copy.error_messages, field.error_messages) + def test_label_does_not_include_new_line(self): + form = Person() + field = form['first_name'] + self.assertEqual( + field.label_tag(), + '', + ) + + @override_settings(USE_THOUSAND_SEPARATOR=True) + def test_label_attrs_not_localized(self): + form = Person() + field = form['first_name'] + self.assertHTMLEqual( + field.label_tag(attrs={'number': 9999}), + '', + ) + class CustomRenderer(DjangoTemplates): pass