Row count fix + sort index page databases alphabetically

Sorting alphabetically should fix a test failure in Python 3.5

Refs #460
This commit is contained in:
Simon Willison 2019-05-15 17:40:10 -07:00
commit 79303163b2
2 changed files with 9 additions and 6 deletions

View file

@ -73,7 +73,7 @@ class IndexView(RenderMixin):
"tables_and_views_more": (len(visible_tables) + len(views))
> TRUNCATE_AT,
"tables_count": len(visible_tables),
"table_rows_sum": sum((t["count"] or 0) for t in tables.values()),
"table_rows_sum": sum((t["count"] or 0) for t in visible_tables),
"hidden_table_rows_sum": sum(
t["count"] for t in hidden_tables if t["count"] is not None
),
@ -81,6 +81,9 @@ class IndexView(RenderMixin):
"views_count": len(views),
}
)
databases.sort(key=lambda database: database["name"])
if as_format:
headers = {}
if self.ds.cors:

View file

@ -25,15 +25,15 @@ def test_homepage(app_client_two_attached_databases):
)
# Should be two attached databases
assert [
{"href": "/fixtures", "text": "fixtures"},
{"href": "/extra_database", "text": "extra_database"},
{"href": "/fixtures", "text": "fixtures"},
] == [{"href": a["href"], "text": a.text.strip()} for a in soup.select("h2 a")]
# The second attached database should show count text and attached tables
h2 = soup.select("h2")[1]
# The first attached database should show count text and attached tables
h2 = soup.select("h2")[0]
assert "extra_database" == h2.text.strip()
counts_p, links_p = h2.find_all_next("p")
counts_p, links_p = h2.find_all_next("p")[:2]
assert (
"7 rows in 1 table, 5 rows in 4 hidden tables, 1 view" == counts_p.text.strip()
"2 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 = [