kopia lustrzana https://github.com/simonw/datasette
New app_client_base_url_prefix fixture
rodzic
d3e9b0aecb
commit
29a977a74e
|
@ -159,6 +159,12 @@ def app_client_no_files():
|
||||||
yield TestClient(ds)
|
yield TestClient(ds)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session")
|
||||||
|
def app_client_base_url_prefix():
|
||||||
|
with make_app_client(config={"base_url": "/prefix/"}) as client:
|
||||||
|
yield client
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def app_client_two_attached_databases():
|
def app_client_two_attached_databases():
|
||||||
with make_app_client(
|
with make_app_client(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from bs4 import BeautifulSoup as Soup
|
from bs4 import BeautifulSoup as Soup
|
||||||
from .fixtures import ( # noqa
|
from .fixtures import ( # noqa
|
||||||
app_client,
|
app_client,
|
||||||
|
app_client_base_url_prefix,
|
||||||
app_client_shorter_time_limit,
|
app_client_shorter_time_limit,
|
||||||
app_client_two_attached_databases,
|
app_client_two_attached_databases,
|
||||||
app_client_with_hash,
|
app_client_with_hash,
|
||||||
|
@ -1371,37 +1372,35 @@ def test_metadata_sort_desc(app_client):
|
||||||
"/fixtures/facetable",
|
"/fixtures/facetable",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_base_url_config(path):
|
def test_base_url_config(app_client_base_url_prefix, path):
|
||||||
base_url = "/prefix/"
|
client = app_client_base_url_prefix
|
||||||
with make_app_client(config={"base_url": base_url}) as client:
|
response = client.get("/prefix/" + path.lstrip("/"))
|
||||||
response = client.get(base_url + path.lstrip("/"))
|
soup = Soup(response.body, "html.parser")
|
||||||
soup = Soup(response.body, "html.parser")
|
for el in soup.findAll(["a", "link", "script"]):
|
||||||
for el in soup.findAll(["a", "link", "script"]):
|
if "href" in el.attrs:
|
||||||
if "href" in el.attrs:
|
href = el["href"]
|
||||||
href = el["href"]
|
elif "src" in el.attrs:
|
||||||
elif "src" in el.attrs:
|
href = el["src"]
|
||||||
href = el["src"]
|
else:
|
||||||
else:
|
continue # Could be a <script>...</script>
|
||||||
continue # Could be a <script>...</script>
|
if (
|
||||||
if (
|
not href.startswith("#")
|
||||||
not href.startswith("#")
|
and href
|
||||||
and href
|
not in {
|
||||||
not in {
|
"https://github.com/simonw/datasette",
|
||||||
"https://github.com/simonw/datasette",
|
"https://github.com/simonw/datasette/blob/master/LICENSE",
|
||||||
"https://github.com/simonw/datasette/blob/master/LICENSE",
|
"https://github.com/simonw/datasette/blob/master/tests/fixtures.py",
|
||||||
"https://github.com/simonw/datasette/blob/master/tests/fixtures.py",
|
}
|
||||||
}
|
and not href.startswith("https://plugin-example.com/")
|
||||||
and not href.startswith("https://plugin-example.com/")
|
):
|
||||||
):
|
# If this has been made absolute it may start http://localhost/
|
||||||
# If this has been made absolute it may start http://localhost/
|
if href.startswith("http://localhost/"):
|
||||||
if href.startswith("http://localhost/"):
|
href = href[len("http://localost/") :]
|
||||||
href = href[len("http://localost/") :]
|
assert href.startswith("/prefix/"), {
|
||||||
assert href.startswith(base_url), {
|
"path": path,
|
||||||
"base_url": base_url,
|
"href_or_src": href,
|
||||||
"path": path,
|
"element_parent": str(el.parent),
|
||||||
"href_or_src": href,
|
}
|
||||||
"element_parent": str(el.parent),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
Ładowanie…
Reference in New Issue