Test Client¶
Warning
The current page still doesn't have a translation for this language.
But you can help translating it: Contributing.
Esmerald offers an extension of the Lilya TestClient
called EsmeraldTestClient
as well
as a create_client
that can be used for context testing.
from esmerald.testclient import EsmeraldTestClient
esmerald.testclient.EsmeraldTestClient
¶
EsmeraldTestClient(app, base_url='http://testserver', raise_server_exceptions=True, root_path='', backend='asyncio', backend_options=None, cookies=None, headers=None)
Bases: TestClient
PARAMETER | DESCRIPTION |
---|---|
app
|
TYPE:
|
base_url
|
TYPE:
|
raise_server_exceptions
|
TYPE:
|
root_path
|
TYPE:
|
backend
|
TYPE:
|
backend_options
|
TYPE:
|
cookies
|
TYPE:
|
headers
|
TYPE:
|
Source code in esmerald/testclient.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
auth
property
writable
¶
auth
Authentication class used when none is passed at the request-level.
See also Authentication.
async_backend
instance-attribute
¶
async_backend = AsyncBackend(backend=backend, backend_options=backend_options or {})
build_request
¶
build_request(method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, timeout=USE_CLIENT_DEFAULT, extensions=None)
Build and return a request instance.
- The
params
,headers
andcookies
arguments are merged with any values set on the client. - The
url
argument is merged with anybase_url
set on the client.
See also: Request instances
PARAMETER | DESCRIPTION |
---|---|
method
|
TYPE:
|
url
|
TYPE:
|
content
|
TYPE:
|
data
|
TYPE:
|
files
|
TYPE:
|
json
|
TYPE:
|
params
|
TYPE:
|
headers
|
TYPE:
|
cookies
|
TYPE:
|
timeout
|
TYPE:
|
extensions
|
TYPE:
|
Source code in httpx/_client.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
request
¶
request(method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=USE_CLIENT_DEFAULT, follow_redirects=None, timeout=USE_CLIENT_DEFAULT, extensions=None)
Sends an HTTP request.
PARAMETER | DESCRIPTION |
---|---|
method
|
TYPE:
|
url
|
TYPE:
|
content
|
TYPE:
|
data
|
TYPE:
|
files
|
TYPE:
|
json
|
TYPE:
|
params
|
TYPE:
|
headers
|
TYPE:
|
cookies
|
TYPE:
|
auth
|
TYPE:
|
follow_redirects
|
TYPE:
|
timeout
|
TYPE:
|
extensions
|
TYPE:
|
PARAMETER | DESCRIPTION |
---|---|
method
|
The HTTP method.
TYPE:
|
url
|
The URL to send the request to.
TYPE:
|
content
|
The request content. Defaults to None.
TYPE:
|
data
|
The request data. Defaults to None.
TYPE:
|
files
|
The request files. Defaults to None.
TYPE:
|
json
|
The request JSON. Defaults to None.
TYPE:
|
params
|
The request query parameters. Defaults to None.
TYPE:
|
headers
|
The request headers. Defaults to None.
TYPE:
|
cookies
|
The request cookies. Defaults to None.
TYPE:
|
auth
|
The request authentication. Defaults to httpx._client.USE_CLIENT_DEFAULT.
TYPE:
|
follow_redirects
|
Whether to follow redirects. Defaults to None.
TYPE:
|
timeout
|
The request timeout. Defaults to httpx._client.USE_CLIENT_DEFAULT.
TYPE:
|
extensions
|
The request extensions. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Response
|
httpx.Response: The HTTP response. |
Source code in lilya/testclient/base.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
stream
¶
stream(method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT, timeout=USE_CLIENT_DEFAULT, extensions=None)
Alternative to httpx.request()
that streams the response body
instead of loading it into memory at once.
Parameters: See httpx.request
.
See also: Streaming Responses
PARAMETER | DESCRIPTION |
---|---|
method
|
TYPE:
|
url
|
TYPE:
|
content
|
TYPE:
|
data
|
TYPE:
|
files
|
TYPE:
|
json
|
TYPE:
|
params
|
TYPE:
|
headers
|
TYPE:
|
cookies
|
TYPE:
|
auth
|
TYPE:
|
follow_redirects
|
TYPE:
|
timeout
|
TYPE:
|
extensions
|
TYPE:
|
YIELDS | DESCRIPTION |
---|---|
Response
|
|
Source code in httpx/_client.py
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 |
|
send
¶
send(request, *, stream=False, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT)
Send a request.
The request is sent as-is, unmodified.
Typically you'll want to build one with Client.build_request()
so that any client-level configuration is merged into the request,
but passing an explicit httpx.Request()
is supported as well.
See also: Request instances
PARAMETER | DESCRIPTION |
---|---|
request
|
TYPE:
|
stream
|
TYPE:
|
auth
|
TYPE:
|
follow_redirects
|
TYPE:
|
Source code in httpx/_client.py
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 |
|
get
¶
get(url, **kwargs)
PARAMETER | DESCRIPTION |
---|---|
url
|
TYPE:
|
**kwargs
|
TYPE:
|
Source code in lilya/testclient/base.py
200 201 202 203 204 205 |
|
options
¶
options(url, **kwargs)
PARAMETER | DESCRIPTION |
---|---|
url
|
TYPE:
|
**kwargs
|
TYPE:
|
Source code in lilya/testclient/base.py
242 243 244 245 246 247 |
|
head
¶
head(url, **kwargs)
PARAMETER | DESCRIPTION |
---|---|
url
|
TYPE:
|
**kwargs
|
TYPE:
|
Source code in lilya/testclient/base.py
207 208 209 210 211 212 |
|
post
¶
post(url, **kwargs)
PARAMETER | DESCRIPTION |
---|---|
url
|
TYPE:
|
**kwargs
|
TYPE:
|
Source code in lilya/testclient/base.py
214 215 216 217 218 219 |
|
put
¶
put(url, **kwargs)
PARAMETER | DESCRIPTION |
---|---|
url
|
TYPE:
|
**kwargs
|
TYPE:
|
Source code in lilya/testclient/base.py
221 222 223 224 225 226 |
|
patch
¶
patch(url, **kwargs)
PARAMETER | DESCRIPTION |
---|---|
url
|
TYPE:
|
**kwargs
|
TYPE:
|
Source code in lilya/testclient/base.py
228 229 230 231 232 233 |
|
delete
¶
delete(url, **kwargs)
PARAMETER | DESCRIPTION |
---|---|
url
|
TYPE:
|
**kwargs
|
TYPE:
|
Source code in lilya/testclient/base.py
235 236 237 238 239 240 |
|
close
¶
close()
Close transport and proxies.
Source code in httpx/_client.py
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 |
|
websocket_connect
¶
websocket_connect(url, subprotocols=None, **kwargs)
Establishes a WebSocket connection.
PARAMETER | DESCRIPTION |
---|---|
url
|
TYPE:
|
subprotocols
|
TYPE:
|
**kwargs
|
TYPE:
|
PARAMETER | DESCRIPTION |
---|---|
url
|
The WebSocket URL.
TYPE:
|
subprotocols
|
The WebSocket subprotocols. Defaults to None.
TYPE:
|
**kwargs
|
Additional keyword arguments.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
WebSocketTestSession
|
The WebSocket session.
TYPE:
|
Source code in lilya/testclient/base.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
lifespan
async
¶
lifespan()
Handles the lifespan of the ASGI application.
Source code in lilya/testclient/base.py
343 344 345 346 347 348 349 350 351 |
|
wait_startup
async
¶
wait_startup()
Waits for the ASGI application to start up.
Source code in lilya/testclient/base.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
|
wait_shutdown
async
¶
wait_shutdown()
Waits for the ASGI application to shut down.
Source code in lilya/testclient/base.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
|
from esmerald.testclient import create_client
You can learn more how to use it in the documentation.
esmerald.testclient.create_client
¶
create_client(routes, *, settings_module=None, debug=None, app_name=None, title=None, version=None, summary=None, description=None, contact=None, terms_of_service=None, license=None, security=None, servers=None, secret_key=get_random_secret_key(), allowed_hosts=None, allow_origins=None, base_url='http://testserver', backend='asyncio', backend_options=None, interceptors=None, pluggables=None, extensions=None, permissions=None, dependencies=None, middleware=None, csrf_config=None, exception_handlers=None, openapi_config=None, on_shutdown=None, on_startup=None, cors_config=None, session_config=None, scheduler_config=None, enable_scheduler=None, enable_openapi=True, include_in_schema=True, openapi_version='3.1.0', raise_server_exceptions=True, root_path='', static_files_config=None, template_config=None, lifespan=None, cookies=None, redirect_slashes=None, tags=None, webhooks=None, encoders=None)
PARAMETER | DESCRIPTION |
---|---|
routes
|
TYPE:
|
settings_module
|
TYPE:
|
debug
|
TYPE:
|
app_name
|
TYPE:
|
title
|
TYPE:
|
version
|
TYPE:
|
summary
|
TYPE:
|
description
|
TYPE:
|
contact
|
TYPE:
|
terms_of_service
|
TYPE:
|
license
|
TYPE:
|
security
|
TYPE:
|
servers
|
TYPE:
|
secret_key
|
TYPE:
|
allowed_hosts
|
TYPE:
|
allow_origins
|
TYPE:
|
base_url
|
TYPE:
|
backend
|
TYPE:
|
backend_options
|
TYPE:
|
interceptors
|
TYPE:
|
pluggables
|
TYPE:
|
extensions
|
TYPE:
|
permissions
|
TYPE:
|
dependencies
|
TYPE:
|
middleware
|
TYPE:
|
csrf_config
|
TYPE:
|
exception_handlers
|
TYPE:
|
openapi_config
|
TYPE:
|
on_shutdown
|
TYPE:
|
on_startup
|
TYPE:
|
cors_config
|
TYPE:
|
session_config
|
TYPE:
|
scheduler_config
|
TYPE:
|
enable_scheduler
|
TYPE:
|
enable_openapi
|
TYPE:
|
include_in_schema
|
TYPE:
|
openapi_version
|
TYPE:
|
raise_server_exceptions
|
TYPE:
|
root_path
|
TYPE:
|
static_files_config
|
TYPE:
|
template_config
|
TYPE:
|
lifespan
|
TYPE:
|
cookies
|
TYPE:
|
redirect_slashes
|
TYPE:
|
tags
|
TYPE:
|
webhooks
|
TYPE:
|
encoders
|
TYPE:
|
Source code in esmerald/testclient.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|