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

Add headers parameter to django.test.{RequestFactory,Client} methods #236

Merged
merged 1 commit into from
Apr 24, 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
67 changes: 48 additions & 19 deletions django-stubs/test/client.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from io import BytesIO
from json import JSONEncoder
from re import Pattern
Expand Down Expand Up @@ -47,7 +48,11 @@ class RequestFactory:
cookies: SimpleCookie
errors: BytesIO
def __init__(
self, *, json_encoder: type[JSONEncoder] = ..., **defaults: Any
self,
*,
json_encoder: type[JSONEncoder] = ...,
headers: Mapping[str, Any] | None = ...,
**defaults: Any,
) -> None: ...
def request(self, **request: Any) -> WSGIRequest: ...
def get(
Expand All @@ -57,7 +62,8 @@ class RequestFactory:
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> WSGIRequest: ...
def post(
self,
Expand All @@ -67,7 +73,8 @@ class RequestFactory:
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> WSGIRequest: ...
def head(
self,
Expand All @@ -76,10 +83,17 @@ class RequestFactory:
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> WSGIRequest: ...
def trace(
self, path: str, secure: bool = ..., *, QUERY_STRING: str = ..., **extra: str
self,
path: str,
secure: bool = ...,
*,
QUERY_STRING: str = ...,
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> WSGIRequest: ...
def options(
self,
Expand All @@ -89,7 +103,8 @@ class RequestFactory:
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> WSGIRequest: ...
def put(
self,
Expand All @@ -99,7 +114,8 @@ class RequestFactory:
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> WSGIRequest: ...
def patch(
self,
Expand All @@ -109,7 +125,8 @@ class RequestFactory:
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> WSGIRequest: ...
def delete(
self,
Expand All @@ -119,7 +136,8 @@ class RequestFactory:
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> WSGIRequest: ...
def generic(
self,
Expand All @@ -130,20 +148,23 @@ class RequestFactory:
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> WSGIRequest: ...

class Client(RequestFactory):
handler: ClientHandler
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] = ...,
**defaults: Any
headers: Mapping[str, Any] | None = ...,
**defaults: Any,
) -> None: ...
# Silence type warnings, since this class overrides arguments and return types in an unsafe manner.
def request(self, **request: Any) -> HttpResponse: ... # type: ignore [override]
Expand All @@ -155,7 +176,8 @@ class Client(RequestFactory):
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> HttpResponse: ...
def post( # type: ignore [override]
self,
Expand All @@ -166,7 +188,8 @@ class Client(RequestFactory):
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> HttpResponse: ...
def head( # type: ignore [override]
self,
Expand All @@ -176,7 +199,8 @@ class Client(RequestFactory):
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> HttpResponse: ...
def trace( # type: ignore [override]
self,
Expand All @@ -186,7 +210,8 @@ class Client(RequestFactory):
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> HttpResponse: ...
def options( # type: ignore [override]
self,
Expand All @@ -197,7 +222,8 @@ class Client(RequestFactory):
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> HttpResponse: ...
def put( # type: ignore [override]
self,
Expand All @@ -208,7 +234,8 @@ class Client(RequestFactory):
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> HttpResponse: ...
def patch( # type: ignore [override]
self,
Expand All @@ -219,7 +246,8 @@ class Client(RequestFactory):
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> HttpResponse: ...
def delete( # type: ignore [override]
self,
Expand All @@ -230,7 +258,8 @@ class Client(RequestFactory):
secure: bool = ...,
*,
QUERY_STRING: str = ...,
**extra: str
headers: Mapping[str, Any] | None = ...,
**extra: str,
) -> HttpResponse: ...
def store_exc_info(self, **kwargs: Any) -> None: ...
@property
Expand Down
Loading