Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django.test.client: add AsyncClient and dependencies #241

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 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,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: ...
Loading