kopia lustrzana https://github.com/simonw/datasette
rodzic
eff112498e
commit
b7fec7f902
|
@ -217,7 +217,10 @@ class Datasette:
|
||||||
self._secret = secret or secrets.token_hex(32)
|
self._secret = secret or secrets.token_hex(32)
|
||||||
self.files = tuple(files or []) + tuple(immutables or [])
|
self.files = tuple(files or []) + tuple(immutables or [])
|
||||||
if config_dir:
|
if config_dir:
|
||||||
self.files += tuple([str(p) for p in config_dir.glob("*.db")])
|
db_files = []
|
||||||
|
for ext in ("db", "sqlite", "sqlite3"):
|
||||||
|
db_files.extend(config_dir.glob("*.{}".format(ext)))
|
||||||
|
self.files += tuple(str(f) for f in db_files)
|
||||||
if (
|
if (
|
||||||
config_dir
|
config_dir
|
||||||
and (config_dir / "inspect-data.json").exists()
|
and (config_dir / "inspect-data.json").exists()
|
||||||
|
|
|
@ -46,7 +46,7 @@ Datasette will detect the files in that directory and automatically configure it
|
||||||
|
|
||||||
The files that can be included in this directory are as follows. All are optional.
|
The files that can be included in this directory are as follows. All are optional.
|
||||||
|
|
||||||
* ``*.db`` - SQLite database files that will be served by Datasette
|
* ``*.db`` (or ``*.sqlite3`` or ``*.sqlite``) - SQLite database files that will be served by Datasette
|
||||||
* ``metadata.json`` - :ref:`metadata` for those databases - ``metadata.yaml`` or ``metadata.yml`` can be used as well
|
* ``metadata.json`` - :ref:`metadata` for those databases - ``metadata.yaml`` or ``metadata.yml`` can be used as well
|
||||||
* ``inspect-data.json`` - the result of running ``datasette inspect *.db --inspect-file=inspect-data.json`` from the configuration directory - any database files listed here will be treated as immutable, so they should not be changed while Datasette is running
|
* ``inspect-data.json`` - the result of running ``datasette inspect *.db --inspect-file=inspect-data.json`` from the configuration directory - any database files listed here will be treated as immutable, so they should not be changed while Datasette is running
|
||||||
* ``settings.json`` - settings that would normally be passed using ``--setting`` - here they should be stored as a JSON object of key/value pairs
|
* ``settings.json`` - settings that would normally be passed using ``--setting`` - here they should be stored as a JSON object of key/value pairs
|
||||||
|
|
|
@ -49,7 +49,7 @@ def config_dir(tmp_path_factory):
|
||||||
(config_dir / "metadata.json").write_text(json.dumps(METADATA), "utf-8")
|
(config_dir / "metadata.json").write_text(json.dumps(METADATA), "utf-8")
|
||||||
(config_dir / "settings.json").write_text(json.dumps(SETTINGS), "utf-8")
|
(config_dir / "settings.json").write_text(json.dumps(SETTINGS), "utf-8")
|
||||||
|
|
||||||
for dbname in ("demo.db", "immutable.db"):
|
for dbname in ("demo.db", "immutable.db", "j.sqlite3", "k.sqlite"):
|
||||||
db = sqlite3.connect(str(config_dir / dbname))
|
db = sqlite3.connect(str(config_dir / dbname))
|
||||||
db.executescript(
|
db.executescript(
|
||||||
"""
|
"""
|
||||||
|
@ -151,12 +151,11 @@ def test_databases(config_dir_client):
|
||||||
response = config_dir_client.get("/-/databases.json")
|
response = config_dir_client.get("/-/databases.json")
|
||||||
assert 200 == response.status
|
assert 200 == response.status
|
||||||
databases = response.json
|
databases = response.json
|
||||||
assert 2 == len(databases)
|
assert 4 == len(databases)
|
||||||
databases.sort(key=lambda d: d["name"])
|
databases.sort(key=lambda d: d["name"])
|
||||||
assert "demo" == databases[0]["name"]
|
for db, expected_name in zip(databases, ("demo", "immutable", "j", "k")):
|
||||||
assert databases[0]["is_mutable"]
|
assert expected_name == db["name"]
|
||||||
assert "immutable" == databases[1]["name"]
|
assert db["is_mutable"] == (expected_name != "immutable")
|
||||||
assert not databases[1]["is_mutable"]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("filename", ("metadata.yml", "metadata.yaml"))
|
@pytest.mark.parametrize("filename", ("metadata.yml", "metadata.yaml"))
|
||||||
|
|
Ładowanie…
Reference in New Issue