kopia lustrzana https://github.com/simonw/datasette
datasette --get status code for error pages, closes #947
rodzic
77521c6cd7
commit
d02f6151da
|
@ -444,6 +444,8 @@ def serve(
|
||||||
client = TestClient(ds.app())
|
client = TestClient(ds.app())
|
||||||
response = client.get(get)
|
response = client.get(get)
|
||||||
click.echo(response.text)
|
click.echo(response.text)
|
||||||
|
exit_code = 0 if response.status == 200 else 1
|
||||||
|
sys.exit(exit_code)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Start the server
|
# Start the server
|
||||||
|
|
|
@ -155,6 +155,8 @@ The ``--get`` option can specify the path to a page within Datasette and cause D
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
The exit code will be 0 if the request succeeds and 1 if the request produced an HTTP status code other than 200 - e.g. a 404 or 500 error. This means you can use ``datasette --get /`` to run tests against a Datasette application in a continuous integration environment such as GitHub Actions.
|
||||||
|
|
||||||
.. _getting_started_serve_help:
|
.. _getting_started_serve_help:
|
||||||
|
|
||||||
datasette serve --help
|
datasette serve --help
|
||||||
|
|
|
@ -39,6 +39,7 @@ def test_serve_with_get(tmp_path_factory):
|
||||||
"truncated": False,
|
"truncated": False,
|
||||||
"columns": ["sqlite_version()"],
|
"columns": ["sqlite_version()"],
|
||||||
}.items() <= json.loads(result.output).items()
|
}.items() <= json.loads(result.output).items()
|
||||||
|
|
||||||
# The plugin should have created hello.txt
|
# The plugin should have created hello.txt
|
||||||
assert (plugins_dir / "hello.txt").read_text() == "hello"
|
assert (plugins_dir / "hello.txt").read_text() == "hello"
|
||||||
|
|
||||||
|
@ -48,3 +49,18 @@ def test_serve_with_get(tmp_path_factory):
|
||||||
p for p in pm.get_plugins() if p.__name__ == "init_for_serve_with_get.py"
|
p for p in pm.get_plugins() if p.__name__ == "init_for_serve_with_get.py"
|
||||||
][0]
|
][0]
|
||||||
pm.unregister(to_unregister)
|
pm.unregister(to_unregister)
|
||||||
|
|
||||||
|
|
||||||
|
def test_serve_with_get_exit_code_for_error(tmp_path_factory):
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(
|
||||||
|
cli,
|
||||||
|
[
|
||||||
|
"serve",
|
||||||
|
"--memory",
|
||||||
|
"--get",
|
||||||
|
"/this-is-404",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 1
|
||||||
|
assert "404" in result.output
|
||||||
|
|
Ładowanie…
Reference in New Issue