mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Make custom pages compatible with base_url setting
Closes #1238 - base_url no longer causes custom page routing to fail - new route_path key in request.scope storing the path that was used for routing with the base_url prefix stripped - TestClient used by tests now avoids accidentally double processing of the base_url prefix
This commit is contained in:
parent
6e9b07be92
commit
a634121525
4 changed files with 27 additions and 8 deletions
|
|
@ -2,11 +2,19 @@ import pathlib
|
|||
import pytest
|
||||
from .fixtures import make_app_client
|
||||
|
||||
TEST_TEMPLATE_DIRS = str(pathlib.Path(__file__).parent / "test_templates")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def custom_pages_client():
|
||||
with make_app_client(template_dir=TEST_TEMPLATE_DIRS) as client:
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def custom_pages_client_with_base_url():
|
||||
with make_app_client(
|
||||
template_dir=str(pathlib.Path(__file__).parent / "test_templates")
|
||||
template_dir=TEST_TEMPLATE_DIRS, config={"base_url": "/prefix/"}
|
||||
) as client:
|
||||
yield client
|
||||
|
||||
|
|
@ -23,6 +31,12 @@ def test_request_is_available(custom_pages_client):
|
|||
assert "path:/request" == response.text
|
||||
|
||||
|
||||
def test_custom_pages_with_base_url(custom_pages_client_with_base_url):
|
||||
response = custom_pages_client_with_base_url.get("/prefix/request")
|
||||
assert 200 == response.status
|
||||
assert "path:/prefix/request" == response.text
|
||||
|
||||
|
||||
def test_custom_pages_nested(custom_pages_client):
|
||||
response = custom_pages_client.get("/nested/nest")
|
||||
assert 200 == response.status
|
||||
|
|
|
|||
|
|
@ -1523,6 +1523,7 @@ def test_base_url_config(app_client_base_url_prefix, path):
|
|||
and href
|
||||
not in {
|
||||
"https://datasette.io/",
|
||||
"https://github.com/simonw/datasette",
|
||||
"https://github.com/simonw/datasette/blob/main/LICENSE",
|
||||
"https://github.com/simonw/datasette/blob/main/tests/fixtures.py",
|
||||
"/login-as-root", # Only used for the latest.datasette.io demo
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue