mirror of
https://github.com/simonw/datasette.git
synced 2026-10-18 07:17:00 +02:00
Merge 091e8ab994 into c435a80030
This commit is contained in:
commit
9e3fee3c0b
3 changed files with 46 additions and 1 deletions
|
|
@ -1491,7 +1491,9 @@ class Datasette:
|
|||
|
||||
# fallback to db_config or top-level config, in that order, if needed
|
||||
if table_plugin_config is None and fallback:
|
||||
return db_plugin_config or self._plugin_config_top(plugin_name)
|
||||
if db_plugin_config is not None:
|
||||
return db_plugin_config
|
||||
return self._plugin_config_top(plugin_name)
|
||||
|
||||
return table_plugin_config
|
||||
|
||||
|
|
|
|||
|
|
@ -302,6 +302,8 @@ If it cannot find the requested configuration at the table layer, it will fall b
|
|||
|
||||
In this case, the above code would return that configuration for ANY table within the ``sf-trees`` database.
|
||||
|
||||
An explicit empty dictionary at the database or table layer counts as configuration and prevents fallback to the next layer.
|
||||
|
||||
The plugin configuration could also be set at the top level of ``datasette.yaml``:
|
||||
|
||||
.. [[[cog
|
||||
|
|
|
|||
|
|
@ -301,6 +301,47 @@ async def test_plugin_config(ds_client):
|
|||
assert None is ds_client.ds.plugin_config("unknown-plugin")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"database_plugins,table_plugins,fallback,expected",
|
||||
[
|
||||
({"example": {}}, {}, True, {}),
|
||||
({"example": {"setting": "database"}}, {}, True, {"setting": "database"}),
|
||||
({}, {}, True, {"setting": "top"}),
|
||||
({"example": None}, {}, True, {"setting": "top"}),
|
||||
(
|
||||
{"example": {}},
|
||||
{"example": {"setting": "table"}},
|
||||
True,
|
||||
{"setting": "table"},
|
||||
),
|
||||
({"example": {"setting": "database"}}, {"example": {}}, True, {}),
|
||||
({"example": {}}, {}, False, None),
|
||||
({"example": {}}, {"example": {}}, False, {}),
|
||||
],
|
||||
)
|
||||
def test_plugin_config_table_fallback_preserves_empty_database_config(
|
||||
database_plugins, table_plugins, fallback, expected
|
||||
):
|
||||
datasette = Datasette(
|
||||
config={
|
||||
"plugins": {"example": {"setting": "top"}},
|
||||
"databases": {
|
||||
"example_db": {
|
||||
"plugins": database_plugins,
|
||||
"tables": {"items": {"plugins": table_plugins}},
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
assert (
|
||||
datasette.plugin_config(
|
||||
"example", database="example_db", table="items", fallback=fallback
|
||||
)
|
||||
== expected
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_plugin_config_env(ds_client, monkeypatch):
|
||||
monkeypatch.setenv("FOO_ENV", "FROM_ENVIRONMENT")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue