Skip to content

Commit

Permalink
Display 500 error page for POST requests
Browse files Browse the repository at this point in the history
  • Loading branch information
brmzkw committed Feb 29, 2024
1 parent 54248e4 commit 6e5ab1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mesads/app/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from freezegun import freeze_time

from mesads.app.views import HTTP500View
from mesads.fradm.models import Commune, EPCI, Prefecture

from .models import (
Expand All @@ -24,6 +25,18 @@
from .views import DashboardsView, DashboardsDetailView


class TestHTTP500View(ClientTestCase):
def test_500(self):
request = RequestFactory().get("/500")
response = HTTP500View.as_view()(request)
self.assertEqual(response.status_code, 200)

# POST requests should be allowed
request = RequestFactory().post("/500")
response = HTTP500View.as_view()(request)
self.assertEqual(response.status_code, 200)


class TestHomepageView(ClientTestCase):
def test_200(self):
resp = self.anonymous_client.get("/")
Expand Down
5 changes: 5 additions & 0 deletions mesads/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class HTTP500View(TemplateView):

template_name = "500.html"

def dispatch(self, request, *args, **kwargs):
"""The base class TemplateView only accepts GET requests. By overriding
dispatch, we return the error page for any other method."""
return super().get(request, *args, **kwargs)


class HomepageView(TemplateView):
template_name = "pages/homepage.html"
Expand Down

0 comments on commit 6e5ab1d

Please sign in to comment.