mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
--metadata accepts YAML as well as JSON - closes #713
This commit is contained in:
parent
2aaad72789
commit
6717c719dd
12 changed files with 149 additions and 25 deletions
|
|
@ -1,8 +1,10 @@
|
|||
from .fixtures import app_client, make_app_client
|
||||
from datasette.cli import cli
|
||||
from .fixtures import app_client, make_app_client, TestClient as _TestClient
|
||||
from datasette.cli import cli, serve
|
||||
from click.testing import CliRunner
|
||||
import pathlib
|
||||
import io
|
||||
import json
|
||||
import pathlib
|
||||
import textwrap
|
||||
|
||||
|
||||
def test_inspect_cli(app_client):
|
||||
|
|
@ -46,3 +48,38 @@ def test_spatialite_error_if_attempt_to_open_spatialite():
|
|||
)
|
||||
assert result.exit_code != 0
|
||||
assert "trying to load a SpatiaLite database" in result.output
|
||||
|
||||
|
||||
def test_metadata_yaml():
|
||||
yaml_file = io.StringIO(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
title: Hello from YAML
|
||||
"""
|
||||
)
|
||||
)
|
||||
# Annoyingly we have to provide all default arguments here:
|
||||
ds = serve.callback(
|
||||
[],
|
||||
metadata=yaml_file,
|
||||
immutable=[],
|
||||
host="127.0.0.1",
|
||||
port=8001,
|
||||
debug=False,
|
||||
reload=False,
|
||||
cors=False,
|
||||
sqlite_extensions=[],
|
||||
inspect_file=None,
|
||||
template_dir=None,
|
||||
plugins_dir=None,
|
||||
static=[],
|
||||
memory=False,
|
||||
config=[],
|
||||
version_note=None,
|
||||
help_config=False,
|
||||
return_instance=True,
|
||||
)
|
||||
client = _TestClient(ds.app())
|
||||
client.ds = ds
|
||||
response = client.get("/-/metadata.json")
|
||||
assert {"title": "Hello from YAML"} == response.json
|
||||
|
|
|
|||
|
|
@ -146,12 +146,15 @@ def test_publish_cloudrun_plugin_secrets(mock_call, mock_output, mock_which):
|
|||
runner = CliRunner()
|
||||
with runner.isolated_filesystem():
|
||||
open("test.db", "w").write("data")
|
||||
open("metadata.yml", "w").write("title: Hello from metadata YAML")
|
||||
result = runner.invoke(
|
||||
cli.cli,
|
||||
[
|
||||
"publish",
|
||||
"cloudrun",
|
||||
"test.db",
|
||||
"--metadata",
|
||||
"metadata.yml",
|
||||
"--service",
|
||||
"datasette",
|
||||
"--plugin-secret",
|
||||
|
|
@ -183,9 +186,10 @@ CMD datasette serve --host 0.0.0.0 -i test.db --cors --inspect-file inspect-data
|
|||
.strip()
|
||||
)
|
||||
assert {
|
||||
"title": "Hello from metadata YAML",
|
||||
"plugins": {
|
||||
"datasette-auth-github": {
|
||||
"client_id": {"$env": "DATASETTE_AUTH_GITHUB_CLIENT_ID"}
|
||||
}
|
||||
}
|
||||
},
|
||||
} == json.loads(metadata)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue