mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Ported test_api.py app_client test to ds_client, refs #1959
This commit is contained in:
parent
5ee954e34b
commit
b077e63dc6
4 changed files with 156 additions and 80 deletions
|
|
@ -1,7 +1,9 @@
|
|||
import asyncio
|
||||
import httpx
|
||||
import os
|
||||
import pathlib
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
|
@ -23,6 +25,43 @@ UNDOCUMENTED_PERMISSIONS = {
|
|||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def event_loop():
|
||||
return asyncio.get_event_loop()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
async def ds_client():
|
||||
from datasette.app import Datasette
|
||||
from .fixtures import METADATA, PLUGINS_DIR
|
||||
|
||||
ds = Datasette(
|
||||
memory=False,
|
||||
metadata=METADATA,
|
||||
plugins_dir=PLUGINS_DIR,
|
||||
settings={
|
||||
"default_page_size": 50,
|
||||
"max_returned_rows": 100,
|
||||
"sql_time_limit_ms": 200,
|
||||
# Default is 3 but this results in "too many open files"
|
||||
# errors when running the full test suite:
|
||||
"num_sql_threads": 1,
|
||||
},
|
||||
)
|
||||
from .fixtures import TABLES, TABLE_PARAMETERIZED_SQL
|
||||
|
||||
db = ds.add_memory_database("fixtures")
|
||||
|
||||
def prepare(conn):
|
||||
conn.executescript(TABLES)
|
||||
for sql, params in TABLE_PARAMETERIZED_SQL:
|
||||
with conn:
|
||||
conn.execute(sql, params)
|
||||
|
||||
await db.execute_write_fn(prepare)
|
||||
return ds.client
|
||||
|
||||
|
||||
def pytest_report_header(config):
|
||||
return "SQLite: {}".format(
|
||||
sqlite3.connect(":memory:").execute("select sqlite_version()").fetchone()[0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue