mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Test confirming plugins can over-ride default routes, closes #1517
This commit is contained in:
parent
0156c6b5e5
commit
6e971b4ac1
2 changed files with 28 additions and 1 deletions
|
|
@ -176,4 +176,12 @@ def register_routes(datasette):
|
||||||
if not config:
|
if not config:
|
||||||
return
|
return
|
||||||
path = config["path"]
|
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<db_name>[^/]+)/(?P<table_and_format>[^/]+?$)", new_table),
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -678,6 +678,25 @@ def test_hook_register_routes_with_datasette(configured_path):
|
||||||
assert client.get(f"/{other_path}/", follow_redirects=True).status == 404
|
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):
|
def test_hook_register_routes_post(app_client):
|
||||||
response = app_client.post("/post/", {"this is": "post data"}, csrftoken_from=True)
|
response = app_client.post("/post/", {"this is": "post data"}, csrftoken_from=True)
|
||||||
assert 200 == response.status
|
assert 200 == response.status
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue