Skip to content

Commit

Permalink
Add headers parameter to django.test.{RequestFactory,Client} methods
Browse files Browse the repository at this point in the history
Closes #144
  • Loading branch information
voidus committed Apr 23, 2024
1 parent f0f1026 commit d8e1195
Showing 1 changed file with 48 additions and 19 deletions.
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

0 comments on commit d8e1195

Please sign in to comment.