Link rel=alternate header for tables and rows

Also added Access-Control-Expose-Headers: Link to --cors mode.

Closes #1533

Refs https://github.com/simonw/datasette-notebook/issues/2

LL#	metadata.json.1
This commit is contained in:
Simon Willison 2021-11-27 12:08:42 -08:00
commit 3ef47a0896
9 changed files with 86 additions and 6 deletions

View file

@ -977,6 +977,7 @@ def test_cors(app_client_with_cors, path, status_code):
assert response.status == status_code
assert response.headers["Access-Control-Allow-Origin"] == "*"
assert response.headers["Access-Control-Allow-Headers"] == "Authorization"
assert response.headers["Access-Control-Expose-Headers"] == "Link"
@pytest.mark.parametrize(

View file

@ -1069,3 +1069,31 @@ def test_table_page_title(app_client, path, expected):
response = app_client.get(path)
title = Soup(response.text, "html.parser").find("title").text
assert title == expected
@pytest.mark.parametrize(
"path,expected",
(
(
"/fixtures/table%2Fwith%2Fslashes.csv",
"http://localhost/fixtures/table%2Fwith%2Fslashes.csv?_format=json",
),
("/fixtures/facetable", "http://localhost/fixtures/facetable.json"),
(
"/fixtures/no_primary_key/1",
"http://localhost/fixtures/no_primary_key/1.json",
),
),
)
def test_alternate_url_json(app_client, path, expected):
response = app_client.get(path)
link = response.headers["link"]
assert link == '{}; rel="alternate"; type="application/json+datasette"'.format(
expected
)
assert (
'<link rel="alternate" type="application/json+datasette" href="{}">'.format(
expected
)
in response.text
)