mirror of
https://github.com/simonw/datasette.git
synced 2026-05-27 12:34:37 +02:00
Better example in API explorer for /-/upsert, closes #1936
This commit is contained in:
parent
4922fc2e39
commit
73f338b9f3
2 changed files with 24 additions and 2 deletions
|
|
@ -813,9 +813,15 @@ class ApiExplorerView(BaseView):
|
|||
"json": {
|
||||
"rows": [
|
||||
{
|
||||
column: None
|
||||
column: "<{}{}>".format(
|
||||
column,
|
||||
(
|
||||
" (primary key)"
|
||||
if column in pks
|
||||
else ""
|
||||
),
|
||||
)
|
||||
for column in await db.table_columns(table)
|
||||
if column not in pks
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -44,6 +44,22 @@ def _headers(token):
|
|||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_api_explorer_upsert_example_json(ds_write):
|
||||
response = await ds_write.client.get("/-/api", actor={"id": "root"})
|
||||
print("STATUS", response.status_code)
|
||||
assert response.status_code == 200
|
||||
import urllib.parse
|
||||
|
||||
text = urllib.parse.unquote_plus(response.text)
|
||||
upsert_idx = text.index("/data/docs/-/upsert")
|
||||
upsert_chunk = text[upsert_idx : upsert_idx + 500]
|
||||
assert '"id": "<id (primary key)>"' in upsert_chunk
|
||||
assert '"title": "<title>"' in upsert_chunk
|
||||
assert '"score": "<score>"' in upsert_chunk
|
||||
assert '"age": "<age>"' in upsert_chunk
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"content_type",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue