diff options
author | David Smith <smithdc@gmail.com> | 2021-09-10 08:04:05 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-09-17 09:21:10 +0200 |
commit | 4ca508a68916dd43da45fd6e8b9004824a62d9c8 (patch) | |
tree | 4413f3468eb6d2013500c588307d4bf284defc9c | |
parent | 91e8b95d5ba8e296148ba6e2a1c856319c6e6ebc (diff) | |
download | django-4ca508a68916dd43da45fd6e8b9004824a62d9c8.tar.gz |
Refs #31026 -- Added extra form render tests.
-rw-r--r-- | tests/forms_tests/tests/test_forms.py | 36 |
1 files changed, 36 insertions, 0 deletions
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(), + '<tr><td colspan="2"><ul class="errorlist nonfield"><li>Form error</li>' + '<li>(Hidden field hidden_input) This field is required.</li></ul>' + '<input type="hidden" name="hidden_input" id="id_hidden_input"></td></tr>', + ) + self.assertHTMLEqual( + f.as_ul(), + '<li><ul class="errorlist nonfield"><li>Form error</li>' + '<li>(Hidden field hidden_input) This field is required.</li></ul>' + '<input type="hidden" name="hidden_input" id="id_hidden_input"></li>', + ) + self.assertHTMLEqual( + f.as_p(), + '<ul class="errorlist nonfield"><li>Form error</li>' + '<li>(Hidden field hidden_input) This field is required.</li></ul>' + '<p><input type="hidden" name="hidden_input" id="id_hidden_input"></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: <input type="password" name="password" required> 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(), + '<label for="id_first_name">First name:</label>', + ) + + @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}), + '<label number="9999" for="id_first_name">First name:</label>', + ) + class CustomRenderer(DjangoTemplates): pass |