mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
daab48aaf5
commit
e5dc89a58b
4 changed files with 26 additions and 8 deletions
|
|
@ -203,12 +203,13 @@ class DataView(BaseView):
|
||||||
hash = hash_bit
|
hash = hash_bit
|
||||||
else:
|
else:
|
||||||
name = db_name
|
name = db_name
|
||||||
# Verify the hash
|
name = urllib.parse.unquote_plus(name)
|
||||||
try:
|
try:
|
||||||
db = self.ds.databases[name]
|
db = self.ds.databases[name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise NotFound("Database not found: {}".format(name))
|
raise NotFound("Database not found: {}".format(name))
|
||||||
|
|
||||||
|
# Verify the hash
|
||||||
expected = "000"
|
expected = "000"
|
||||||
if db.hash is not None:
|
if db.hash is not None:
|
||||||
expected = db.hash[:HASH_LENGTH]
|
expected = db.hash[:HASH_LENGTH]
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ def app_client_no_files():
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def app_client_two_attached_databases():
|
def app_client_two_attached_databases():
|
||||||
yield from make_app_client(
|
yield from make_app_client(
|
||||||
extra_databases={"extra_database.db": EXTRA_DATABASE_SQL}
|
extra_databases={"extra database.db": EXTRA_DATABASE_SQL}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -188,7 +188,7 @@ def app_client_conflicting_database_names():
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def app_client_two_attached_databases_one_immutable():
|
def app_client_two_attached_databases_one_immutable():
|
||||||
yield from make_app_client(
|
yield from make_app_client(
|
||||||
is_immutable=True, extra_databases={"extra_database.db": EXTRA_DATABASE_SQL}
|
is_immutable=True, extra_databases={"extra database.db": EXTRA_DATABASE_SQL}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from .fixtures import ( # noqa
|
||||||
app_client_shorter_time_limit,
|
app_client_shorter_time_limit,
|
||||||
app_client_larger_cache_size,
|
app_client_larger_cache_size,
|
||||||
app_client_returned_rows_matches_page_size,
|
app_client_returned_rows_matches_page_size,
|
||||||
|
app_client_two_attached_databases,
|
||||||
app_client_two_attached_databases_one_immutable,
|
app_client_two_attached_databases_one_immutable,
|
||||||
app_client_conflicting_database_names,
|
app_client_conflicting_database_names,
|
||||||
app_client_with_cors,
|
app_client_with_cors,
|
||||||
|
|
@ -1188,7 +1189,7 @@ def test_databases_json(app_client_two_attached_databases_one_immutable):
|
||||||
databases = response.json
|
databases = response.json
|
||||||
assert 2 == len(databases)
|
assert 2 == len(databases)
|
||||||
extra_database, fixtures_database = databases
|
extra_database, fixtures_database = databases
|
||||||
assert "extra_database" == extra_database["name"]
|
assert "extra database" == extra_database["name"]
|
||||||
assert None == extra_database["hash"]
|
assert None == extra_database["hash"]
|
||||||
assert True == extra_database["is_mutable"]
|
assert True == extra_database["is_mutable"]
|
||||||
assert False == extra_database["is_memory"]
|
assert False == extra_database["is_memory"]
|
||||||
|
|
@ -1679,6 +1680,22 @@ def test_cors(app_client_with_cors, path, status_code):
|
||||||
assert "*" == response.headers["Access-Control-Allow-Origin"]
|
assert "*" == response.headers["Access-Control-Allow-Origin"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"path",
|
||||||
|
(
|
||||||
|
"/",
|
||||||
|
".json",
|
||||||
|
"/searchable",
|
||||||
|
"/searchable.json",
|
||||||
|
"/searchable_view",
|
||||||
|
"/searchable_view.json",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_database_with_space_in_name(app_client_two_attached_databases, path):
|
||||||
|
response = app_client_two_attached_databases.get("/extra database" + path)
|
||||||
|
assert response.status == 200
|
||||||
|
|
||||||
|
|
||||||
def test_common_prefix_database_names(app_client_conflicting_database_names):
|
def test_common_prefix_database_names(app_client_conflicting_database_names):
|
||||||
# https://github.com/simonw/datasette/issues/597
|
# https://github.com/simonw/datasette/issues/597
|
||||||
assert ["fixtures", "foo", "foo-bar"] == [
|
assert ["fixtures", "foo", "foo-bar"] == [
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,11 @@ def test_homepage(app_client_two_attached_databases):
|
||||||
# Should be two attached databases
|
# Should be two attached databases
|
||||||
assert [
|
assert [
|
||||||
{"href": "/fixtures", "text": "fixtures"},
|
{"href": "/fixtures", "text": "fixtures"},
|
||||||
{"href": "/extra_database", "text": "extra_database"},
|
{"href": "/extra database", "text": "extra database"},
|
||||||
] == [{"href": a["href"], "text": a.text.strip()} for a in soup.select("h2 a")]
|
] == [{"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
|
# The first attached database should show count text and attached tables
|
||||||
h2 = soup.select("h2")[1]
|
h2 = soup.select("h2")[1]
|
||||||
assert "extra_database" == h2.text.strip()
|
assert "extra database" == h2.text.strip()
|
||||||
counts_p, links_p = h2.find_all_next("p")[:2]
|
counts_p, links_p = h2.find_all_next("p")[:2]
|
||||||
assert (
|
assert (
|
||||||
"2 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()
|
||||||
|
|
@ -41,8 +41,8 @@ def test_homepage(app_client_two_attached_databases):
|
||||||
{"href": a["href"], "text": a.text.strip()} for a in links_p.findAll("a")
|
{"href": a["href"], "text": a.text.strip()} for a in links_p.findAll("a")
|
||||||
]
|
]
|
||||||
assert [
|
assert [
|
||||||
{"href": "/extra_database/searchable", "text": "searchable"},
|
{"href": "/extra database/searchable", "text": "searchable"},
|
||||||
{"href": "/extra_database/searchable_view", "text": "searchable_view"},
|
{"href": "/extra database/searchable_view", "text": "searchable_view"},
|
||||||
] == table_links
|
] == table_links
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue