Skip to content

Commit

Permalink
Test for _title= mechanism, refs #10
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 4, 2024
1 parent 0bfef41 commit f45fcca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion datasette_write/templates/datasette_write.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "base.html" %}

{% block title %}Write with SQL{% endblock %}
{% block title %}{% if custom_title %}{{ custom_title }}{% else %}Write to {{ database_name }} with SQL{% endif %}{% endblock %}

{% block extra_head %}
<style>
Expand Down
23 changes: 23 additions & 0 deletions tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,26 @@ async def test_redirect_to(ds, valid):
assert response2.status_code == 302
actual_redirect_to = response2.headers["location"]
assert actual_redirect_to == "/" if valid else "/test/-/write"


@pytest.mark.asyncio
@pytest.mark.parametrize("scenario", ("valid", "invalid", "none"))
async def test_title(ds, scenario):
cookies = {"ds_actor": ds.sign({"a": {"id": "root"}}, "actor")}
signed_title = ds.sign("Custom Title", "query_title")
params = {}
if scenario != "none":
params["_title"] = signed_title + ("" if scenario == "valid" else "invalid")
response = await ds.client.get(
"/test/-/write",
params=params,
cookies=cookies,
)
assert response.status_code == 200
if scenario == "valid":
assert "<title>Custom Title</title>" in response.text
# <details><summary only if custom title is set
assert "<summary>SQL query</summary>" in response.text
else:
assert "<title>Write to test with SQL</title>" in response.text
assert "<summary>SQL query</summary>" not in response.text

0 comments on commit f45fcca

Please sign in to comment.