A bunch of remaining ds_client conversions, refs #1959

pull/1965/head
Simon Willison 2022-12-16 09:44:30 -08:00
rodzic be95359a80
commit 42a66c2f04
5 zmienionych plików z 17 dodań i 14 usunięć

Wyświetl plik

@ -1010,6 +1010,7 @@ async def test_http_options_request(ds_client):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_db_path(app_client): async def test_db_path(app_client):
# Needs app_client because needs file based database
db = app_client.ds.get_database() db = app_client.ds.get_database()
path = pathlib.Path(db.path) path = pathlib.Path(db.path)

Wyświetl plik

@ -485,6 +485,7 @@ def test_database_download_for_immutable():
def test_database_download_disallowed_for_mutable(app_client): def test_database_download_disallowed_for_mutable(app_client):
# Use app_client because we need a file database, not in-memory
response = app_client.get("/fixtures") response = app_client.get("/fixtures")
soup = Soup(response.content, "html.parser") soup = Soup(response.content, "html.parser")
assert len(soup.findAll("a", {"href": re.compile(r"\.db$")})) == 0 assert len(soup.findAll("a", {"href": re.compile(r"\.db$")})) == 0

Wyświetl plik

@ -4,13 +4,12 @@ Tests for the datasette.app.Datasette class
from datasette import Forbidden from datasette import Forbidden
from datasette.app import Datasette, Database from datasette.app import Datasette, Database
from itsdangerous import BadSignature from itsdangerous import BadSignature
from .fixtures import app_client
import pytest import pytest
@pytest.fixture @pytest.fixture
def datasette(app_client): def datasette(ds_client):
return app_client.ds return ds_client.ds
def test_get_database(datasette): def test_get_database(datasette):

Wyświetl plik

@ -1,13 +1,12 @@
from .fixtures import app_client
import httpx import httpx
import pytest import pytest
import pytest_asyncio import pytest_asyncio
@pytest_asyncio.fixture @pytest_asyncio.fixture
async def datasette(app_client): async def datasette(ds_client):
await app_client.ds.invoke_startup() await ds_client.ds.invoke_startup()
return app_client.ds return ds_client.ds
@pytest.mark.asyncio @pytest.mark.asyncio

Wyświetl plik

@ -1,8 +1,9 @@
from .fixtures import app_client
from .utils import cookie_was_deleted from .utils import cookie_was_deleted
import pytest import pytest
@pytest.mark.ds_client
@pytest.mark.asyncio
@pytest.mark.parametrize( @pytest.mark.parametrize(
"qs,expected", "qs,expected",
[ [
@ -11,18 +12,20 @@ import pytest
("add_msg=added-error&type=ERROR", [["added-error", 3]]), ("add_msg=added-error&type=ERROR", [["added-error", 3]]),
], ],
) )
def test_add_message_sets_cookie(app_client, qs, expected): async def test_add_message_sets_cookie(ds_client, qs, expected):
response = app_client.get(f"/fixtures.message?{qs}") response = await ds_client.get(f"/fixtures.message?{qs}")
signed = response.cookies["ds_messages"] signed = response.cookies["ds_messages"]
decoded = app_client.ds.unsign(signed, "messages") decoded = ds_client.ds.unsign(signed, "messages")
assert expected == decoded assert expected == decoded
def test_messages_are_displayed_and_cleared(app_client): @pytest.mark.ds_client
@pytest.mark.asyncio
async def test_messages_are_displayed_and_cleared(ds_client):
# First set the message cookie # First set the message cookie
set_msg_response = app_client.get("/fixtures.message?add_msg=xmessagex") set_msg_response = await ds_client.get("/fixtures.message?add_msg=xmessagex")
# Now access a page that displays messages # Now access a page that displays messages
response = app_client.get("/", cookies=set_msg_response.cookies) response = await ds_client.get("/", cookies=set_msg_response.cookies)
# Messages should be in that HTML # Messages should be in that HTML
assert "xmessagex" in response.text assert "xmessagex" in response.text
# Cookie should have been set that clears messages # Cookie should have been set that clears messages