mirror of
https://github.com/simonw/datasette.git
synced 2026-10-24 18:26:58 +02:00
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
import pytest
|
|
from bs4 import BeautifulSoup as Soup
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_ad_hoc_query_form_targets_query_route(ds_client):
|
|
response = await ds_client.get("/fixtures/-/query?sql=select+1")
|
|
assert response.status_code == 200
|
|
|
|
form = Soup(response.text, "html.parser").select_one("form.sql.core")
|
|
assert form is not None
|
|
assert form["action"] == "/fixtures/-/query"
|
|
|
|
|
|
def test_ad_hoc_query_form_action_preserves_base_url(app_client_base_url_prefix):
|
|
response = app_client_base_url_prefix.get("/prefix/fixtures/-/query?sql=select+1")
|
|
assert response.status_code == 200
|
|
|
|
form = Soup(response.text, "html.parser").select_one("form.sql.core")
|
|
assert form is not None
|
|
assert form["action"] == "/prefix/fixtures/-/query"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_stored_query_form_action_encodes_query_name(ds_client):
|
|
query_name = "query with spaces"
|
|
await ds_client.ds.update_query("fixtures", query_name, sql="select 1")
|
|
query_url = ds_client.ds.urls.query("fixtures", query_name)
|
|
|
|
response = await ds_client.get(query_url)
|
|
assert response.status_code == 200
|
|
|
|
form = Soup(response.text, "html.parser").select_one("form.sql.core")
|
|
assert form is not None
|
|
assert form["action"] == query_url
|