1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #30521 -- Fixed invalid HTML in default error pages.

This commit is contained in:
Alexandre Varas
2019-06-05 20:12:21 +02:00
committed by Mariusz Felisiak
parent 3fb0a1a67f
commit c498f088c5
2 changed files with 44 additions and 7 deletions

View File

@@ -81,8 +81,7 @@ class DefaultsTests(TestCase):
def test_bad_request(self):
request = self.request_factory.get('/')
response = bad_request(request, Exception())
self.assertEqual(response.status_code, 400)
self.assertEqual(response.content, b'<h1>Bad Request (400)</h1>')
self.assertContains(response, b'<h1>Bad Request (400)</h1>', status_code=400)
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
@@ -134,3 +133,18 @@ class DefaultsTests(TestCase):
with self.assertRaises(TemplateDoesNotExist):
server_error(request, template_name='nonexistent')
def test_error_pages(self):
request = self.request_factory.get('/')
for response, title in (
(bad_request(request, Exception()), b'Bad Request (400)'),
(permission_denied(request, Exception()), b'403 Forbidden'),
(page_not_found(request, Http404()), b'Not Found'),
(server_error(request), b'Server Error (500)'),
):
with self.subTest(title=title):
self.assertIn(b'<!doctype html>', response.content)
self.assertIn(b'<html lang="en">', response.content)
self.assertIn(b'<head>', response.content)
self.assertIn(b'<title>%s</title>' % title, response.content)
self.assertIn(b'<body>', response.content)