New "startup" plugin hook, closes #834

This commit is contained in:
Simon Willison 2020-06-13 10:55:41 -07:00
commit 09a3479a54
8 changed files with 61 additions and 0 deletions

View file

@ -49,6 +49,7 @@ EXPECTED_PLUGINS = [
"register_facet_classes",
"register_routes",
"render_cell",
"startup",
],
},
{

View file

@ -167,3 +167,8 @@ def register_routes():
(r"/two/(?P<name>.*)$", two),
(r"/three/$", three),
]
@hookimpl
def startup(datasette):
datasette._startup_hook_fired = True

View file

@ -10,6 +10,7 @@ from click.testing import CliRunner
import io
import json
import pathlib
import pytest
import textwrap

View file

@ -572,3 +572,9 @@ def test_register_routes_asgi(app_client):
response = app_client.get("/three/")
assert {"hello": "world"} == response.json
assert "1" == response.headers["x-three"]
@pytest.mark.asyncio
async def test_startup(app_client):
await app_client.ds.invoke_startup()
assert app_client.ds._startup_hook_fired