mirror of
https://github.com/simonw/datasette.git
synced 2026-09-28 04:44:21 +02:00
Fix facet selection for explicit exact filters
`colname__exact=value` is now treated the same as `colname=value` when determining which facets are selected. Closes #1695
This commit is contained in:
parent
266eaddb73
commit
d2098e9f84
4 changed files with 91 additions and 2 deletions
|
|
@ -484,6 +484,31 @@ async def test_facet_display(ds_client):
|
|||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"filters", ["state=CA", "state__exact=CA", "state=CA&state__exact=CA"]
|
||||
)
|
||||
async def test_facet_remove_exact_filter(ds_client, filters):
|
||||
response = await ds_client.get(
|
||||
f"/fixtures/facetable?_facet=state&{filters}&on_earth=1"
|
||||
)
|
||||
assert response.status_code == 200
|
||||
soup = Soup(response.text, "html.parser")
|
||||
remove_link = soup.select_one('.facet-info[data-column="state"] li a.cross')
|
||||
assert remove_link is not None
|
||||
url = urllib.parse.urlsplit(remove_link["href"])
|
||||
assert urllib.parse.parse_qsl(url.query) == [
|
||||
("_facet", "state"),
|
||||
("on_earth", "1"),
|
||||
]
|
||||
unfiltered = await ds_client.get(f"{url.path}.json?{url.query}")
|
||||
assert unfiltered.status_code == 200
|
||||
rows = unfiltered.json()["rows"]
|
||||
assert len(rows) == 14
|
||||
assert all(row["on_earth"] == 1 for row in rows)
|
||||
assert {row["state"] for row in rows} == {"CA", "MI"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_facets_persist_through_filter_form(ds_client):
|
||||
response = await ds_client.get(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue