Default 405 for POST, plus tests

This commit is contained in:
Simon Willison 2021-06-23 15:27:30 -07:00
commit 4a3e8561ab
2 changed files with 10 additions and 0 deletions

View file

@ -106,6 +106,9 @@ class BaseView:
async def options(self, request, *args, **kwargs):
return Response.text("Method not allowed", status=405)
async def post(self, request, *args, **kwargs):
return Response.text("Method not allowed", status=405)
async def put(self, request, *args, **kwargs):
return Response.text("Method not allowed", status=405)

View file

@ -92,6 +92,13 @@ def test_memory_database_page():
assert response.status == 200
def test_not_allowed_methods():
with make_app_client(memory=True) as client:
for method in ("post", "put", "patch", "delete"):
response = client.request(path="/_memory", method=method.upper())
assert response.status == 405
def test_database_page_redirects_with_url_hash(app_client_with_hash):
response = app_client_with_hash.get("/fixtures", allow_redirects=False)
assert response.status == 302