Documentation for Datasette() constructor, closes #1563

pull/1589/head
Simon Willison 2021-12-17 18:19:36 -08:00
rodzic 3a0cae4d7f
commit 7c8f8aa209
2 zmienionych plików z 22 dodań i 1 usunięć

Wyświetl plik

@ -196,6 +196,27 @@ Datasette class
This object is an instance of the ``Datasette`` class, passed to many plugin hooks as an argument called ``datasette``.
You can create your own instance of this - for example to help write tests for a plugin - like so:
.. code-block:: python
from datasette.app import Datasette
# With no arguments a single in-memory database will be attached
datasette = Datasette()
# The files= argument can load files from disk
datasette = Datasette(files="/path/to/my-database.db")
# Pass metadata as a JSON dictionary like this
datasette = Datasette(files="/path/to/my-database.db", metadata={
"databases": {
"my-database": {
"description": "This is my database"
}
}
})
.. _datasette_databases:
.databases

Wyświetl plik

@ -50,7 +50,7 @@ def test_datasette_setting(datasette, setting, expected):
@pytest.mark.asyncio
async def test_datasette_constructor():
ds = Datasette(memory=True)
ds = Datasette()
databases = (await ds.client.get("/-/databases.json")).json()
assert databases == [
{