mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fixed bug loading database called 'test-database (1).sqlite'
Closes #1181. Also now ensures that database URLs have special characters URL-quoted.
This commit is contained in:
parent
07e1635615
commit
a5ede3cdd4
7 changed files with 55 additions and 27 deletions
|
|
@ -609,17 +609,17 @@ def test_no_files_uses_memory_database(app_client_no_files):
|
|||
assert response.status == 200
|
||||
assert {
|
||||
":memory:": {
|
||||
"name": ":memory:",
|
||||
"hash": None,
|
||||
"color": "f7935d",
|
||||
"path": "/%3Amemory%3A",
|
||||
"tables_and_views_truncated": [],
|
||||
"tables_and_views_more": False,
|
||||
"tables_count": 0,
|
||||
"table_rows_sum": 0,
|
||||
"show_table_row_counts": False,
|
||||
"hidden_table_rows_sum": 0,
|
||||
"hidden_tables_count": 0,
|
||||
"name": ":memory:",
|
||||
"show_table_row_counts": False,
|
||||
"path": "/:memory:",
|
||||
"table_rows_sum": 0,
|
||||
"tables_count": 0,
|
||||
"tables_and_views_more": False,
|
||||
"tables_and_views_truncated": [],
|
||||
"views_count": 0,
|
||||
"private": False,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import pytest
|
|||
import sys
|
||||
import textwrap
|
||||
from unittest import mock
|
||||
import urllib
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -255,3 +256,25 @@ def test_serve_duplicate_database_names(ensure_eventloop, tmpdir):
|
|||
assert result.exit_code == 0, result.output
|
||||
databases = json.loads(result.output)
|
||||
assert {db["name"] for db in databases} == {"db", "db_2"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"filename", ["test-database (1).sqlite", "database (1).sqlite"]
|
||||
)
|
||||
def test_weird_database_names(ensure_eventloop, tmpdir, filename):
|
||||
# https://github.com/simonw/datasette/issues/1181
|
||||
runner = CliRunner()
|
||||
db_path = str(tmpdir / filename)
|
||||
sqlite3.connect(db_path).execute("vacuum")
|
||||
result1 = runner.invoke(cli, [db_path, "--get", "/"])
|
||||
assert result1.exit_code == 0, result1.output
|
||||
filename_no_stem = filename.rsplit(".", 1)[0]
|
||||
expected_link = '<a href="/{}">{}</a>'.format(
|
||||
urllib.parse.quote(filename_no_stem), filename_no_stem
|
||||
)
|
||||
assert expected_link in result1.output
|
||||
# Now try hitting that database page
|
||||
result2 = runner.invoke(
|
||||
cli, [db_path, "--get", "/{}".format(urllib.parse.quote(filename_no_stem))]
|
||||
)
|
||||
assert result2.exit_code == 0, result2.output
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ 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": r"/extra%20database", "text": "extra database"},
|
||||
] == [{"href": a["href"], "text": a.text.strip()} for a in soup.select("h2 a")]
|
||||
# The first attached database should show count text and attached tables
|
||||
h2 = soup.select("h2")[1]
|
||||
|
|
@ -44,8 +44,8 @@ def test_homepage(app_client_two_attached_databases):
|
|||
{"href": a["href"], "text": a.text.strip()} for a in links_p.findAll("a")
|
||||
]
|
||||
assert [
|
||||
{"href": "/extra database/searchable", "text": "searchable"},
|
||||
{"href": "/extra database/searchable_view", "text": "searchable_view"},
|
||||
{"href": r"/extra%20database/searchable", "text": "searchable"},
|
||||
{"href": r"/extra%20database/searchable_view", "text": "searchable_view"},
|
||||
] == table_links
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -103,9 +103,9 @@ def test_logout(ds, base_url, expected):
|
|||
@pytest.mark.parametrize(
|
||||
"base_url,format,expected",
|
||||
[
|
||||
("/", None, "/:memory:"),
|
||||
("/prefix/", None, "/prefix/:memory:"),
|
||||
("/", "json", "/:memory:.json"),
|
||||
("/", None, "/%3Amemory%3A"),
|
||||
("/prefix/", None, "/prefix/%3Amemory%3A"),
|
||||
("/", "json", "/%3Amemory%3A.json"),
|
||||
],
|
||||
)
|
||||
def test_database(ds, base_url, format, expected):
|
||||
|
|
@ -118,10 +118,10 @@ def test_database(ds, base_url, format, expected):
|
|||
@pytest.mark.parametrize(
|
||||
"base_url,name,format,expected",
|
||||
[
|
||||
("/", "name", None, "/:memory:/name"),
|
||||
("/prefix/", "name", None, "/prefix/:memory:/name"),
|
||||
("/", "name", "json", "/:memory:/name.json"),
|
||||
("/", "name.json", "json", "/:memory:/name.json?_format=json"),
|
||||
("/", "name", None, "/%3Amemory%3A/name"),
|
||||
("/prefix/", "name", None, "/prefix/%3Amemory%3A/name"),
|
||||
("/", "name", "json", "/%3Amemory%3A/name.json"),
|
||||
("/", "name.json", "json", "/%3Amemory%3A/name.json?_format=json"),
|
||||
],
|
||||
)
|
||||
def test_table_and_query(ds, base_url, name, format, expected):
|
||||
|
|
@ -137,9 +137,9 @@ def test_table_and_query(ds, base_url, name, format, expected):
|
|||
@pytest.mark.parametrize(
|
||||
"base_url,format,expected",
|
||||
[
|
||||
("/", None, "/:memory:/facetable/1"),
|
||||
("/prefix/", None, "/prefix/:memory:/facetable/1"),
|
||||
("/", "json", "/:memory:/facetable/1.json"),
|
||||
("/", None, "/%3Amemory%3A/facetable/1"),
|
||||
("/prefix/", None, "/prefix/%3Amemory%3A/facetable/1"),
|
||||
("/", "json", "/%3Amemory%3A/facetable/1.json"),
|
||||
],
|
||||
)
|
||||
def test_row(ds, base_url, format, expected):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue