.add_message() now works inside plugins, closes #864

Refs #870
This commit is contained in:
Simon Willison 2020-06-28 17:25:35 -07:00
commit 7ac4936cec
4 changed files with 32 additions and 17 deletions

View file

@ -190,6 +190,12 @@ def register_routes():
def not_async():
return Response.html("This was not async")
def add_message(datasette, request):
datasette.add_message(request, "Hello from messages")
print("Adding message")
print(request._messages)
return Response.html("Added message")
return [
(r"/one/$", one),
(r"/two/(?P<name>.*)$", two),
@ -197,6 +203,7 @@ def register_routes():
(r"/post/$", post),
(r"/csrftoken-form/$", csrftoken_form),
(r"/not-async/$", not_async),
(r"/add-message/$", add_message),
]

View file

@ -602,6 +602,14 @@ def test_register_routes_asgi(app_client):
assert "1" == response.headers["x-three"]
def test_register_routes_add_message(app_client):
response = app_client.get("/add-message/")
assert 200 == response.status
assert "Added message" == response.text
decoded = app_client.ds.unsign(response.cookies["ds_messages"], "messages")
assert [["Hello from messages", 1]] == decoded
@pytest.mark.asyncio
async def test_startup(app_client):
await app_client.ds.invoke_startup()