kopia lustrzana https://github.com/simonw/datasette
simple_primary_key now uses integer id, helps close #2458
rodzic
d48e5ae0ce
commit
4dff846271
|
@ -404,7 +404,7 @@ METADATA = {
|
|||
TABLES = (
|
||||
"""
|
||||
CREATE TABLE simple_primary_key (
|
||||
id varchar(30) primary key,
|
||||
id integer primary key,
|
||||
content text
|
||||
);
|
||||
|
||||
|
@ -441,8 +441,8 @@ CREATE INDEX idx_compound_three_primary_keys_content ON compound_three_primary_k
|
|||
|
||||
CREATE TABLE foreign_key_references (
|
||||
pk varchar(30) primary key,
|
||||
foreign_key_with_label varchar(30),
|
||||
foreign_key_with_blank_label varchar(30),
|
||||
foreign_key_with_label integer,
|
||||
foreign_key_with_blank_label integer,
|
||||
foreign_key_with_no_label varchar(30),
|
||||
foreign_key_compound_pk1 varchar(30),
|
||||
foreign_key_compound_pk2 varchar(30),
|
||||
|
@ -492,9 +492,9 @@ CREATE TABLE "table/with/slashes.csv" (
|
|||
|
||||
CREATE TABLE "complex_foreign_keys" (
|
||||
pk varchar(30) primary key,
|
||||
f1 text,
|
||||
f2 text,
|
||||
f3 text,
|
||||
f1 integer,
|
||||
f2 integer,
|
||||
f3 integer,
|
||||
FOREIGN KEY ("f1") REFERENCES [simple_primary_key](id),
|
||||
FOREIGN KEY ("f2") REFERENCES [simple_primary_key](id),
|
||||
FOREIGN KEY ("f3") REFERENCES [simple_primary_key](id)
|
||||
|
|
|
@ -708,7 +708,7 @@ async def test_invalid_custom_sql(ds_client):
|
|||
async def test_row(ds_client):
|
||||
response = await ds_client.get("/fixtures/simple_primary_key/1.json?_shape=objects")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["rows"] == [{"id": "1", "content": "hello"}]
|
||||
assert response.json()["rows"] == [{"id": 1, "content": "hello"}]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
@ -99,7 +99,19 @@ async def test_table_csv_with_nullable_labels(ds_client):
|
|||
@pytest.mark.asyncio
|
||||
async def test_table_csv_with_invalid_labels():
|
||||
# https://github.com/simonw/datasette/issues/2214
|
||||
ds = Datasette()
|
||||
ds = Datasette(
|
||||
config={
|
||||
"databases": {
|
||||
"db_2214": {
|
||||
"tables": {
|
||||
"t2": {
|
||||
"label_column": "name",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
await ds.invoke_startup()
|
||||
db = ds.add_memory_database("db_2214")
|
||||
await db.execute_write_script(
|
||||
|
|
|
@ -355,7 +355,7 @@ async def test_row_html_simple_primary_key(ds_client):
|
|||
assert ["id", "content"] == [th.string.strip() for th in table.select("thead th")]
|
||||
assert [
|
||||
[
|
||||
'<td class="col-id type-str">1</td>',
|
||||
'<td class="col-id type-int">1</td>',
|
||||
'<td class="col-content type-str">hello</td>',
|
||||
]
|
||||
] == [[str(td) for td in tr.select("td")] for tr in table.select("tbody tr")]
|
||||
|
|
|
@ -194,7 +194,7 @@ async def test_hook_render_cell_demo(ds_client):
|
|||
soup = Soup(response.text, "html.parser")
|
||||
td = soup.find("td", {"class": "col-content"})
|
||||
assert json.loads(td.string) == {
|
||||
"row": {"id": "4", "content": "RENDER_CELL_DEMO"},
|
||||
"row": {"id": 4, "content": "RENDER_CELL_DEMO"},
|
||||
"column": "content",
|
||||
"table": "simple_primary_key",
|
||||
"database": "fixtures",
|
||||
|
|
|
@ -24,11 +24,11 @@ async def test_table_json(ds_client):
|
|||
)
|
||||
assert data["query"]["params"] == {}
|
||||
assert data["rows"] == [
|
||||
{"id": "1", "content": "hello"},
|
||||
{"id": "2", "content": "world"},
|
||||
{"id": "3", "content": ""},
|
||||
{"id": "4", "content": "RENDER_CELL_DEMO"},
|
||||
{"id": "5", "content": "RENDER_CELL_ASYNC"},
|
||||
{"id": 1, "content": "hello"},
|
||||
{"id": 2, "content": "world"},
|
||||
{"id": 3, "content": ""},
|
||||
{"id": 4, "content": "RENDER_CELL_DEMO"},
|
||||
{"id": 5, "content": "RENDER_CELL_ASYNC"},
|
||||
]
|
||||
|
||||
|
||||
|
@ -46,11 +46,11 @@ async def test_table_not_exists_json(ds_client):
|
|||
async def test_table_shape_arrays(ds_client):
|
||||
response = await ds_client.get("/fixtures/simple_primary_key.json?_shape=arrays")
|
||||
assert response.json()["rows"] == [
|
||||
["1", "hello"],
|
||||
["2", "world"],
|
||||
["3", ""],
|
||||
["4", "RENDER_CELL_DEMO"],
|
||||
["5", "RENDER_CELL_ASYNC"],
|
||||
[1, "hello"],
|
||||
[2, "world"],
|
||||
[3, ""],
|
||||
[4, "RENDER_CELL_DEMO"],
|
||||
[5, "RENDER_CELL_ASYNC"],
|
||||
]
|
||||
|
||||
|
||||
|
@ -78,11 +78,11 @@ async def test_table_shape_arrayfirst(ds_client):
|
|||
async def test_table_shape_objects(ds_client):
|
||||
response = await ds_client.get("/fixtures/simple_primary_key.json?_shape=objects")
|
||||
assert response.json()["rows"] == [
|
||||
{"id": "1", "content": "hello"},
|
||||
{"id": "2", "content": "world"},
|
||||
{"id": "3", "content": ""},
|
||||
{"id": "4", "content": "RENDER_CELL_DEMO"},
|
||||
{"id": "5", "content": "RENDER_CELL_ASYNC"},
|
||||
{"id": 1, "content": "hello"},
|
||||
{"id": 2, "content": "world"},
|
||||
{"id": 3, "content": ""},
|
||||
{"id": 4, "content": "RENDER_CELL_DEMO"},
|
||||
{"id": 5, "content": "RENDER_CELL_ASYNC"},
|
||||
]
|
||||
|
||||
|
||||
|
@ -90,11 +90,11 @@ async def test_table_shape_objects(ds_client):
|
|||
async def test_table_shape_array(ds_client):
|
||||
response = await ds_client.get("/fixtures/simple_primary_key.json?_shape=array")
|
||||
assert response.json() == [
|
||||
{"id": "1", "content": "hello"},
|
||||
{"id": "2", "content": "world"},
|
||||
{"id": "3", "content": ""},
|
||||
{"id": "4", "content": "RENDER_CELL_DEMO"},
|
||||
{"id": "5", "content": "RENDER_CELL_ASYNC"},
|
||||
{"id": 1, "content": "hello"},
|
||||
{"id": 2, "content": "world"},
|
||||
{"id": 3, "content": ""},
|
||||
{"id": 4, "content": "RENDER_CELL_DEMO"},
|
||||
{"id": 5, "content": "RENDER_CELL_ASYNC"},
|
||||
]
|
||||
|
||||
|
||||
|
@ -106,11 +106,11 @@ async def test_table_shape_array_nl(ds_client):
|
|||
lines = response.text.split("\n")
|
||||
results = [json.loads(line) for line in lines]
|
||||
assert [
|
||||
{"id": "1", "content": "hello"},
|
||||
{"id": "2", "content": "world"},
|
||||
{"id": "3", "content": ""},
|
||||
{"id": "4", "content": "RENDER_CELL_DEMO"},
|
||||
{"id": "5", "content": "RENDER_CELL_ASYNC"},
|
||||
{"id": 1, "content": "hello"},
|
||||
{"id": 2, "content": "world"},
|
||||
{"id": 3, "content": ""},
|
||||
{"id": 4, "content": "RENDER_CELL_DEMO"},
|
||||
{"id": 5, "content": "RENDER_CELL_ASYNC"},
|
||||
] == results
|
||||
|
||||
|
||||
|
@ -129,11 +129,11 @@ async def test_table_shape_invalid(ds_client):
|
|||
async def test_table_shape_object(ds_client):
|
||||
response = await ds_client.get("/fixtures/simple_primary_key.json?_shape=object")
|
||||
assert response.json() == {
|
||||
"1": {"id": "1", "content": "hello"},
|
||||
"2": {"id": "2", "content": "world"},
|
||||
"3": {"id": "3", "content": ""},
|
||||
"4": {"id": "4", "content": "RENDER_CELL_DEMO"},
|
||||
"5": {"id": "5", "content": "RENDER_CELL_ASYNC"},
|
||||
"1": {"id": 1, "content": "hello"},
|
||||
"2": {"id": 2, "content": "world"},
|
||||
"3": {"id": 3, "content": ""},
|
||||
"4": {"id": 4, "content": "RENDER_CELL_DEMO"},
|
||||
"5": {"id": 5, "content": "RENDER_CELL_ASYNC"},
|
||||
}
|
||||
|
||||
|
||||
|
@ -522,27 +522,27 @@ async def test_searchable_invalid_column(ds_client):
|
|||
[
|
||||
(
|
||||
"/fixtures/simple_primary_key.json?_shape=arrays&content=hello",
|
||||
[["1", "hello"]],
|
||||
[[1, "hello"]],
|
||||
),
|
||||
(
|
||||
"/fixtures/simple_primary_key.json?_shape=arrays&content__contains=o",
|
||||
[
|
||||
["1", "hello"],
|
||||
["2", "world"],
|
||||
["4", "RENDER_CELL_DEMO"],
|
||||
[1, "hello"],
|
||||
[2, "world"],
|
||||
[4, "RENDER_CELL_DEMO"],
|
||||
],
|
||||
),
|
||||
(
|
||||
"/fixtures/simple_primary_key.json?_shape=arrays&content__exact=",
|
||||
[["3", ""]],
|
||||
[[3, ""]],
|
||||
),
|
||||
(
|
||||
"/fixtures/simple_primary_key.json?_shape=arrays&content__not=world",
|
||||
[
|
||||
["1", "hello"],
|
||||
["3", ""],
|
||||
["4", "RENDER_CELL_DEMO"],
|
||||
["5", "RENDER_CELL_ASYNC"],
|
||||
[1, "hello"],
|
||||
[3, ""],
|
||||
[4, "RENDER_CELL_DEMO"],
|
||||
[5, "RENDER_CELL_ASYNC"],
|
||||
],
|
||||
),
|
||||
],
|
||||
|
@ -558,9 +558,9 @@ async def test_table_filter_queries_multiple_of_same_type(ds_client):
|
|||
"/fixtures/simple_primary_key.json?_shape=arrays&content__not=world&content__not=hello"
|
||||
)
|
||||
assert [
|
||||
["3", ""],
|
||||
["4", "RENDER_CELL_DEMO"],
|
||||
["5", "RENDER_CELL_ASYNC"],
|
||||
[3, ""],
|
||||
[4, "RENDER_CELL_DEMO"],
|
||||
[5, "RENDER_CELL_ASYNC"],
|
||||
] == response.json()["rows"]
|
||||
|
||||
|
||||
|
@ -1100,8 +1100,8 @@ async def test_expand_label(ds_client):
|
|||
assert response.json() == {
|
||||
"1": {
|
||||
"pk": "1",
|
||||
"foreign_key_with_label": {"value": "1", "label": "hello"},
|
||||
"foreign_key_with_blank_label": "3",
|
||||
"foreign_key_with_label": {"value": 1, "label": "hello"},
|
||||
"foreign_key_with_blank_label": 3,
|
||||
"foreign_key_with_no_label": "1",
|
||||
"foreign_key_compound_pk1": "a",
|
||||
"foreign_key_compound_pk2": "b",
|
||||
|
@ -1163,8 +1163,8 @@ async def test_null_and_compound_foreign_keys_are_not_expanded(ds_client):
|
|||
assert response.json() == [
|
||||
{
|
||||
"pk": "1",
|
||||
"foreign_key_with_label": {"value": "1", "label": "hello"},
|
||||
"foreign_key_with_blank_label": {"value": "3", "label": ""},
|
||||
"foreign_key_with_label": {"value": 1, "label": "hello"},
|
||||
"foreign_key_with_blank_label": {"value": 3, "label": ""},
|
||||
"foreign_key_with_no_label": {"value": "1", "label": "1"},
|
||||
"foreign_key_compound_pk1": "a",
|
||||
"foreign_key_compound_pk2": "b",
|
||||
|
|
|
@ -615,8 +615,8 @@ async def test_table_html_foreign_key_links(ds_client):
|
|||
assert actual == [
|
||||
[
|
||||
'<td class="col-pk type-pk"><a href="/fixtures/foreign_key_references/1">1</a></td>',
|
||||
'<td class="col-foreign_key_with_label type-str"><a href="/fixtures/simple_primary_key/1">hello</a>\xa0<em>1</em></td>',
|
||||
'<td class="col-foreign_key_with_blank_label type-str"><a href="/fixtures/simple_primary_key/3">-</a>\xa0<em>3</em></td>',
|
||||
'<td class="col-foreign_key_with_label type-int"><a href="/fixtures/simple_primary_key/1">hello</a>\xa0<em>1</em></td>',
|
||||
'<td class="col-foreign_key_with_blank_label type-int"><a href="/fixtures/simple_primary_key/3">-</a>\xa0<em>3</em></td>',
|
||||
'<td class="col-foreign_key_with_no_label type-str"><a href="/fixtures/primary_key_multiple_columns/1">1</a></td>',
|
||||
'<td class="col-foreign_key_compound_pk1 type-str">a</td>',
|
||||
'<td class="col-foreign_key_compound_pk2 type-str">b</td>',
|
||||
|
@ -655,8 +655,8 @@ async def test_table_html_disable_foreign_key_links_with_labels(ds_client):
|
|||
assert actual == [
|
||||
[
|
||||
'<td class="col-pk type-pk"><a href="/fixtures/foreign_key_references/1">1</a></td>',
|
||||
'<td class="col-foreign_key_with_label type-str">1</td>',
|
||||
'<td class="col-foreign_key_with_blank_label type-str">3</td>',
|
||||
'<td class="col-foreign_key_with_label type-int">1</td>',
|
||||
'<td class="col-foreign_key_with_blank_label type-int">3</td>',
|
||||
'<td class="col-foreign_key_with_no_label type-str">1</td>',
|
||||
'<td class="col-foreign_key_compound_pk1 type-str">a</td>',
|
||||
'<td class="col-foreign_key_compound_pk2 type-str">b</td>',
|
||||
|
|
Ładowanie…
Reference in New Issue