1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #33236 -- Fixed assertHTMLEqual() error messages for escaped HTML.

This commit is contained in:
Pratyush Mittal
2021-10-28 23:45:01 +05:30
committed by Mariusz Felisiak
parent 073b7b5915
commit f38458fe56
2 changed files with 25 additions and 3 deletions

View File

@@ -868,6 +868,11 @@ class HTMLEqualTests(SimpleTestCase):
dom2 = parse_html('<a><b/><b/></a><b/><b/>')
self.assertEqual(dom2.count(dom1), 2)
def test_root_element_escaped_html(self):
html = '&lt;br&gt;'
parsed = parse_html(html)
self.assertEqual(str(parsed), html)
def test_parsing_errors(self):
with self.assertRaises(AssertionError):
self.assertHTMLEqual('<p>', '')
@@ -882,6 +887,17 @@ class HTMLEqualTests(SimpleTestCase):
with self.assertRaises(HTMLParseError):
parse_html('</p>')
def test_escaped_html_errors(self):
msg = (
'<p>\n<foo>\n</p>'
' != '
'<p>\n&lt;foo&gt;\n</p>\n'
)
with self.assertRaisesMessage(AssertionError, msg):
self.assertHTMLEqual('<p><foo></p>', '<p>&lt;foo&gt;</p>')
with self.assertRaisesMessage(AssertionError, msg):
self.assertHTMLEqual('<p><foo></p>', '<p>&#60;foo&#62;</p>')
def test_contains_html(self):
response = HttpResponse('''<body>
This is a form: <form method="get">