From cd4252cd64ef4492615114b51c1e006263466e3e Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 19 Aug 2022 15:07:59 +0100 Subject: [PATCH] Return 200 when viewing the dedicated 404 page --- website/common/tests/test_views.py | 10 ++++++++-- website/common/views.py | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/website/common/tests/test_views.py b/website/common/tests/test_views.py index 238adf5..6a80a99 100644 --- a/website/common/tests/test_views.py +++ b/website/common/tests/test_views.py @@ -7,10 +7,16 @@ class Error404PageTestCase(TestCase): def test_accessible(self) -> None: response = self.client.get(self.url) - self.assertEqual(response.status_code, 404) + self.assertContains(response, "

There's nothing here!

", html=True) + + def test_actual_404(self) -> None: + response = self.client.get("/does-not-exist/") + self.assertContains( + response, "

There's nothing here!

", html=True, status_code=404 + ) def test_queries(self) -> None: - with self.assertNumQueries(10): + with self.assertNumQueries(8): self.client.get(self.url) diff --git a/website/common/views.py b/website/common/views.py index cc739e2..77037ec 100644 --- a/website/common/views.py +++ b/website/common/views.py @@ -15,7 +15,8 @@ class Error404View(TemplateView): template_name = ERROR_404_TEMPLATE_NAME def render_to_response(self, context: dict, **response_kwargs: Any) -> HttpResponse: - response_kwargs["status"] = 404 + if self.request.resolver_match.url_name != "404": + response_kwargs["status"] = 404 return super().render_to_response(context, **response_kwargs) def get_context_data(self, **kwargs: dict) -> dict: