mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Reset _metadata_local in a couple of tests
Refs https://github.com/simonw/datasette/pull/1960#issuecomment-1356476886
This commit is contained in:
parent
9c43b4164d
commit
89cffcf14c
2 changed files with 44 additions and 34 deletions
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -990,28 +990,32 @@ def test_hook_skip_csrf(app_client):
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hook_get_metadata(ds_client):
|
||||
ds_client.ds._metadata_local = {
|
||||
"title": "Testing get_metadata hook!",
|
||||
"databases": {"from-local": {"title": "Hello from local metadata"}},
|
||||
}
|
||||
og_pm_hook_get_metadata = pm.hook.get_metadata
|
||||
try:
|
||||
orig_metadata = ds_client.ds._metadata_local
|
||||
ds_client.ds._metadata_local = {
|
||||
"title": "Testing get_metadata hook!",
|
||||
"databases": {"from-local": {"title": "Hello from local metadata"}},
|
||||
}
|
||||
og_pm_hook_get_metadata = pm.hook.get_metadata
|
||||
|
||||
def get_metadata_mock(*args, **kwargs):
|
||||
return [
|
||||
{
|
||||
"databases": {
|
||||
"from-hook": {"title": "Hello from the plugin hook"},
|
||||
"from-local": {"title": "This will be overwritten!"},
|
||||
def get_metadata_mock(*args, **kwargs):
|
||||
return [
|
||||
{
|
||||
"databases": {
|
||||
"from-hook": {"title": "Hello from the plugin hook"},
|
||||
"from-local": {"title": "This will be overwritten!"},
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
pm.hook.get_metadata = get_metadata_mock
|
||||
meta = ds_client.ds.metadata()
|
||||
assert "Testing get_metadata hook!" == meta["title"]
|
||||
assert "Hello from local metadata" == meta["databases"]["from-local"]["title"]
|
||||
assert "Hello from the plugin hook" == meta["databases"]["from-hook"]["title"]
|
||||
pm.hook.get_metadata = og_pm_hook_get_metadata
|
||||
pm.hook.get_metadata = get_metadata_mock
|
||||
meta = ds_client.ds.metadata()
|
||||
assert "Testing get_metadata hook!" == meta["title"]
|
||||
assert "Hello from local metadata" == meta["databases"]["from-local"]["title"]
|
||||
assert "Hello from the plugin hook" == meta["databases"]["from-hook"]["title"]
|
||||
pm.hook.get_metadata = og_pm_hook_get_metadata
|
||||
finally:
|
||||
ds_client.ds._metadata_local = orig_metadata
|
||||
|
||||
|
||||
def _extract_commands(output):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue