Reset _metadata_local in a couple of tests

Refs https://github.com/simonw/datasette/pull/1960#issuecomment-1356476886
This commit is contained in:
Simon Willison 2022-12-17 13:40:27 -08:00
commit 89cffcf14c
2 changed files with 44 additions and 34 deletions

View file

@ -582,22 +582,28 @@ async def test_facet_size():
data5 = response5.json()
assert len(data5["facet_results"]["city"]["results"]) == 20
# Now try messing with facet_size in the table metadata
ds._metadata_local = {
"databases": {
"test_facet_size": {"tables": {"neighbourhoods": {"facet_size": 6}}}
orig_metadata = ds._metadata_local
try:
ds._metadata_local = {
"databases": {
"test_facet_size": {"tables": {"neighbourhoods": {"facet_size": 6}}}
}
}
}
response6 = await ds.client.get("/test_facet_size/neighbourhoods.json?_facet=city")
data6 = response6.json()
assert len(data6["facet_results"]["city"]["results"]) == 6
# Setting it to max bumps it up to 50 again
ds._metadata_local["databases"]["test_facet_size"]["tables"]["neighbourhoods"][
"facet_size"
] = "max"
data7 = (
await ds.client.get("/test_facet_size/neighbourhoods.json?_facet=city")
).json()
assert len(data7["facet_results"]["city"]["results"]) == 20
response6 = await ds.client.get(
"/test_facet_size/neighbourhoods.json?_facet=city"
)
data6 = response6.json()
assert len(data6["facet_results"]["city"]["results"]) == 6
# Setting it to max bumps it up to 50 again
ds._metadata_local["databases"]["test_facet_size"]["tables"]["neighbourhoods"][
"facet_size"
] = "max"
data7 = (
await ds.client.get("/test_facet_size/neighbourhoods.json?_facet=city")
).json()
assert len(data7["facet_results"]["city"]["results"]) == 20
finally:
ds._metadata_local = orig_metadata
def test_other_types_of_facet_in_metadata():