mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
static_mounts mechanism works again, refs #272
This commit is contained in:
parent
8a1a15d725
commit
eb06e59332
3 changed files with 15 additions and 2 deletions
|
|
@ -600,8 +600,8 @@ class Datasette:
|
|||
add_route(
|
||||
asgi_static(app_root / "datasette" / "static"), r"/-/static/(?P<path>.*)$"
|
||||
)
|
||||
# for path, dirname in self.static_mounts:
|
||||
# app.static(path, dirname)
|
||||
for path, dirname in self.static_mounts:
|
||||
add_route(asgi_static(dirname), r"/" + path + "/(?P<path>.*)$")
|
||||
|
||||
# Mount any plugin static/ directories
|
||||
for plugin in get_plugins(pm):
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ def make_app_client(
|
|||
is_immutable=False,
|
||||
extra_databases=None,
|
||||
inspect_data=None,
|
||||
static_mounts=None,
|
||||
):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
filepath = os.path.join(tmpdir, filename)
|
||||
|
|
@ -123,6 +124,7 @@ def make_app_client(
|
|||
plugins_dir=plugins_dir,
|
||||
config=config,
|
||||
inspect_data=inspect_data,
|
||||
static_mounts=static_mounts,
|
||||
)
|
||||
ds.sqlite_functions.append(("sleep", 1, lambda n: time.sleep(float(n))))
|
||||
client = TestClient(ds.app())
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from .fixtures import ( # noqa
|
|||
METADATA,
|
||||
)
|
||||
import json
|
||||
import pathlib
|
||||
import pytest
|
||||
import re
|
||||
import urllib.parse
|
||||
|
|
@ -52,6 +53,16 @@ def test_static(app_client):
|
|||
assert "text/css" == response.headers["content-type"]
|
||||
|
||||
|
||||
def test_static_mounts():
|
||||
for client in make_app_client(
|
||||
static_mounts=[("custom-static", str(pathlib.Path(__file__).parent))]
|
||||
):
|
||||
response = client.get("/custom-static/test_html.py")
|
||||
assert response.status == 200
|
||||
response = client.get("/custom-static/not_exists.py")
|
||||
assert response.status == 404
|
||||
|
||||
|
||||
def test_memory_database_page():
|
||||
for client in make_app_client(memory=True):
|
||||
response = client.get("/:memory:")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue