Include views on homepage, fix table counts

If we have less than 5 tables we now also show one or more views in the
summary on the homepage.

Also corrected the logic for the row counts - we now count hidden and
visible tables separately.

Closes #373, Refs #460
This commit is contained in:
Simon Willison 2019-05-15 17:28:07 -07:00
commit 5d6b2c30f1
5 changed files with 42 additions and 24 deletions

View file

@ -612,6 +612,8 @@ CREATE TABLE searchable (
text2 text
);
CREATE VIEW searchable_view AS SELECT * FROM searchable;
INSERT INTO searchable VALUES (1, 'barry cat', 'terry dog');
INSERT INTO searchable VALUES (2, 'terry dog', 'sara weasel');

View file

@ -24,9 +24,9 @@ def test_homepage(app_client):
assert response.json.keys() == {"fixtures": 0}.keys()
d = response.json["fixtures"]
assert d["name"] == "fixtures"
assert d["tables_count"] == 26
assert len(d["tables_truncated"]) == 5
assert d["tables_more"] is True
assert d["tables_count"] == 21
assert len(d["tables_and_views_truncated"]) == 5
assert d["tables_and_views_more"] is True
# 4 hidden FTS tables + no_primary_key (hidden in metadata)
assert d["hidden_tables_count"] == 5
# 201 in no_primary_key, plus 5 in other hidden tables:
@ -448,8 +448,8 @@ def test_no_files_uses_memory_database(app_client_no_files):
"path": "/:memory:",
"table_rows_sum": 0,
"tables_count": 0,
"tables_more": False,
"tables_truncated": [],
"tables_and_views_more": False,
"tables_and_views_truncated": [],
"views_count": 0,
}
} == response.json

View file

@ -32,16 +32,17 @@ def test_homepage(app_client_two_attached_databases):
h2 = soup.select("h2")[1]
assert "extra_database" == h2.text.strip()
counts_p, links_p = h2.find_all_next("p")
assert "7 rows in 5 tables, 5 rows in 4 hidden tables" == counts_p.text.strip().replace(
" ", ""
).replace(
"\n", ""
assert (
"7 rows in 1 table, 5 rows in 4 hidden tables, 1 view" == counts_p.text.strip()
)
# We should only show visible, not hidden tables here:
table_links = [
{"href": a["href"], "text": a.text.strip()} for a in links_p.findAll("a")
]
assert [{"href": "/extra_database/searchable", "text": "searchable"}] == table_links
assert [
{"href": "/extra_database/searchable", "text": "searchable"},
{"href": "/extra_database/searchable_view", "text": "searchable_view"},
] == table_links
def test_memory_database_page(app_client_with_memory):