mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
extra_template_vars plugin hook (#542)
* extra_template_vars plugin hook Closes #541 * Workaround for cwd bug Based on https://github.com/pytest-dev/pytest/issues/1235#issuecomment-175295691
This commit is contained in:
parent
a18e0964ec
commit
fcfcae21e6
9 changed files with 186 additions and 19 deletions
|
|
@ -3,6 +3,7 @@ from .fixtures import app_client, make_app_client, TEMP_PLUGIN_SECRET_FILE # no
|
|||
import base64
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import pytest
|
||||
import urllib
|
||||
|
|
@ -188,3 +189,28 @@ def test_plugins_extra_body_script(app_client, path, expected_extra_body_script)
|
|||
def test_plugins_asgi_wrapper(app_client):
|
||||
response = app_client.get("/fixtures")
|
||||
assert "fixtures" == response.headers["x-databases"]
|
||||
|
||||
|
||||
def test_plugins_extra_template_vars(restore_working_directory):
|
||||
for client in make_app_client(
|
||||
template_dir=str(pathlib.Path(__file__).parent / "test_templates")
|
||||
):
|
||||
response = client.get("/-/metadata")
|
||||
assert response.status == 200
|
||||
extra_template_vars = json.loads(
|
||||
Soup(response.body, "html.parser").select("pre.extra_template_vars")[0].text
|
||||
)
|
||||
assert {
|
||||
"template": "show_json.html",
|
||||
"scope_path": "/-/metadata",
|
||||
} == extra_template_vars
|
||||
extra_template_vars_from_awaitable = json.loads(
|
||||
Soup(response.body, "html.parser")
|
||||
.select("pre.extra_template_vars_from_awaitable")[0]
|
||||
.text
|
||||
)
|
||||
assert {
|
||||
"template": "show_json.html",
|
||||
"awaitable": True,
|
||||
"scope_path": "/-/metadata",
|
||||
} == extra_template_vars_from_awaitable
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue