-
-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internals tests for datasette.client methods
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |