mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
d9aad1fd04
commit
d8351b08ed
3 changed files with 21 additions and 3 deletions
|
|
@ -439,6 +439,10 @@ def uninstall(packages, yes):
|
||||||
"--token",
|
"--token",
|
||||||
help="API token to send with --get requests",
|
help="API token to send with --get requests",
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"--actor",
|
||||||
|
help="Actor to use for --get requests (JSON string)",
|
||||||
|
)
|
||||||
@click.option("--version-note", help="Additional note to show on /-/versions")
|
@click.option("--version-note", help="Additional note to show on /-/versions")
|
||||||
@click.option("--help-settings", is_flag=True, help="Show available settings")
|
@click.option("--help-settings", is_flag=True, help="Show available settings")
|
||||||
@click.option("--pdb", is_flag=True, help="Launch debugger on any errors")
|
@click.option("--pdb", is_flag=True, help="Launch debugger on any errors")
|
||||||
|
|
@ -493,6 +497,7 @@ def serve(
|
||||||
root,
|
root,
|
||||||
get,
|
get,
|
||||||
token,
|
token,
|
||||||
|
actor,
|
||||||
version_note,
|
version_note,
|
||||||
help_settings,
|
help_settings,
|
||||||
pdb,
|
pdb,
|
||||||
|
|
@ -612,7 +617,10 @@ def serve(
|
||||||
headers = {}
|
headers = {}
|
||||||
if token:
|
if token:
|
||||||
headers["Authorization"] = "Bearer {}".format(token)
|
headers["Authorization"] = "Bearer {}".format(token)
|
||||||
response = client.get(get, headers=headers)
|
cookies = {}
|
||||||
|
if actor:
|
||||||
|
cookies["ds_actor"] = client.actor_cookie(json.loads(actor))
|
||||||
|
response = client.get(get, headers=headers, cookies=cookies)
|
||||||
click.echo(response.text)
|
click.echo(response.text)
|
||||||
exit_code = 0 if response.status == 200 else 1
|
exit_code = 0 if response.status == 200 else 1
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_code)
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@ Once started you can access it at ``http://localhost:8001``
|
||||||
--get TEXT Run an HTTP GET request against this path,
|
--get TEXT Run an HTTP GET request against this path,
|
||||||
print results and exit
|
print results and exit
|
||||||
--token TEXT API token to send with --get requests
|
--token TEXT API token to send with --get requests
|
||||||
|
--actor TEXT Actor to use for --get requests (JSON string)
|
||||||
--version-note TEXT Additional note to show on /-/versions
|
--version-note TEXT Additional note to show on /-/versions
|
||||||
--help-settings Show available settings
|
--help-settings Show available settings
|
||||||
--pdb Launch debugger on any errors
|
--pdb Launch debugger on any errors
|
||||||
|
|
@ -148,7 +149,9 @@ The ``--get`` option to ``datasette serve`` (or just ``datasette``) specifies th
|
||||||
|
|
||||||
This means that all of Datasette's functionality can be accessed directly from the command-line.
|
This means that all of Datasette's functionality can be accessed directly from the command-line.
|
||||||
|
|
||||||
For example::
|
For example:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
datasette --get '/-/versions.json' | jq .
|
datasette --get '/-/versions.json' | jq .
|
||||||
|
|
||||||
|
|
@ -194,7 +197,13 @@ For example::
|
||||||
|
|
||||||
You can use the ``--token TOKEN`` option to send an :ref:`API token <CreateTokenView>` with the simulated request.
|
You can use the ``--token TOKEN`` option to send an :ref:`API token <CreateTokenView>` with the simulated request.
|
||||||
|
|
||||||
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.
|
Or you can make a request as a specific actor by passing a JSON representation of that actor to ``--actor``:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
datasette --memory --actor '{"id": "root"}' --get '/-/actor.json'
|
||||||
|
|
||||||
|
The exit code of ``datasette --get`` 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 lets you use ``datasette --get /`` to run tests against a Datasette application in a continuous integration environment such as GitHub Actions.
|
This lets you use ``datasette --get /`` to run tests against a Datasette application in a continuous integration environment such as GitHub Actions.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,7 @@ def test_metadata_yaml():
|
||||||
secret=None,
|
secret=None,
|
||||||
root=False,
|
root=False,
|
||||||
token=None,
|
token=None,
|
||||||
|
actor=None,
|
||||||
version_note=None,
|
version_note=None,
|
||||||
get=None,
|
get=None,
|
||||||
help_settings=False,
|
help_settings=False,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue