mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
51d7881140
commit
7e983fede6
5 changed files with 86 additions and 13 deletions
|
|
@ -129,16 +129,16 @@ def make_app_client(
|
|||
files.append(extra_filepath)
|
||||
os.chdir(os.path.dirname(filepath))
|
||||
config = config or {}
|
||||
config.update(
|
||||
{
|
||||
"default_page_size": 50,
|
||||
"max_returned_rows": max_returned_rows or 100,
|
||||
"sql_time_limit_ms": sql_time_limit_ms or 200,
|
||||
# Default is 3 but this results in "too many open files"
|
||||
# errors when running the full test suite:
|
||||
"num_sql_threads": 1,
|
||||
}
|
||||
)
|
||||
for key, value in {
|
||||
"default_page_size": 50,
|
||||
"max_returned_rows": max_returned_rows or 100,
|
||||
"sql_time_limit_ms": sql_time_limit_ms or 200,
|
||||
# Default is 3 but this results in "too many open files"
|
||||
# errors when running the full test suite:
|
||||
"num_sql_threads": 1,
|
||||
}.items():
|
||||
if key not in config:
|
||||
config[key] = value
|
||||
ds = Datasette(
|
||||
files,
|
||||
immutables=immutables,
|
||||
|
|
|
|||
|
|
@ -1612,3 +1612,65 @@ def test_navigation_menu_links(
|
|||
assert (
|
||||
details.find("a", {"href": link}) is None
|
||||
), f"{link} found but should not have been in nav menu"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"max_returned_rows,path,expected_num_facets,expected_ellipses,expected_ellipses_url",
|
||||
(
|
||||
(
|
||||
5,
|
||||
# Default should show 2 facets
|
||||
"/fixtures/facetable?_facet=neighborhood",
|
||||
2,
|
||||
True,
|
||||
"/fixtures/facetable?_facet=neighborhood&_facet_size=max",
|
||||
),
|
||||
# _facet_size above max_returned_rows should show max_returned_rows (5)
|
||||
(
|
||||
5,
|
||||
"/fixtures/facetable?_facet=neighborhood&_facet_size=50",
|
||||
5,
|
||||
True,
|
||||
"/fixtures/facetable?_facet=neighborhood&_facet_size=max",
|
||||
),
|
||||
# If max_returned_rows is high enough, should return all
|
||||
(
|
||||
20,
|
||||
"/fixtures/facetable?_facet=neighborhood&_facet_size=max",
|
||||
14,
|
||||
False,
|
||||
None,
|
||||
),
|
||||
# If num facets > max_returned_rows, show ... without a link
|
||||
# _facet_size above max_returned_rows should show max_returned_rows (5)
|
||||
(
|
||||
5,
|
||||
"/fixtures/facetable?_facet=neighborhood&_facet_size=max",
|
||||
5,
|
||||
True,
|
||||
None,
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_facet_more_links(
|
||||
max_returned_rows,
|
||||
path,
|
||||
expected_num_facets,
|
||||
expected_ellipses,
|
||||
expected_ellipses_url,
|
||||
):
|
||||
with make_app_client(
|
||||
config={"max_returned_rows": max_returned_rows, "default_facet_size": 2}
|
||||
) as client:
|
||||
response = client.get(path)
|
||||
soup = Soup(response.body, "html.parser")
|
||||
lis = soup.select("#facet-neighborhood ul li:not(.facet-truncated)")
|
||||
facet_truncated = soup.select_one(".facet-truncated")
|
||||
assert len(lis) == expected_num_facets
|
||||
if not expected_ellipses:
|
||||
assert facet_truncated is None
|
||||
else:
|
||||
if expected_ellipses_url:
|
||||
assert facet_truncated.find("a")["href"] == expected_ellipses_url
|
||||
else:
|
||||
assert facet_truncated.find("a") is None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue