mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Add register_actions hook to test plugin and improve test
This commit is contained in:
parent
130dad268d
commit
d73b6f169f
3 changed files with 28 additions and 0 deletions
|
|
@ -48,6 +48,7 @@ EXPECTED_PLUGINS = [
|
||||||
"prepare_connection",
|
"prepare_connection",
|
||||||
"prepare_jinja2_environment",
|
"prepare_jinja2_environment",
|
||||||
"query_actions",
|
"query_actions",
|
||||||
|
"register_actions",
|
||||||
"register_facet_classes",
|
"register_facet_classes",
|
||||||
"register_magic_parameters",
|
"register_magic_parameters",
|
||||||
"register_permissions",
|
"register_permissions",
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ import asyncio
|
||||||
from datasette import hookimpl, Permission
|
from datasette import hookimpl, Permission
|
||||||
from datasette.facets import Facet
|
from datasette.facets import Facet
|
||||||
from datasette import tracer
|
from datasette import tracer
|
||||||
|
from datasette.permissions import Action
|
||||||
|
from datasette.resources import DatabaseResource
|
||||||
from datasette.utils import path_with_added_args
|
from datasette.utils import path_with_added_args
|
||||||
from datasette.utils.asgi import asgi_send_json, Response
|
from datasette.utils.asgi import asgi_send_json, Response
|
||||||
import base64
|
import base64
|
||||||
|
|
@ -498,3 +500,17 @@ def register_permissions(datasette):
|
||||||
for p in extras["permissions"]
|
for p in extras["permissions"]
|
||||||
)
|
)
|
||||||
return permissions
|
return permissions
|
||||||
|
|
||||||
|
|
||||||
|
@hookimpl
|
||||||
|
def register_actions(datasette):
|
||||||
|
return [
|
||||||
|
Action(
|
||||||
|
name="view-collection",
|
||||||
|
abbr="vc",
|
||||||
|
description="View a collection",
|
||||||
|
takes_parent=True,
|
||||||
|
takes_child=False,
|
||||||
|
resource_class=DatabaseResource,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -1560,6 +1560,17 @@ async def test_hook_register_events():
|
||||||
assert any(k.__name__ == "OneEvent" for k in datasette.event_classes)
|
assert any(k.__name__ == "OneEvent" for k in datasette.event_classes)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_hook_register_actions():
|
||||||
|
datasette = Datasette(memory=True, plugins_dir=PLUGINS_DIR)
|
||||||
|
await datasette.invoke_startup()
|
||||||
|
# Check that the custom action from my_plugin.py is registered
|
||||||
|
assert "view-collection" in datasette.actions
|
||||||
|
action = datasette.actions["view-collection"]
|
||||||
|
assert action.abbr == "vc"
|
||||||
|
assert action.description == "View a collection"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="TODO")
|
@pytest.mark.skip(reason="TODO")
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"metadata,config,expected_metadata,expected_config",
|
"metadata,config,expected_metadata,expected_config",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue