mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
request.url_vars property, closes #822
This commit is contained in:
parent
db660db463
commit
fac8e93815
5 changed files with 28 additions and 4 deletions
|
|
@ -152,8 +152,8 @@ def register_routes():
|
|||
(await datasette.get_database().execute("select 1 + 1")).first()[0]
|
||||
)
|
||||
|
||||
async def two(request, scope):
|
||||
name = scope["url_route"]["kwargs"]["name"]
|
||||
async def two(request):
|
||||
name = request.url_vars["name"]
|
||||
greeting = request.args.get("greeting")
|
||||
return Response.text("{} {}".format(greeting, name))
|
||||
|
||||
|
|
|
|||
|
|
@ -44,3 +44,20 @@ def test_request_args():
|
|||
assert 2 == len(request.args)
|
||||
with pytest.raises(KeyError):
|
||||
request.args["missing"]
|
||||
|
||||
|
||||
def test_request_url_vars():
|
||||
scope = {
|
||||
"http_version": "1.1",
|
||||
"method": "POST",
|
||||
"path": "/",
|
||||
"raw_path": b"/",
|
||||
"query_string": b"",
|
||||
"scheme": "http",
|
||||
"type": "http",
|
||||
"headers": [[b"content-type", b"application/x-www-form-urlencoded"]],
|
||||
}
|
||||
assert {} == Request(scope, None).url_vars
|
||||
assert {"name": "cleo"} == Request(
|
||||
dict(scope, url_route={"kwargs": {"name": "cleo"}}), None
|
||||
).url_vars
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue