mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Blank foreign key labels now show as hyphens, closes #1086
This commit is contained in:
parent
13d1228d80
commit
2a981e2ac1
6 changed files with 73 additions and 37 deletions
|
|
@ -49,21 +49,21 @@ def test_homepage_sort_by_relationships(app_client):
|
|||
tables = [
|
||||
t["name"] for t in response.json["fixtures"]["tables_and_views_truncated"]
|
||||
]
|
||||
assert [
|
||||
assert tables == [
|
||||
"simple_primary_key",
|
||||
"foreign_key_references",
|
||||
"complex_foreign_keys",
|
||||
"roadside_attraction_characteristics",
|
||||
"searchable_tags",
|
||||
"foreign_key_references",
|
||||
] == tables
|
||||
]
|
||||
|
||||
|
||||
def test_database_page(app_client):
|
||||
response = app_client.get("/fixtures.json")
|
||||
assert response.status == 200
|
||||
data = response.json
|
||||
assert "fixtures" == data["database"]
|
||||
assert [
|
||||
assert data["database"] == "fixtures"
|
||||
assert data["tables"] == [
|
||||
{
|
||||
"name": "123_starts_with_digits",
|
||||
"columns": ["content"],
|
||||
|
|
@ -232,7 +232,12 @@ def test_database_page(app_client):
|
|||
},
|
||||
{
|
||||
"name": "foreign_key_references",
|
||||
"columns": ["pk", "foreign_key_with_label", "foreign_key_with_no_label"],
|
||||
"columns": [
|
||||
"pk",
|
||||
"foreign_key_with_label",
|
||||
"foreign_key_with_blank_label",
|
||||
"foreign_key_with_no_label",
|
||||
],
|
||||
"primary_keys": ["pk"],
|
||||
"count": 2,
|
||||
"hidden": False,
|
||||
|
|
@ -245,6 +250,11 @@ def test_database_page(app_client):
|
|||
"column": "foreign_key_with_no_label",
|
||||
"other_column": "id",
|
||||
},
|
||||
{
|
||||
"other_table": "simple_primary_key",
|
||||
"column": "foreign_key_with_blank_label",
|
||||
"other_column": "id",
|
||||
},
|
||||
{
|
||||
"other_table": "simple_primary_key",
|
||||
"column": "foreign_key_with_label",
|
||||
|
|
@ -403,6 +413,11 @@ def test_database_page(app_client):
|
|||
"fts_table": None,
|
||||
"foreign_keys": {
|
||||
"incoming": [
|
||||
{
|
||||
"other_table": "foreign_key_references",
|
||||
"column": "id",
|
||||
"other_column": "foreign_key_with_blank_label",
|
||||
},
|
||||
{
|
||||
"other_table": "foreign_key_references",
|
||||
"column": "id",
|
||||
|
|
@ -548,7 +563,7 @@ def test_database_page(app_client):
|
|||
"foreign_keys": {"incoming": [], "outgoing": []},
|
||||
"private": False,
|
||||
},
|
||||
] == data["tables"]
|
||||
]
|
||||
|
||||
|
||||
def test_no_files_uses_memory_database(app_client_no_files):
|
||||
|
|
@ -1203,32 +1218,38 @@ def test_row_foreign_key_tables(app_client):
|
|||
"/fixtures/simple_primary_key/1.json?_extras=foreign_key_tables"
|
||||
)
|
||||
assert response.status == 200
|
||||
assert [
|
||||
assert response.json["foreign_key_tables"] == [
|
||||
{
|
||||
"column": "id",
|
||||
"count": 1,
|
||||
"other_column": "foreign_key_with_label",
|
||||
"other_table": "foreign_key_references",
|
||||
},
|
||||
{
|
||||
"column": "id",
|
||||
"count": 1,
|
||||
"other_column": "f3",
|
||||
"other_table": "complex_foreign_keys",
|
||||
},
|
||||
{
|
||||
"column": "id",
|
||||
"other_column": "foreign_key_with_blank_label",
|
||||
"count": 0,
|
||||
"other_column": "f2",
|
||||
"other_table": "complex_foreign_keys",
|
||||
},
|
||||
{
|
||||
"other_table": "foreign_key_references",
|
||||
"column": "id",
|
||||
"other_column": "foreign_key_with_label",
|
||||
"count": 1,
|
||||
"other_column": "f1",
|
||||
"other_table": "complex_foreign_keys",
|
||||
},
|
||||
] == response.json["foreign_key_tables"]
|
||||
{
|
||||
"other_table": "complex_foreign_keys",
|
||||
"column": "id",
|
||||
"other_column": "f3",
|
||||
"count": 1,
|
||||
},
|
||||
{
|
||||
"other_table": "complex_foreign_keys",
|
||||
"column": "id",
|
||||
"other_column": "f2",
|
||||
"count": 0,
|
||||
},
|
||||
{
|
||||
"other_table": "complex_foreign_keys",
|
||||
"column": "id",
|
||||
"other_column": "f1",
|
||||
"count": 1,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def test_unit_filters(app_client):
|
||||
|
|
@ -1593,13 +1614,14 @@ def test_expand_label(app_client):
|
|||
"/fixtures/foreign_key_references.json?_shape=object"
|
||||
"&_label=foreign_key_with_label&_size=1"
|
||||
)
|
||||
assert {
|
||||
assert response.json == {
|
||||
"1": {
|
||||
"pk": "1",
|
||||
"foreign_key_with_label": {"value": "1", "label": "hello"},
|
||||
"foreign_key_with_blank_label": "3",
|
||||
"foreign_key_with_no_label": "1",
|
||||
}
|
||||
} == response.json
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -1790,11 +1812,13 @@ def test_null_foreign_keys_are_not_expanded(app_client):
|
|||
{
|
||||
"pk": "1",
|
||||
"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"},
|
||||
},
|
||||
{
|
||||
"pk": "2",
|
||||
"foreign_key_with_label": None,
|
||||
"foreign_key_with_blank_label": None,
|
||||
"foreign_key_with_no_label": None,
|
||||
},
|
||||
] == response.json
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue