From d2aef9f7ef30fa20b1450cd181cf803f44fb4e21 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 18 Jun 2020 09:21:15 -0700 Subject: [PATCH] Test illustrating POST against register_routes(), closes #853 --- tests/plugins/my_plugin.py | 7 +++++++ tests/test_plugins.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/tests/plugins/my_plugin.py b/tests/plugins/my_plugin.py index 3f019a8411..72736e84b8 100644 --- a/tests/plugins/my_plugin.py +++ b/tests/plugins/my_plugin.py @@ -162,10 +162,17 @@ async def three(scope, send): send, {"hello": "world"}, status=200, headers={"x-three": "1"} ) + async def post(request): + if request.method == "GET": + return Response.html(request.scope["csrftoken"]()) + else: + return Response.json(await request.post_vars()) + return [ (r"/one/$", one), (r"/two/(?P.*)$", two), (r"/three/$", three), + (r"/post/$", post), ] diff --git a/tests/test_plugins.py b/tests/test_plugins.py index bc759385a2..e3a234f2df 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -568,6 +568,13 @@ def test_register_routes(app_client, path, body): assert body == response.text +def test_register_routes_post(app_client): + response = app_client.post("/post/", {"this is": "post data"}, csrftoken_from=True) + assert 200 == response.status + assert "csrftoken" in response.json + assert "post data" == response.json["this is"] + + def test_register_routes_asgi(app_client): response = app_client.get("/three/") assert {"hello": "world"} == response.json