mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
datasette.client internal requests mechanism
Closes #943 * Datasette now requires httpx>=0.15 * Support OPTIONS without 500, closes #1001 * Added internals tests for datasette.client methods * Datasette's own test mechanism now uses httpx to simulate requests * Tests simulate HTTP 1.1 now * Added base_url in a bunch more places * Mark some tests as xfail - will remove that when new httpx release ships: #1005
This commit is contained in:
parent
7249ac5ca0
commit
8f97b9b58e
18 changed files with 163 additions and 100 deletions
44
tests/test_internals_datasette_client.py
Normal file
44
tests/test_internals_datasette_client.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
from .fixtures import app_client
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def datasette(app_client):
|
||||
return app_client.ds
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"method,path,expected_status",
|
||||
[
|
||||
("get", "/", 200),
|
||||
("options", "/", 405),
|
||||
("head", "/", 200),
|
||||
("put", "/", 405),
|
||||
("patch", "/", 405),
|
||||
("delete", "/", 405),
|
||||
],
|
||||
)
|
||||
async def test_client_methods(datasette, method, path, expected_status):
|
||||
client_method = getattr(datasette.client, method)
|
||||
response = await client_method(path)
|
||||
assert isinstance(response, httpx.Response)
|
||||
assert response.status_code == expected_status
|
||||
# Try that again using datasette.client.request
|
||||
response2 = await datasette.client.request(method, path)
|
||||
assert response2.status_code == expected_status
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_client_post(datasette):
|
||||
response = await datasette.client.post(
|
||||
"/-/messages",
|
||||
data={
|
||||
"message": "A message",
|
||||
},
|
||||
allow_redirects=False,
|
||||
)
|
||||
assert isinstance(response, httpx.Response)
|
||||
assert response.status_code == 302
|
||||
assert "ds_messages" in response.cookies
|
||||
Loading…
Add table
Add a link
Reference in a new issue