mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
base_url configuration setting, closes #394
* base_url configuration setting * base_url works for static assets as well
This commit is contained in:
parent
2a36dfa2a8
commit
7656fd64d8
15 changed files with 104 additions and 28 deletions
|
|
@ -1157,3 +1157,46 @@ def test_metadata_sort_desc(app_client):
|
|||
table = Soup(response.body, "html.parser").find("table")
|
||||
rows = [[str(td) for td in tr.select("td")] for tr in table.select("tbody tr")]
|
||||
assert list(reversed(expected)) == rows
|
||||
|
||||
|
||||
@pytest.mark.parametrize("base_url", ["/prefix/", "https://example.com/"])
|
||||
@pytest.mark.parametrize(
|
||||
"path",
|
||||
[
|
||||
"/",
|
||||
"/fixtures",
|
||||
"/fixtures/compound_three_primary_keys",
|
||||
"/fixtures/compound_three_primary_keys/a,a,a",
|
||||
"/fixtures/paginated_view",
|
||||
],
|
||||
)
|
||||
def test_base_url_config(base_url, path):
|
||||
for client in make_app_client(config={"base_url": base_url}):
|
||||
response = client.get(base_url + path.lstrip("/"))
|
||||
soup = Soup(response.body, "html.parser")
|
||||
for el in soup.findAll(["a", "link", "script"]):
|
||||
if "href" in el.attrs:
|
||||
href = el["href"]
|
||||
elif "src" in el.attrs:
|
||||
href = el["src"]
|
||||
else:
|
||||
continue # Could be a <script>...</script>
|
||||
if (
|
||||
not href.startswith("#")
|
||||
and href
|
||||
not in {
|
||||
"https://github.com/simonw/datasette",
|
||||
"https://github.com/simonw/datasette/blob/master/LICENSE",
|
||||
"https://github.com/simonw/datasette/blob/master/tests/fixtures.py",
|
||||
}
|
||||
and not href.startswith("https://plugin-example.com/")
|
||||
):
|
||||
# If this has been made absolute it may start http://localhost/
|
||||
if href.startswith("http://localhost/"):
|
||||
href = href[len("http://localost/") :]
|
||||
assert href.startswith(base_url), {
|
||||
"base_url": base_url,
|
||||
"path": path,
|
||||
"href_or_src": href,
|
||||
"element_parent": str(el.parent),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue