Added test for async startup hook, refs #834

This commit is contained in:
Simon Willison 2020-06-13 10:58:32 -07:00
commit 72ae975156
2 changed files with 9 additions and 0 deletions

View file

@ -120,3 +120,11 @@ def permission_allowed(datasette, actor, action):
return False
return inner
@hookimpl
def startup(datasette):
async def inner():
result = await datasette.get_database().execute("select 1 + 1")
datasette._startup_hook_calculation = result.first()[0]
return inner

View file

@ -578,3 +578,4 @@ def test_register_routes_asgi(app_client):
async def test_startup(app_client):
await app_client.ds.invoke_startup()
assert app_client.ds._startup_hook_fired
assert 2 == app_client.ds._startup_hook_calculation