Skip to content

Commit

Permalink
django.test.client: add AsyncClient and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
david-flok committed May 10, 2024
1 parent 00d234b commit 3caf625
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions django-stubs/test/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...

Expand Down Expand Up @@ -270,6 +277,129 @@ class Client(RequestFactory):
) -> None: ...
def logout(self) -> None: ...


class AsyncRequestFactory(RequestFactory):
pass


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: ...

0 comments on commit 3caf625

Please sign in to comment.