mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
New JSON design for query views (#2118)
* Refs #2111, closes #2110 * New Context dataclass/subclass mechanism, refs #2127 * Define QueryContext and extract get_tables() method, refs #2127 * Fix OPTIONS bug by porting DaatbaseView to be a View subclass * Expose async_view_for_class.view_class for test_routes test * Error/truncated aruments for renderers, closes #2130
This commit is contained in:
parent
5139c0886a
commit
1377a290cd
15 changed files with 579 additions and 112 deletions
|
|
@ -1,10 +1,12 @@
|
|||
"""
|
||||
Tests for the datasette.app.Datasette class
|
||||
"""
|
||||
from datasette import Forbidden
|
||||
import dataclasses
|
||||
from datasette import Forbidden, Context
|
||||
from datasette.app import Datasette, Database
|
||||
from itsdangerous import BadSignature
|
||||
import pytest
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -136,6 +138,22 @@ async def test_datasette_render_template_no_request():
|
|||
assert "Error " in rendered
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_datasette_render_template_with_dataclass():
|
||||
@dataclasses.dataclass
|
||||
class ExampleContext(Context):
|
||||
title: str
|
||||
status: int
|
||||
error: str
|
||||
|
||||
context = ExampleContext(title="Hello", status=200, error="Error message")
|
||||
ds = Datasette(memory=True)
|
||||
await ds.invoke_startup()
|
||||
rendered = await ds.render_template("error.html", context)
|
||||
assert "<h1>Hello</h1>" in rendered
|
||||
assert "Error message" in rendered
|
||||
|
||||
|
||||
def test_datasette_error_if_string_not_list(tmpdir):
|
||||
# https://github.com/simonw/datasette/issues/1985
|
||||
db_path = str(tmpdir / "data.db")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue