This commit is contained in:
Simon Willison 2026-10-12 18:18:01 +00:00 • committed by GitHub
commit 3fe43cd22c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 151 additions and 48 deletions

View file

@ -363,10 +363,45 @@ async def test_invalid_custom_sql(ds_client):
@pytest.mark.asyncio
async def test_row(ds_client):
response = await ds_client.get("/fixtures/simple_primary_key/1.json?_shape=objects")
response = await ds_client.get("/fixtures/simple_primary_key/1.json")
assert response.status_code == 200
assert response.json()["ok"] is True
assert response.json()["rows"] == [{"id": 1, "content": "hello"}]
data = response.json()
assert data["ok"] is True
assert data["row"] == {"id": 1, "content": "hello"}
assert "rows" not in data
assert "truncated" not in data
@pytest.mark.asyncio
@pytest.mark.parametrize(
"shape,expected",
(
("objects", [{"id": 1, "content": "hello"}]),
("arrays", [[1, "hello"]]),
("array", [{"id": 1, "content": "hello"}]),
("arrayfirst", [1]),
("object", {"1": {"id": 1, "content": "hello"}}),
),
)
async def test_row_shape(ds_client, shape, expected):
# Any ?_shape= returns the same shapes as the table JSON
response = await ds_client.get(
f"/fixtures/simple_primary_key/1.json?_shape={shape}"
)
assert response.status_code == 200
data = response.json()
if shape in ("objects", "arrays"):
assert "row" not in data
assert data["truncated"] is False
data = data["rows"]
assert data == expected
@pytest.mark.asyncio
async def test_row_json_cols(ds_client):
response = await ds_client.get("/fixtures/facetable/1.json?_json=tags")
assert response.status_code == 200
assert response.json()["row"]["tags"] == ["tag1", "tag2"]
@pytest.mark.asyncio
@ -615,20 +650,23 @@ async def test_row_extra_render_cell():
# Verify the response structure
assert "render_cell" in data
assert "rows" in data
assert "row" in data
# render_cell should be a list with one row (since this is a row page)
# render_cell is a single object to match "row"
# Only columns modified by plugins are included (sparse output)
render_cell = data["render_cell"]
assert len(render_cell) == 1
# The row: id=1, name='Alice'
# The 'name' column should be rendered by our plugin as <strong>Alice</strong>
assert render_cell[0]["name"] == "<strong>Alice</strong>"
# The 'id' column is not included since no plugin modified it
assert "id" not in render_cell[0]
assert data["render_cell"] == {"name": "<strong>Alice</strong>"}
# The regular rows should still contain raw values
# The regular row should still contain raw values
assert data["row"] == {"id": 1, "name": "Alice"}
# With a ?_shape= render_cell is a list, matching "rows"
response = await ds.client.get(
"/test_row_render/test_render/1.json?_extra=render_cell&_shape=objects"
)
data = response.json()
assert data["render_cell"] == [{"name": "<strong>Alice</strong>"}]
assert data["rows"] == [{"id": 1, "name": "Alice"}]
finally:

View file

@ -748,7 +748,7 @@ async def test_row_endpoint_render_cell_with_column_types(ds_ct):
response = await ds_ct.client.get("/data/posts/1.json?_extra=render_cell")
assert response.status_code == 200
data = response.json()
rendered = data["render_cell"][0]
rendered = data["render_cell"]
assert "mailto:" in rendered["author_email"]
assert "href" in rendered["website"]

View file

@ -1302,6 +1302,24 @@ async def test_infinity_returned_as_invalid_json_if_requested(ds_client):
]
@pytest.mark.asyncio
@pytest.mark.parametrize(
"shape,expected",
(
("arrays", {"ok": True, "rows": [[None], [None], [1.5]], "truncated": False}),
("arrayfirst", [None, None, 1.5]),
),
)
async def test_infinity_with_array_shapes(ds_client, shape, expected):
# Rows containing infinity are lists rather than sqlite3.Row objects
response = await ds_client.get(
"/fixtures/-/query.json?sql=select+value+from+infinity+order+by+rowid"
"&_shape=" + shape
)
assert response.status_code == 200
assert response.json() == expected
@pytest.mark.asyncio
async def test_custom_query_with_unicode_characters(ds_client):
# /fixtures/𝐜𝐢𝐭𝐢𝐞𝐬.json