mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
query_actions plugin hook
* New query_actions plugin hook, closes #2283
This commit is contained in:
parent
f99c2f5f8c
commit
6ec0081f5d
7 changed files with 151 additions and 0 deletions
|
|
@ -945,6 +945,31 @@ async def test_hook_table_actions(ds_client, table_or_view):
|
|||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"path,expected_url",
|
||||
(
|
||||
("/fixtures?sql=select+1", "/fixtures/-/explain?sql=select+1"),
|
||||
(
|
||||
"/fixtures/pragma_cache_size",
|
||||
"/fixtures/-/explain?sql=PRAGMA+cache_size%3B&query_name=pragma_cache_size",
|
||||
),
|
||||
),
|
||||
)
|
||||
async def test_hook_query_actions(ds_client, path, expected_url):
|
||||
def get_table_actions_links(html):
|
||||
soup = Soup(html, "html.parser")
|
||||
details = soup.find("details", {"class": "actions-menu-links"})
|
||||
if details is None:
|
||||
return []
|
||||
return [{"label": a.text, "href": a["href"]} for a in details.select("a")]
|
||||
|
||||
response = await ds_client.get(path)
|
||||
assert response.status_code == 200
|
||||
links = get_table_actions_links(response.text)
|
||||
assert links == [{"label": "Explain this query", "href": expected_url}]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hook_database_actions(ds_client):
|
||||
def get_table_actions_links(html):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue