New app_client_base_url_prefix fixture

This commit is contained in:
Simon Willison 2020-10-24 12:03:24 -07:00
commit 29a977a74e
2 changed files with 36 additions and 31 deletions

View file

@ -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(

View file

@ -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,10 +1372,9 @@ 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:
@ -1396,8 +1396,7 @@ def test_base_url_config(path):
# 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(base_url), { assert href.startswith("/prefix/"), {
"base_url": base_url,
"path": path, "path": path,
"href_or_src": href, "href_or_src": href,
"element_parent": str(el.parent), "element_parent": str(el.parent),