Skip to content

Commit

Permalink
Only show nav menu item if plugin is configured, closes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Aug 21, 2023
1 parent e3b2bb9 commit 1547a5c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions datasette_ripgrep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ def register_routes():

@hookimpl
def menu_links(datasette, actor):
config = datasette.plugin_config("datasette-ripgrep") or {}
if not config.get("path"):
return
return [
{"href": datasette.urls.path("/-/ripgrep"), "label": "ripgrep search"},
]
29 changes: 29 additions & 0 deletions tests/test_ripgrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,32 @@ async def test_permissions(src, metadata, authenticated, path, expected_status):
cookies["ds_actor"] = datasette.sign({"a": {"id": "user"}}, "actor")
response = await datasette.client.get(path, cookies=cookies)
assert response.status_code == expected_status


@pytest.mark.asyncio
@pytest.mark.parametrize("configured", (True, False))
async def test_configuration(configured):
metadata = {}
if configured:
metadata = {
"plugins": {
"datasette-ripgrep": {
"path": "/tmp",
}
}
}
datasette = Datasette(memory=True, metadata=metadata)
response = await datasette.client.get("/-/ripgrep")
if not configured:
assert response.status_code == 500
assert "The path plugin configuration is required." in response.text
else:
assert response.status_code == 200
# And check the navigation menu
response2 = await datasette.client.get("/")
assert response2.status_code == 200
menu_fragment = '<li><a href="/-/ripgrep">ripgrep search</a></li>'
if not configured:
assert menu_fragment not in response2.text
else:
assert menu_fragment in response2.text

0 comments on commit 1547a5c

Please sign in to comment.