Skip to content

Commit

Permalink
Test illustrating POST against register_routes(), closes #853
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 18, 2020
1 parent a4ad5a5 commit d2aef9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/plugins/my_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<name>.*)$", two),
(r"/three/$", three),
(r"/post/$", post),
]


Expand Down
7 changes: 7 additions & 0 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d2aef9f

Please sign in to comment.