quart.testing 包#
子模块#
- quart.testing.app 模块
- quart.testing.client 模块
QuartClient
QuartClient.delete()
QuartClient.delete_cookie()
QuartClient.get()
QuartClient.head()
QuartClient.http_connection_class
QuartClient.open()
QuartClient.options()
QuartClient.patch()
QuartClient.post()
QuartClient.put()
QuartClient.request()
QuartClient.session_transaction()
QuartClient.set_cookie()
QuartClient.trace()
QuartClient.websocket()
QuartClient.websocket_connection_class
- quart.testing.connections 模块
- quart.testing.utils 模块
模块内容#
- class quart.testing.QuartCliRunner(app: Quart, **kwargs: Any)#
Bases:
CliRunner
- invoke(cli: Any = None, args: Any = None, **kwargs: Any) Any #
在隔离的环境中调用命令。参数直接转发到命令行脚本,extra 关键字参数传递给命令的
main()
函数。这将返回一个
Result
对象。- 参数:
cli – 要调用的命令
args – 要调用的参数。它可以作为可迭代对象或字符串给出。当作为字符串给出时,它将被解释为 Unix shell 命令。更多细节请参见
shlex.split()
。input – sys.stdin 的输入数据。
env – 环境覆盖。
catch_exceptions – 是否捕获除
SystemExit
之外的任何其他异常。extra – 传递给
main()
的关键字参数。color – 输出是否应包含颜色代码。应用程序仍然可以明确地覆盖此项。
在版本 8.0 中更改: 结果对象具有包含从调用的命令返回的值的
return_value
属性。在版本 4.0 中更改: 添加了
color
参数。在版本 3.0 中更改: 添加了
catch_exceptions
参数。在版本 3.0 中更改: 结果对象具有
exc_info
属性,其中包含可用的跟踪信息。
- class quart.testing.QuartClient(app: Quart, use_cookies: bool = True)#
Bases:
object
- delete_cookie(server_name: str, key: str, path: str = '/', domain: str | None = None) None #
删除一个 cookie(设置为立即过期)。
- http_connection_class#
- async open(path: str, *, method: str = 'GET', headers: dict | ~werkzeug.datastructures.headers.Headers | None = None, data: AnyStr | None = None, form: dict | None = None, files: dict[str, ~quart.datastructures.FileStorage] | None = None, query_string: dict | None = None, json: ~typing.Any = <object object>, scheme: str = 'http', follow_redirects: bool = False, root_path: str = '', http_version: str = '1.1', scope_base: dict | None = None, auth: ~werkzeug.datastructures.auth.Authorization | tuple[str, str] | None = None, subdomain: str | None = None) Response #
- request(path: str, *, method: str = 'GET', headers: dict | Headers | None = None, query_string: dict | None = None, scheme: str = 'http', root_path: str = '', http_version: str = '1.1', scope_base: dict | None = None, auth: Authorization | tuple[str, str] | None = None, subdomain: str | None = None) TestHTTPConnectionProtocol #
- session_transaction(path: str = '/', *, method: str = 'GET', headers: dict | ~werkzeug.datastructures.headers.Headers | None = None, query_string: dict | None = None, scheme: str = 'http', data: AnyStr | None = None, form: dict | None = None, json: ~typing.Any = <object object>, root_path: str = '', http_version: str = '1.1', auth: ~werkzeug.datastructures.auth.Authorization | tuple[str, str] | None = None) AsyncGenerator[SessionMixin, None] #
- set_cookie(server_name: str, key: str, value: str = '', max_age: int | timedelta | None = None, expires: int | float | datetime | None = None, path: str = '/', domain: str | None = None, secure: bool = False, httponly: bool = False, samesite: str = None) None #
在 cookie 罐中设置 cookie。
参数是标准 cookie 块,这是一个围绕 stdlib SimpleCookie 代码的包装器。
- websocket(path: str, *, headers: dict | Headers | None = None, query_string: dict | None = None, scheme: str = 'ws', subprotocols: list[str] | None = None, root_path: str = '', http_version: str = '1.1', scope_base: dict | None = None, auth: Authorization | tuple[str, str] | None = None, subdomain: str | None = None) TestWebsocketConnectionProtocol #
- websocket_connection_class#
- class quart.testing.TestApp(app: Quart, startup_timeout: int = 6, shutdown_timeout: int = 6)#
Bases:
object
- async shutdown() None #
- async startup() None #
- test_client() TestClientProtocol #
- quart.testing.make_test_body_with_headers(*, data: AnyStr | None = None, form: dict | None = None, files: dict[str, FileStorage] | None = None, json: Any = <object object>, app: Quart | None = None) tuple[bytes, Headers] #
创建带有相关标头的正文字节。
- 参数:
data – 发送到请求正文中的原始数据。
form – 发送到请求正文中以表单编码形式的键值对数据。
files – 发送到请求正文中以文件编码形式的键值对数据。
json – 发送到请求正文中以 JSON 编码形式的数据。
- quart.testing.make_test_headers_path_and_query_string(app: Quart, path: str, headers: dict | Headers | None = None, query_string: dict | None = None, auth: Authorization | tuple[str, str] | None = None, subdomain: str | None = None) tuple[Headers, str, bytes] #
用于测试的默认请求头、路径和查询字符串。
- 参数:
app – 要测试的应用程序。
path – 要请求的路径。如果未定义 query_string 参数,则此参数将在 ‘?’ 上进行分割,后面的部分将被视为查询字符串。
headers – 要发送的初始请求头。
query_string – 以字典形式发送,或者可以从路径中确定查询字符串。
- quart.testing.make_test_scope(type_: str, path: str, method: str, headers: Headers, query_string: bytes, scheme: str, root_path: str, http_version: str, scope_base: dict | None, *, _preserve_context: bool = False) HTTPScope | WebsocketScope | LifespanScope #
- async quart.testing.no_op_push(path: str, headers: Headers) None #
一个什么也不做的 push promise 发送器。
这最适合在 QuartClient 之外创建 Request 实例进行测试时使用。Request 实例必须知道如何处理 push promise,而这为它提供了什么也不做的选择。