mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Request.fake(... url_vars), plus .fake() is now documented
Also made 'from datasette import Request' shortcut work. Closes #1697
This commit is contained in:
parent
e73fa72917
commit
5c5e9b3657
4 changed files with 38 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from datasette.version import __version_info__, __version__ # noqa
|
||||
from datasette.utils.asgi import Forbidden, NotFound, Response # noqa
|
||||
from datasette.utils.asgi import Forbidden, NotFound, Request, Response # noqa
|
||||
from datasette.utils import actor_matches_allow # noqa
|
||||
from .hookspecs import hookimpl # noqa
|
||||
from .hookspecs import hookspec # noqa
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ class Request:
|
|||
return dict(parse_qsl(body.decode("utf-8"), keep_blank_values=True))
|
||||
|
||||
@classmethod
|
||||
def fake(cls, path_with_query_string, method="GET", scheme="http"):
|
||||
def fake(cls, path_with_query_string, method="GET", scheme="http", url_vars=None):
|
||||
"""Useful for constructing Request objects for tests"""
|
||||
path, _, query_string = path_with_query_string.partition("?")
|
||||
scope = {
|
||||
|
|
@ -130,6 +130,8 @@ class Request:
|
|||
"scheme": scheme,
|
||||
"type": "http",
|
||||
}
|
||||
if url_vars:
|
||||
scope["url_route"] = {"kwargs": url_vars}
|
||||
return cls(scope, None)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue