mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Treat plugins in metadata as if they were in config, closes #2248
This commit is contained in:
parent
d4bc2b2dfc
commit
be4f02335f
3 changed files with 97 additions and 0 deletions
|
|
@ -1458,3 +1458,54 @@ async def test_hook_register_events():
|
|||
datasette = Datasette(memory=True)
|
||||
await datasette.invoke_startup()
|
||||
assert any(k.__name__ == "OneEvent" for k in datasette.event_classes)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"metadata,config,expected_metadata,expected_config",
|
||||
(
|
||||
(
|
||||
# Instance level
|
||||
{"plugins": {"datasette-foo": "bar"}},
|
||||
{},
|
||||
{},
|
||||
{"plugins": {"datasette-foo": "bar"}},
|
||||
),
|
||||
(
|
||||
# Database level
|
||||
{"databases": {"foo": {"plugins": {"datasette-foo": "bar"}}}},
|
||||
{},
|
||||
{},
|
||||
{"databases": {"foo": {"plugins": {"datasette-foo": "bar"}}}},
|
||||
),
|
||||
(
|
||||
# Table level
|
||||
{
|
||||
"databases": {
|
||||
"foo": {"tables": {"bar": {"plugins": {"datasette-foo": "bar"}}}}
|
||||
}
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
"databases": {
|
||||
"foo": {"tables": {"bar": {"plugins": {"datasette-foo": "bar"}}}}
|
||||
}
|
||||
},
|
||||
),
|
||||
(
|
||||
# Keep other keys
|
||||
{"plugins": {"datasette-foo": "bar"}, "other": "key"},
|
||||
{"original_config": "original"},
|
||||
{"other": "key"},
|
||||
{"original_config": "original", "plugins": {"datasette-foo": "bar"}},
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_metadata_plugin_config_treated_as_config(
|
||||
metadata, config, expected_metadata, expected_config
|
||||
):
|
||||
ds = Datasette(metadata=metadata, config=config)
|
||||
actual_metadata = ds.metadata()
|
||||
assert "plugins" not in actual_metadata
|
||||
assert actual_metadata == expected_metadata
|
||||
assert ds.config == expected_config
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue