kopia lustrzana https://github.com/simonw/datasette
Unit test for _table custom template, refs #521
rodzic
e7120d91f6
commit
13e4f9a676
|
@ -101,6 +101,7 @@ def make_app_client(
|
|||
extra_databases=None,
|
||||
inspect_data=None,
|
||||
static_mounts=None,
|
||||
template_dir=None,
|
||||
):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
filepath = os.path.join(tmpdir, filename)
|
||||
|
@ -143,6 +144,7 @@ def make_app_client(
|
|||
config=config,
|
||||
inspect_data=inspect_data,
|
||||
static_mounts=static_mounts,
|
||||
template_dir=template_dir,
|
||||
)
|
||||
ds.sqlite_functions.append(("sleep", 1, lambda n: time.sleep(float(n))))
|
||||
client = TestClient(ds.app())
|
||||
|
|
|
@ -964,3 +964,16 @@ def test_metadata_json_html(app_client):
|
|||
assert response.status == 200
|
||||
pre = Soup(response.body, "html.parser").find("pre")
|
||||
assert METADATA == json.loads(pre.text)
|
||||
|
||||
|
||||
def test_custom_table_include():
|
||||
for client in make_app_client(
|
||||
template_dir=str(pathlib.Path(__file__).parent / "test_templates")
|
||||
):
|
||||
response = client.get("/fixtures/complex_foreign_keys")
|
||||
assert response.status == 200
|
||||
assert (
|
||||
'<div class="custom-table-row">'
|
||||
'1 - 2 - <a href="/fixtures/simple_primary_key/1">hello</a> <em>1</em>'
|
||||
"</div>"
|
||||
) == str(Soup(response.text, "html.parser").select_one("div.custom-table-row"))
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{% for row in display_rows %}
|
||||
<div class="custom-table-row">{{ row["f1"] }} - {{ row["f2"] }} - {{ row.display("f3") }}</div>
|
||||
{% endfor %}
|
Ładowanie…
Reference in New Issue