diff --git a/tests/plugins/my_plugin_2.py b/tests/plugins/my_plugin_2.py index ba298fd4..f5ce36b3 100644 --- a/tests/plugins/my_plugin_2.py +++ b/tests/plugins/my_plugin_2.py @@ -176,4 +176,12 @@ def register_routes(datasette): if not config: return path = config["path"] - return [(r"/{}/$".format(path), lambda: Response.text(path.upper()))] + + def new_table(request): + return Response.text("/db/table: {}".format(sorted(request.url_vars.items()))) + + return [ + (r"/{}/$".format(path), lambda: Response.text(path.upper())), + # Also serves to demonstrate over-ride of default paths: + (r"/(?P[^/]+)/(?P[^/]+?$)", new_table), + ] diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 7ac6b173..c9ff6edb 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -678,6 +678,25 @@ def test_hook_register_routes_with_datasette(configured_path): assert client.get(f"/{other_path}/", follow_redirects=True).status == 404 +def test_hook_register_routes_override(): + "Plugins can over-ride default paths such as /db/table" + with make_app_client( + metadata={ + "plugins": { + "register-route-demo": { + "path": "blah", + } + } + } + ) as client: + response = client.get("/db/table") + assert response.status == 200 + assert ( + response.text + == "/db/table: [('db_name', 'db'), ('table_and_format', 'table')]" + ) + + def test_hook_register_routes_post(app_client): response = app_client.post("/post/", {"this is": "post data"}, csrftoken_from=True) assert 200 == response.status