From 9cc16f6666a06c3b8800f9a74199850ed1bbd56e Mon Sep 17 00:00:00 2001 From: David Sheets Date: Fri, 10 May 2024 11:25:46 +0100 Subject: [PATCH] django.test.client: add AsyncClient and dependencies --- django-stubs/test/client.pyi | 128 +++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/django-stubs/test/client.pyi b/django-stubs/test/client.pyi index 44d50163a..145d8290b 100644 --- a/django-stubs/test/client.pyi +++ b/django-stubs/test/client.pyi @@ -37,6 +37,13 @@ class ClientHandler(BaseHandler): ) -> None: ... def __call__(self, environ: dict[str, Any]) -> HttpResponseBase: ... +class AsyncClientHandler(BaseHandler): + enforce_csrf_checks: bool = ... + def __init__( + self, enforce_csrf_checks: bool = ..., *args: Any, **kwargs: Any + ) -> None: ... + async def __call__(self, scope: dict[str, Any]) -> HttpResponseBase: ... + def encode_multipart(boundary: str, data: dict[str, Any]) -> bytes: ... def encode_file(boundary: str, key: str, file: Any) -> list[bytes]: ... @@ -270,6 +277,127 @@ class Client(RequestFactory): ) -> None: ... def logout(self) -> None: ... +class AsyncRequestFactory(RequestFactory): + ... + +class AsyncClient(AsyncRequestFactory): + handler: AsyncClientHandler + raise_request_exception: bool + exc_info: tuple[type[BaseException], BaseException, TracebackType] | None + headers: dict[str, Any] + def __init__( + self, + enforce_csrf_checks: bool = ..., + raise_request_exception: bool = ..., + *, + json_encoder: type[JSONEncoder] = ..., + headers: Mapping[str, Any] | None = ..., + **defaults: Any, + ) -> None: ... + # Silence type warnings, since this class overrides arguments and return types in an unsafe manner. + async def request(self, **request: Any) -> HttpResponse: ... # type: ignore [override] + async def get( # type: ignore [override] + self, + path: str, + data: _RequestData = ..., + follow: bool = ..., + secure: bool = ..., + *, + QUERY_STRING: str = ..., + headers: Mapping[str, Any] | None = ..., + **extra: str, + ) -> HttpResponse: ... + async def post( # type: ignore [override] + self, + path: str, + data: _RequestData = ..., + content_type: str = ..., + follow: bool = ..., + secure: bool = ..., + *, + QUERY_STRING: str = ..., + headers: Mapping[str, Any] | None = ..., + **extra: str, + ) -> HttpResponse: ... + async def head( # type: ignore [override] + self, + path: str, + data: _RequestData = ..., + follow: bool = ..., + secure: bool = ..., + *, + QUERY_STRING: str = ..., + headers: Mapping[str, Any] | None = ..., + **extra: str, + ) -> HttpResponse: ... + async def trace( # type: ignore [override] + self, + path: str, + data: _RequestData = ..., + follow: bool = ..., + secure: bool = ..., + *, + QUERY_STRING: str = ..., + headers: Mapping[str, Any] | None = ..., + **extra: str, + ) -> HttpResponse: ... + async def options( # type: ignore [override] + self, + path: str, + data: _RequestData = ..., + content_type: str = ..., + follow: bool = ..., + secure: bool = ..., + *, + QUERY_STRING: str = ..., + headers: Mapping[str, Any] | None = ..., + **extra: str, + ) -> HttpResponse: ... + async def put( # type: ignore [override] + self, + path: str, + data: _RequestData = ..., + content_type: str = ..., + follow: bool = ..., + secure: bool = ..., + *, + QUERY_STRING: str = ..., + headers: Mapping[str, Any] | None = ..., + **extra: str, + ) -> HttpResponse: ... + async def patch( # type: ignore [override] + self, + path: str, + data: _RequestData = ..., + content_type: str = ..., + follow: bool = ..., + secure: bool = ..., + *, + QUERY_STRING: str = ..., + headers: Mapping[str, Any] | None = ..., + **extra: str, + ) -> HttpResponse: ... + async def delete( # type: ignore [override] + self, + path: str, + data: _RequestData = ..., + content_type: str = ..., + follow: bool = ..., + secure: bool = ..., + *, + QUERY_STRING: str = ..., + headers: Mapping[str, Any] | None = ..., + **extra: str, + ) -> HttpResponse: ... + def store_exc_info(self, **kwargs: Any) -> None: ... + @property + def session(self) -> SessionBase: ... + def login(self, **credentials: Any) -> bool: ... + def force_login( + self, user: AbstractBaseUser, backend: str | None = ... + ) -> None: ... + def logout(self) -> None: ... + def conditional_content_removal( request: HttpRequest, response: HttpResponseBase ) -> HttpResponse: ...