kopia lustrzana https://github.com/simonw/datasette
Don't use pytest_asyncio.fixture(scope="session") any more, refs #1959
Also got rid of the weird memory=False hack: https://github.com/simonw/datasette/pull/1960#issuecomment-1354053151pull/1965/head
rodzic
95900b9d02
commit
d94d363ec0
|
@ -281,7 +281,7 @@ class Datasette:
|
|||
raise
|
||||
self.crossdb = crossdb
|
||||
self.nolock = nolock
|
||||
if memory or crossdb or (not self.files and memory is not False):
|
||||
if memory or crossdb or not self.files:
|
||||
self.add_database(
|
||||
Database(self, is_mutable=False, is_memory=True), name="_memory"
|
||||
)
|
||||
|
|
|
@ -25,18 +25,12 @@ UNDOCUMENTED_PERMISSIONS = {
|
|||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def event_loop():
|
||||
return asyncio.get_event_loop()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest_asyncio.fixture
|
||||
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={
|
||||
|
@ -51,12 +45,14 @@ async def ds_client():
|
|||
from .fixtures import TABLES, TABLE_PARAMETERIZED_SQL
|
||||
|
||||
db = ds.add_memory_database("fixtures")
|
||||
ds.remove_database("_memory")
|
||||
|
||||
def prepare(conn):
|
||||
conn.executescript(TABLES)
|
||||
for sql, params in TABLE_PARAMETERIZED_SQL:
|
||||
with conn:
|
||||
conn.execute(sql, params)
|
||||
if not conn.execute("select count(*) from sqlite_master").fetchone()[0]:
|
||||
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
|
||||
|
|
|
@ -117,7 +117,12 @@ def actor_from_request(datasette, request):
|
|||
def permission_allowed(datasette, actor, action):
|
||||
# Testing asyncio version of permission_allowed
|
||||
async def inner():
|
||||
assert 2 == (await datasette.get_database().execute("select 1 + 1")).first()[0]
|
||||
assert (
|
||||
2
|
||||
== (
|
||||
await datasette.get_database("_internal").execute("select 1 + 1")
|
||||
).first()[0]
|
||||
)
|
||||
if action == "this_is_allowed_async":
|
||||
return True
|
||||
elif action == "this_is_denied_async":
|
||||
|
|
Ładowanie…
Reference in New Issue