summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/litestar/testing/helpers.py
blob: 5ac59af7c8223d758c13c9ebd8efce6af6d13686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Callable, Literal, Mapping, Sequence

from litestar.app import DEFAULT_OPENAPI_CONFIG, Litestar
from litestar.controller import Controller
from litestar.events import SimpleEventEmitter
from litestar.testing.client import AsyncTestClient, TestClient
from litestar.types import Empty
from litestar.utils.predicates import is_class_and_subclass

if TYPE_CHECKING:
    from contextlib import AbstractAsyncContextManager

    from litestar import Request, Response, WebSocket
    from litestar.config.allowed_hosts import AllowedHostsConfig
    from litestar.config.app import ExperimentalFeatures
    from litestar.config.compression import CompressionConfig
    from litestar.config.cors import CORSConfig
    from litestar.config.csrf import CSRFConfig
    from litestar.config.response_cache import ResponseCacheConfig
    from litestar.datastructures import CacheControlHeader, ETag, State
    from litestar.dto import AbstractDTO
    from litestar.events import BaseEventEmitterBackend, EventListener
    from litestar.logging.config import BaseLoggingConfig
    from litestar.middleware.session.base import BaseBackendConfig
    from litestar.openapi.config import OpenAPIConfig
    from litestar.openapi.spec import SecurityRequirement
    from litestar.plugins import PluginProtocol
    from litestar.static_files.config import StaticFilesConfig
    from litestar.stores.base import Store
    from litestar.stores.registry import StoreRegistry
    from litestar.template.config import TemplateConfig
    from litestar.types import (
        AfterExceptionHookHandler,
        AfterRequestHookHandler,
        AfterResponseHookHandler,
        BeforeMessageSendHookHandler,
        BeforeRequestHookHandler,
        ControllerRouterHandler,
        Dependencies,
        EmptyType,
        ExceptionHandlersMap,
        Guard,
        LifespanHook,
        Middleware,
        OnAppInitHandler,
        ParametersMap,
        ResponseCookies,
        ResponseHeaders,
        TypeEncodersMap,
    )


def create_test_client(
    route_handlers: ControllerRouterHandler | Sequence[ControllerRouterHandler] | None = None,
    *,
    after_exception: Sequence[AfterExceptionHookHandler] | None = None,
    after_request: AfterRequestHookHandler | None = None,
    after_response: AfterResponseHookHandler | None = None,
    allowed_hosts: Sequence[str] | AllowedHostsConfig | None = None,
    backend: Literal["asyncio", "trio"] = "asyncio",
    backend_options: Mapping[str, Any] | None = None,
    base_url: str = "http://testserver.local",
    before_request: BeforeRequestHookHandler | None = None,
    before_send: Sequence[BeforeMessageSendHookHandler] | None = None,
    cache_control: CacheControlHeader | None = None,
    compression_config: CompressionConfig | None = None,
    cors_config: CORSConfig | None = None,
    csrf_config: CSRFConfig | None = None,
    debug: bool = True,
    dependencies: Dependencies | None = None,
    dto: type[AbstractDTO] | None | EmptyType = Empty,
    etag: ETag | None = None,
    event_emitter_backend: type[BaseEventEmitterBackend] = SimpleEventEmitter,
    exception_handlers: ExceptionHandlersMap | None = None,
    guards: Sequence[Guard] | None = None,
    include_in_schema: bool | EmptyType = Empty,
    listeners: Sequence[EventListener] | None = None,
    logging_config: BaseLoggingConfig | EmptyType | None = Empty,
    middleware: Sequence[Middleware] | None = None,
    multipart_form_part_limit: int = 1000,
    on_app_init: Sequence[OnAppInitHandler] | None = None,
    on_shutdown: Sequence[LifespanHook] | None = None,
    on_startup: Sequence[LifespanHook] | None = None,
    openapi_config: OpenAPIConfig | None = DEFAULT_OPENAPI_CONFIG,
    opt: Mapping[str, Any] | None = None,
    parameters: ParametersMap | None = None,
    plugins: Sequence[PluginProtocol] | None = None,
    lifespan: list[Callable[[Litestar], AbstractAsyncContextManager] | AbstractAsyncContextManager] | None = None,
    raise_server_exceptions: bool = True,
    pdb_on_exception: bool | None = None,
    request_class: type[Request] | None = None,
    response_cache_config: ResponseCacheConfig | None = None,
    response_class: type[Response] | None = None,
    response_cookies: ResponseCookies | None = None,
    response_headers: ResponseHeaders | None = None,
    return_dto: type[AbstractDTO] | None | EmptyType = Empty,
    root_path: str = "",
    security: Sequence[SecurityRequirement] | None = None,
    session_config: BaseBackendConfig | None = None,
    signature_namespace: Mapping[str, Any] | None = None,
    signature_types: Sequence[Any] | None = None,
    state: State | None = None,
    static_files_config: Sequence[StaticFilesConfig] | None = None,
    stores: StoreRegistry | dict[str, Store] | None = None,
    tags: Sequence[str] | None = None,
    template_config: TemplateConfig | None = None,
    timeout: float | None = None,
    type_encoders: TypeEncodersMap | None = None,
    websocket_class: type[WebSocket] | None = None,
    experimental_features: list[ExperimentalFeatures] | None = None,
) -> TestClient[Litestar]:
    """Create a Litestar app instance and initializes it.

    :class:`TestClient <litestar.testing.TestClient>` with it.

    Notes:
        - This function should be called as a context manager to ensure async startup and shutdown are
            handled correctly.

    Examples:
        .. code-block:: python

            from litestar import get
            from litestar.testing import create_test_client


            @get("/some-path")
            def my_handler() -> dict[str, str]:
                return {"hello": "world"}


            def test_my_handler() -> None:
                with create_test_client(my_handler) as client:
                    response = client.get("/some-path")
                    assert response.json() == {"hello": "world"}

    Args:
        route_handlers: A single handler or a sequence of route handlers, which can include instances of
            :class:`Router <litestar.router.Router>`, subclasses of :class:`Controller <.controller.Controller>` or
            any function decorated by the route handler decorators.
        backend: The async backend to use, options are "asyncio" or "trio".
        backend_options: ``anyio`` options.
        base_url: URL scheme and domain for test request paths, e.g. ``http://testserver``.
        raise_server_exceptions: Flag for underlying the test client to raise server exceptions instead of wrapping them
            in an HTTP response.
        root_path: Path prefix for requests.
        session_config: Configuration for Session Middleware class to create raw session cookies for request to the
            route handlers.
        after_exception: A sequence of :class:`exception hook handlers <.types.AfterExceptionHookHandler>`. This
            hook is called after an exception occurs. In difference to exception handlers, it is not meant to
            return a response - only to process the exception (e.g. log it, send it to Sentry etc.).
        after_request: A sync or async function executed after the route handler function returned and the response
            object has been resolved. Receives the response object.
        after_response: A sync or async function called after the response has been awaited. It receives the
            :class:`Request <.connection.Request>` object and should not return any values.
        allowed_hosts: A sequence of allowed hosts, or an
            :class:`AllowedHostsConfig <.config.allowed_hosts.AllowedHostsConfig>` instance. Enables the builtin
            allowed hosts middleware.
        before_request: A sync or async function called immediately before calling the route handler. Receives the
            :class:`Request <.connection.Request>` instance and any non-``None`` return value is used for the
            response, bypassing the route handler.
        before_send: A sequence of :class:`before send hook handlers <.types.BeforeMessageSendHookHandler>`. Called
            when the ASGI send function is called.
        cache_control: A ``cache-control`` header of type
            :class:`CacheControlHeader <litestar.datastructures.CacheControlHeader>` to add to route handlers of
            this app. Can be overridden by route handlers.
        compression_config: Configures compression behaviour of the application, this enabled a builtin or user
            defined Compression middleware.
        cors_config: If set, configures :class:`CORSMiddleware <.middleware.cors.CORSMiddleware>`.
        csrf_config: If set, configures :class:`CSRFMiddleware <.middleware.csrf.CSRFMiddleware>`.
        debug: If ``True``, app errors rendered as HTML with a stack trace.
        dependencies: A string keyed mapping of dependency :class:`Providers <.di.Provide>`.
        dto: :class:`AbstractDTO <.dto.base_dto.AbstractDTO>` to use for (de)serializing and
            validation of request data.
        etag: An ``etag`` header of type :class:`ETag <.datastructures.ETag>` to add to route handlers of this app.
            Can be overridden by route handlers.
        event_emitter_backend: A subclass of
            :class:`BaseEventEmitterBackend <.events.emitter.BaseEventEmitterBackend>`.
        exception_handlers: A mapping of status codes and/or exception types to handler functions.
        guards: A sequence of :class:`Guard <.types.Guard>` callables.
        include_in_schema: A boolean flag dictating whether  the route handler should be documented in the OpenAPI schema.
        lifespan: A list of callables returning async context managers, wrapping the lifespan of the ASGI application
        listeners: A sequence of :class:`EventListener <.events.listener.EventListener>`.
        logging_config: A subclass of :class:`BaseLoggingConfig <.logging.config.BaseLoggingConfig>`.
        middleware: A sequence of :class:`Middleware <.types.Middleware>`.
        multipart_form_part_limit: The maximal number of allowed parts in a multipart/formdata request. This limit
            is intended to protect from DoS attacks.
        on_app_init: A sequence of :class:`OnAppInitHandler <.types.OnAppInitHandler>` instances. Handlers receive
            an instance of :class:`AppConfig <.config.app.AppConfig>` that will have been initially populated with
            the parameters passed to :class:`Litestar <litestar.app.Litestar>`, and must return an instance of same.
            If more than one handler is registered they are called in the order they are provided.
        on_shutdown: A sequence of :class:`LifespanHook <.types.LifespanHook>` called during application
            shutdown.
        on_startup: A sequence of :class:`LifespanHook <litestar.types.LifespanHook>` called during
            application startup.
        openapi_config: Defaults to :attr:`DEFAULT_OPENAPI_CONFIG`
        opt: A string keyed mapping of arbitrary values that can be accessed in :class:`Guards <.types.Guard>` or
            wherever you have access to :class:`Request <litestar.connection.request.Request>` or
            :class:`ASGI Scope <.types.Scope>`.
        parameters: A mapping of :class:`Parameter <.params.Parameter>` definitions available to all application
            paths.
        pdb_on_exception: Drop into the PDB when an exception occurs.
        plugins: Sequence of plugins.
        request_class: An optional subclass of :class:`Request <.connection.Request>` to use for http connections.
        response_class: A custom subclass of :class:`Response <.response.Response>` to be used as the app's default
            response.
        response_cookies: A sequence of :class:`Cookie <.datastructures.Cookie>`.
        response_headers: A string keyed mapping of :class:`ResponseHeader <.datastructures.ResponseHeader>`
        response_cache_config: Configures caching behavior of the application.
        return_dto: :class:`AbstractDTO <.dto.base_dto.AbstractDTO>` to use for serializing
            outbound response data.
        route_handlers: A sequence of route handlers, which can include instances of
            :class:`Router <.router.Router>`, subclasses of :class:`Controller <.controller.Controller>` or any
            callable decorated by the route handler decorators.
        security: A sequence of dicts that will be added to the schema of all route handlers in the application.
            See
            :data:`SecurityRequirement <.openapi.spec.SecurityRequirement>` for details.
        signature_namespace: A mapping of names to types for use in forward reference resolution during signature modeling.
        signature_types: A sequence of types for use in forward reference resolution during signature modeling.
            These types will be added to the signature namespace using their ``__name__`` attribute.
        state: An optional :class:`State <.datastructures.State>` for application state.
        static_files_config: A sequence of :class:`StaticFilesConfig <.static_files.StaticFilesConfig>`
        stores: Central registry of :class:`Store <.stores.base.Store>` that will be available throughout the
            application. If this is a dictionary to it will be passed to a
            :class:`StoreRegistry <.stores.registry.StoreRegistry>`. If it is a
            :class:`StoreRegistry <.stores.registry.StoreRegistry>`, this instance will be used directly.
        tags: A sequence of string tags that will be appended to the schema of all route handlers under the
            application.
        template_config: An instance of :class:`TemplateConfig <.template.TemplateConfig>`
        timeout: Request timeout
        type_encoders: A mapping of types to callables that transform them into types supported for serialization.
        websocket_class: An optional subclass of :class:`WebSocket <.connection.WebSocket>` to use for websocket
            connections.
        experimental_features: An iterable of experimental features to enable


    Returns:
        An instance of :class:`TestClient <.testing.TestClient>` with a created app instance.
    """
    route_handlers = () if route_handlers is None else route_handlers
    if is_class_and_subclass(route_handlers, Controller) or not isinstance(route_handlers, Sequence):
        route_handlers = (route_handlers,)

    app = Litestar(
        after_exception=after_exception,
        after_request=after_request,
        after_response=after_response,
        allowed_hosts=allowed_hosts,
        before_request=before_request,
        before_send=before_send,
        cache_control=cache_control,
        compression_config=compression_config,
        cors_config=cors_config,
        csrf_config=csrf_config,
        debug=debug,
        dependencies=dependencies,
        dto=dto,
        etag=etag,
        lifespan=lifespan,
        event_emitter_backend=event_emitter_backend,
        exception_handlers=exception_handlers,
        guards=guards,
        include_in_schema=include_in_schema,
        listeners=listeners,
        logging_config=logging_config,
        middleware=middleware,
        multipart_form_part_limit=multipart_form_part_limit,
        on_app_init=on_app_init,
        on_shutdown=on_shutdown,
        on_startup=on_startup,
        openapi_config=openapi_config,
        opt=opt,
        parameters=parameters,
        pdb_on_exception=pdb_on_exception,
        plugins=plugins,
        request_class=request_class,
        response_cache_config=response_cache_config,
        response_class=response_class,
        response_cookies=response_cookies,
        response_headers=response_headers,
        return_dto=return_dto,
        route_handlers=route_handlers,
        security=security,
        signature_namespace=signature_namespace,
        signature_types=signature_types,
        state=state,
        static_files_config=static_files_config,
        stores=stores,
        tags=tags,
        template_config=template_config,
        type_encoders=type_encoders,
        websocket_class=websocket_class,
        experimental_features=experimental_features,
    )

    return TestClient[Litestar](
        app=app,
        backend=backend,
        backend_options=backend_options,
        base_url=base_url,
        raise_server_exceptions=raise_server_exceptions,
        root_path=root_path,
        session_config=session_config,
        timeout=timeout,
    )


def create_async_test_client(
    route_handlers: ControllerRouterHandler | Sequence[ControllerRouterHandler] | None = None,
    *,
    after_exception: Sequence[AfterExceptionHookHandler] | None = None,
    after_request: AfterRequestHookHandler | None = None,
    after_response: AfterResponseHookHandler | None = None,
    allowed_hosts: Sequence[str] | AllowedHostsConfig | None = None,
    backend: Literal["asyncio", "trio"] = "asyncio",
    backend_options: Mapping[str, Any] | None = None,
    base_url: str = "http://testserver.local",
    before_request: BeforeRequestHookHandler | None = None,
    before_send: Sequence[BeforeMessageSendHookHandler] | None = None,
    cache_control: CacheControlHeader | None = None,
    compression_config: CompressionConfig | None = None,
    cors_config: CORSConfig | None = None,
    csrf_config: CSRFConfig | None = None,
    debug: bool = True,
    dependencies: Dependencies | None = None,
    dto: type[AbstractDTO] | None | EmptyType = Empty,
    etag: ETag | None = None,
    event_emitter_backend: type[BaseEventEmitterBackend] = SimpleEventEmitter,
    exception_handlers: ExceptionHandlersMap | None = None,
    guards: Sequence[Guard] | None = None,
    include_in_schema: bool | EmptyType = Empty,
    lifespan: list[Callable[[Litestar], AbstractAsyncContextManager] | AbstractAsyncContextManager] | None = None,
    listeners: Sequence[EventListener] | None = None,
    logging_config: BaseLoggingConfig | EmptyType | None = Empty,
    middleware: Sequence[Middleware] | None = None,
    multipart_form_part_limit: int = 1000,
    on_app_init: Sequence[OnAppInitHandler] | None = None,
    on_shutdown: Sequence[LifespanHook] | None = None,
    on_startup: Sequence[LifespanHook] | None = None,
    openapi_config: OpenAPIConfig | None = DEFAULT_OPENAPI_CONFIG,
    opt: Mapping[str, Any] | None = None,
    parameters: ParametersMap | None = None,
    pdb_on_exception: bool | None = None,
    plugins: Sequence[PluginProtocol] | None = None,
    raise_server_exceptions: bool = True,
    request_class: type[Request] | None = None,
    response_cache_config: ResponseCacheConfig | None = None,
    response_class: type[Response] | None = None,
    response_cookies: ResponseCookies | None = None,
    response_headers: ResponseHeaders | None = None,
    return_dto: type[AbstractDTO] | None | EmptyType = Empty,
    root_path: str = "",
    security: Sequence[SecurityRequirement] | None = None,
    session_config: BaseBackendConfig | None = None,
    signature_namespace: Mapping[str, Any] | None = None,
    signature_types: Sequence[Any] | None = None,
    state: State | None = None,
    static_files_config: Sequence[StaticFilesConfig] | None = None,
    stores: StoreRegistry | dict[str, Store] | None = None,
    tags: Sequence[str] | None = None,
    template_config: TemplateConfig | None = None,
    timeout: float | None = None,
    type_encoders: TypeEncodersMap | None = None,
    websocket_class: type[WebSocket] | None = None,
    experimental_features: list[ExperimentalFeatures] | None = None,
) -> AsyncTestClient[Litestar]:
    """Create a Litestar app instance and initializes it.

    :class:`AsyncTestClient <litestar.testing.AsyncTestClient>` with it.

    Notes:
        - This function should be called as a context manager to ensure async startup and shutdown are
            handled correctly.

    Examples:
        .. code-block:: python

            from litestar import get
            from litestar.testing import create_async_test_client


            @get("/some-path")
            def my_handler() -> dict[str, str]:
                return {"hello": "world"}


            async def test_my_handler() -> None:
                async with create_async_test_client(my_handler) as client:
                    response = await client.get("/some-path")
                    assert response.json() == {"hello": "world"}

    Args:
        route_handlers: A single handler or a sequence of route handlers, which can include instances of
            :class:`Router <litestar.router.Router>`, subclasses of :class:`Controller <.controller.Controller>` or
            any function decorated by the route handler decorators.
        backend: The async backend to use, options are "asyncio" or "trio".
        backend_options: ``anyio`` options.
        base_url: URL scheme and domain for test request paths, e.g. ``http://testserver``.
        raise_server_exceptions: Flag for underlying the test client to raise server exceptions instead of wrapping them
            in an HTTP response.
        root_path: Path prefix for requests.
        session_config: Configuration for Session Middleware class to create raw session cookies for request to the
            route handlers.
        after_exception: A sequence of :class:`exception hook handlers <.types.AfterExceptionHookHandler>`. This
            hook is called after an exception occurs. In difference to exception handlers, it is not meant to
            return a response - only to process the exception (e.g. log it, send it to Sentry etc.).
        after_request: A sync or async function executed after the route handler function returned and the response
            object has been resolved. Receives the response object.
        after_response: A sync or async function called after the response has been awaited. It receives the
            :class:`Request <.connection.Request>` object and should not return any values.
        allowed_hosts: A sequence of allowed hosts, or an
            :class:`AllowedHostsConfig <.config.allowed_hosts.AllowedHostsConfig>` instance. Enables the builtin
            allowed hosts middleware.
        before_request: A sync or async function called immediately before calling the route handler. Receives the
            :class:`Request <.connection.Request>` instance and any non-``None`` return value is used for the
            response, bypassing the route handler.
        before_send: A sequence of :class:`before send hook handlers <.types.BeforeMessageSendHookHandler>`. Called
            when the ASGI send function is called.
        cache_control: A ``cache-control`` header of type
            :class:`CacheControlHeader <litestar.datastructures.CacheControlHeader>` to add to route handlers of
            this app. Can be overridden by route handlers.
        compression_config: Configures compression behaviour of the application, this enabled a builtin or user
            defined Compression middleware.
        cors_config: If set, configures :class:`CORSMiddleware <.middleware.cors.CORSMiddleware>`.
        csrf_config: If set, configures :class:`CSRFMiddleware <.middleware.csrf.CSRFMiddleware>`.
        debug: If ``True``, app errors rendered as HTML with a stack trace.
        dependencies: A string keyed mapping of dependency :class:`Providers <.di.Provide>`.
        dto: :class:`AbstractDTO <.dto.base_dto.AbstractDTO>` to use for (de)serializing and
            validation of request data.
        etag: An ``etag`` header of type :class:`ETag <.datastructures.ETag>` to add to route handlers of this app.
            Can be overridden by route handlers.
        event_emitter_backend: A subclass of
            :class:`BaseEventEmitterBackend <.events.emitter.BaseEventEmitterBackend>`.
        exception_handlers: A mapping of status codes and/or exception types to handler functions.
        guards: A sequence of :class:`Guard <.types.Guard>` callables.
        include_in_schema: A boolean flag dictating whether  the route handler should be documented in the OpenAPI schema.
        lifespan: A list of callables returning async context managers, wrapping the lifespan of the ASGI application
        listeners: A sequence of :class:`EventListener <.events.listener.EventListener>`.
        logging_config: A subclass of :class:`BaseLoggingConfig <.logging.config.BaseLoggingConfig>`.
        middleware: A sequence of :class:`Middleware <.types.Middleware>`.
        multipart_form_part_limit: The maximal number of allowed parts in a multipart/formdata request. This limit
            is intended to protect from DoS attacks.
        on_app_init: A sequence of :class:`OnAppInitHandler <.types.OnAppInitHandler>` instances. Handlers receive
            an instance of :class:`AppConfig <.config.app.AppConfig>` that will have been initially populated with
            the parameters passed to :class:`Litestar <litestar.app.Litestar>`, and must return an instance of same.
            If more than one handler is registered they are called in the order they are provided.
        on_shutdown: A sequence of :class:`LifespanHook <.types.LifespanHook>` called during application
            shutdown.
        on_startup: A sequence of :class:`LifespanHook <litestar.types.LifespanHook>` called during
            application startup.
        openapi_config: Defaults to :attr:`DEFAULT_OPENAPI_CONFIG`
        opt: A string keyed mapping of arbitrary values that can be accessed in :class:`Guards <.types.Guard>` or
            wherever you have access to :class:`Request <litestar.connection.request.Request>` or
            :class:`ASGI Scope <.types.Scope>`.
        parameters: A mapping of :class:`Parameter <.params.Parameter>` definitions available to all application
            paths.
        pdb_on_exception: Drop into the PDB when an exception occurs.
        plugins: Sequence of plugins.
        request_class: An optional subclass of :class:`Request <.connection.Request>` to use for http connections.
        response_class: A custom subclass of :class:`Response <.response.Response>` to be used as the app's default
            response.
        response_cookies: A sequence of :class:`Cookie <.datastructures.Cookie>`.
        response_headers: A string keyed mapping of :class:`ResponseHeader <.datastructures.ResponseHeader>`
        response_cache_config: Configures caching behavior of the application.
        return_dto: :class:`AbstractDTO <.dto.base_dto.AbstractDTO>` to use for serializing
            outbound response data.
        route_handlers: A sequence of route handlers, which can include instances of
            :class:`Router <.router.Router>`, subclasses of :class:`Controller <.controller.Controller>` or any
            callable decorated by the route handler decorators.
        security: A sequence of dicts that will be added to the schema of all route handlers in the application.
            See
            :data:`SecurityRequirement <.openapi.spec.SecurityRequirement>` for details.
        signature_namespace: A mapping of names to types for use in forward reference resolution during signature modeling.
        signature_types: A sequence of types for use in forward reference resolution during signature modeling.
            These types will be added to the signature namespace using their ``__name__`` attribute.
        state: An optional :class:`State <.datastructures.State>` for application state.
        static_files_config: A sequence of :class:`StaticFilesConfig <.static_files.StaticFilesConfig>`
        stores: Central registry of :class:`Store <.stores.base.Store>` that will be available throughout the
            application. If this is a dictionary to it will be passed to a
            :class:`StoreRegistry <.stores.registry.StoreRegistry>`. If it is a
            :class:`StoreRegistry <.stores.registry.StoreRegistry>`, this instance will be used directly.
        tags: A sequence of string tags that will be appended to the schema of all route handlers under the
            application.
        template_config: An instance of :class:`TemplateConfig <.template.TemplateConfig>`
        timeout: Request timeout
        type_encoders: A mapping of types to callables that transform them into types supported for serialization.
        websocket_class: An optional subclass of :class:`WebSocket <.connection.WebSocket>` to use for websocket
            connections.
        experimental_features: An iterable of experimental features to enable

    Returns:
        An instance of :class:`AsyncTestClient <litestar.testing.AsyncTestClient>` with a created app instance.
    """
    route_handlers = () if route_handlers is None else route_handlers
    if is_class_and_subclass(route_handlers, Controller) or not isinstance(route_handlers, Sequence):
        route_handlers = (route_handlers,)

    app = Litestar(
        after_exception=after_exception,
        after_request=after_request,
        after_response=after_response,
        allowed_hosts=allowed_hosts,
        before_request=before_request,
        before_send=before_send,
        cache_control=cache_control,
        compression_config=compression_config,
        cors_config=cors_config,
        csrf_config=csrf_config,
        debug=debug,
        dependencies=dependencies,
        dto=dto,
        etag=etag,
        event_emitter_backend=event_emitter_backend,
        exception_handlers=exception_handlers,
        guards=guards,
        include_in_schema=include_in_schema,
        lifespan=lifespan,
        listeners=listeners,
        logging_config=logging_config,
        middleware=middleware,
        multipart_form_part_limit=multipart_form_part_limit,
        on_app_init=on_app_init,
        on_shutdown=on_shutdown,
        on_startup=on_startup,
        openapi_config=openapi_config,
        opt=opt,
        parameters=parameters,
        pdb_on_exception=pdb_on_exception,
        plugins=plugins,
        request_class=request_class,
        response_cache_config=response_cache_config,
        response_class=response_class,
        response_cookies=response_cookies,
        response_headers=response_headers,
        return_dto=return_dto,
        route_handlers=route_handlers,
        security=security,
        signature_namespace=signature_namespace,
        signature_types=signature_types,
        state=state,
        static_files_config=static_files_config,
        stores=stores,
        tags=tags,
        template_config=template_config,
        type_encoders=type_encoders,
        websocket_class=websocket_class,
        experimental_features=experimental_features,
    )

    return AsyncTestClient[Litestar](
        app=app,
        backend=backend,
        backend_options=backend_options,
        base_url=base_url,
        raise_server_exceptions=raise_server_exceptions,
        root_path=root_path,
        session_config=session_config,
        timeout=timeout,
    )