mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
405 method not allowed for GET to POST endpoints, closes #1916
This commit is contained in:
parent
5518397338
commit
8404b21556
2 changed files with 26 additions and 1 deletions
|
|
@ -69,7 +69,6 @@ class BaseView:
|
||||||
return "ff0000"
|
return "ff0000"
|
||||||
|
|
||||||
async def method_not_allowed(self, request):
|
async def method_not_allowed(self, request):
|
||||||
print(request.headers)
|
|
||||||
if (
|
if (
|
||||||
request.path.endswith(".json")
|
request.path.endswith(".json")
|
||||||
or request.headers.get("content-type") == "application/json"
|
or request.headers.get("content-type") == "application/json"
|
||||||
|
|
@ -82,6 +81,9 @@ class BaseView:
|
||||||
async def options(self, request, *args, **kwargs):
|
async def options(self, request, *args, **kwargs):
|
||||||
return await self.method_not_allowed(request)
|
return await self.method_not_allowed(request)
|
||||||
|
|
||||||
|
async def get(self, request, *args, **kwargs):
|
||||||
|
return await self.method_not_allowed(request)
|
||||||
|
|
||||||
async def post(self, request, *args, **kwargs):
|
async def post(self, request, *args, **kwargs):
|
||||||
return await self.method_not_allowed(request)
|
return await self.method_not_allowed(request)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -922,3 +922,26 @@ async def test_create_table(ds_write, input, expected_status, expected_response)
|
||||||
assert response.status_code == expected_status
|
assert response.status_code == expected_status
|
||||||
data = response.json()
|
data = response.json()
|
||||||
assert data == expected_response
|
assert data == expected_response
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"path",
|
||||||
|
(
|
||||||
|
"/data/-/create",
|
||||||
|
"/data/docs/-/drop",
|
||||||
|
"/data/docs/-/insert",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
async def test_method_not_allowed(ds_write, path):
|
||||||
|
response = await ds_write.client.get(
|
||||||
|
path,
|
||||||
|
headers={
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert response.status_code == 405
|
||||||
|
assert response.json() == {
|
||||||
|
"ok": False,
|
||||||
|
"error": "Method not allowed",
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue