Create a request context for testing purposes. This is best used for testing code within request contexts. It is a simplified wrapper of :meth:`request_context`. It is best used in a with block, i.e. .. code-block:: python async with app.test_request_co
(
self,
path: str,
*,
method: str = "GET",
headers: dict | Headers | None = None,
query_string: dict | None = None,
scheme: str = "http",
send_push_promise: Callable[[str, Headers], Awaitable[None]] = no_op_push,
data: AnyStr | None = None,
form: dict | None = None,
json: Any = sentinel,
root_path: str = "",
http_version: str = "1.1",
scope_base: dict | None = None,
auth: Authorization | tuple[str, str] | None = None,
subdomain: str | None = None,
)
| 1294 | return self.test_app_class(self) |
| 1295 | |
| 1296 | def test_request_context( |
| 1297 | self, |
| 1298 | path: str, |
| 1299 | *, |
| 1300 | method: str = "GET", |
| 1301 | headers: dict | Headers | None = None, |
| 1302 | query_string: dict | None = None, |
| 1303 | scheme: str = "http", |
| 1304 | send_push_promise: Callable[[str, Headers], Awaitable[None]] = no_op_push, |
| 1305 | data: AnyStr | None = None, |
| 1306 | form: dict | None = None, |
| 1307 | json: Any = sentinel, |
| 1308 | root_path: str = "", |
| 1309 | http_version: str = "1.1", |
| 1310 | scope_base: dict | None = None, |
| 1311 | auth: Authorization | tuple[str, str] | None = None, |
| 1312 | subdomain: str | None = None, |
| 1313 | ) -> RequestContext: |
| 1314 | """Create a request context for testing purposes. |
| 1315 | |
| 1316 | This is best used for testing code within request contexts. It |
| 1317 | is a simplified wrapper of :meth:`request_context`. It is best |
| 1318 | used in a with block, i.e. |
| 1319 | |
| 1320 | .. code-block:: python |
| 1321 | |
| 1322 | async with app.test_request_context("/", method="GET"): |
| 1323 | ... |
| 1324 | |
| 1325 | Arguments: |
| 1326 | path: Request path. |
| 1327 | method: HTTP verb |
| 1328 | headers: Headers to include in the request. |
| 1329 | query_string: To send as a dictionary, alternatively the |
| 1330 | query_string can be determined from the path. |
| 1331 | scheme: Scheme for the request, default http. |
| 1332 | """ |
| 1333 | headers, path, query_string_bytes = make_test_headers_path_and_query_string( |
| 1334 | self, |
| 1335 | path, |
| 1336 | headers, |
| 1337 | query_string, |
| 1338 | auth, |
| 1339 | subdomain, |
| 1340 | ) |
| 1341 | request_body, body_headers = make_test_body_with_headers( |
| 1342 | data=data, form=form, json=json |
| 1343 | ) |
| 1344 | headers.update(**body_headers) |
| 1345 | scope = make_test_scope( |
| 1346 | "http", |
| 1347 | path, |
| 1348 | method, |
| 1349 | headers, |
| 1350 | query_string_bytes, |
| 1351 | scheme, |
| 1352 | root_path, |
| 1353 | http_version, |
no test coverage detected