From 72ae975156a09619a808cdd03fddddcf62e6f533 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 13 Jun 2020 10:58:32 -0700 Subject: [PATCH] Added test for async startup hook, refs #834 --- tests/plugins/my_plugin_2.py | 8 ++++++++ tests/test_plugins.py | 1 + 2 files changed, 9 insertions(+) diff --git a/tests/plugins/my_plugin_2.py b/tests/plugins/my_plugin_2.py index 039112f4..bdfaea8d 100644 --- a/tests/plugins/my_plugin_2.py +++ b/tests/plugins/my_plugin_2.py @@ -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 diff --git a/tests/test_plugins.py b/tests/test_plugins.py index c0a7438f..bc759385 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -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