Skip to content

Commit 87fddd3

Browse files
authored
Add new headers parameter to test classes (#1529)
* Add new headers parameter to test classes * Tighten `extra` type hint for `Client` and `AsyncClient` * Remove useless method redefinition in AsyncRequestFactory
1 parent 0c87d59 commit 87fddd3

File tree

1 file changed

+147
-27
lines changed

1 file changed

+147
-27
lines changed

django-stubs/test/client.pyi

+147-27
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,83 @@ class _RequestFactory(Generic[_T]):
7272
errors: BytesIO
7373
def __init__(self, *, json_encoder: type[JSONEncoder] = ..., **defaults: Any) -> None: ...
7474
def request(self, **request: Any) -> _T: ...
75-
def get(self, path: str, data: _GetDataType = ..., secure: bool = ..., **extra: Any) -> _T: ...
76-
def post(self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any) -> _T: ...
77-
def head(self, path: str, data: Any = ..., secure: bool = ..., **extra: Any) -> _T: ...
78-
def trace(self, path: str, secure: bool = ..., **extra: Any) -> _T: ...
75+
def get(
76+
self,
77+
path: str,
78+
data: _GetDataType = ...,
79+
secure: bool = ...,
80+
*,
81+
headers: dict[str, Any] | None = ...,
82+
**extra: Any
83+
) -> _T: ...
84+
def post(
85+
self,
86+
path: str,
87+
data: Any = ...,
88+
content_type: str = ...,
89+
secure: bool = ...,
90+
*,
91+
headers: dict[str, Any] | None = ...,
92+
**extra: Any
93+
) -> _T: ...
94+
def head(
95+
self, path: str, data: Any = ..., secure: bool = ..., *, headers: dict[str, Any] | None = ..., **extra: Any
96+
) -> _T: ...
97+
def trace(self, path: str, secure: bool = ..., *, headers: dict[str, Any] | None = ..., **extra: Any) -> _T: ...
7998
def options(
80-
self, path: str, data: dict[str, str] | str = ..., content_type: str = ..., secure: bool = ..., **extra: Any
99+
self,
100+
path: str,
101+
data: dict[str, str] | str = ...,
102+
content_type: str = ...,
103+
secure: bool = ...,
104+
*,
105+
headers: dict[str, Any] | None = ...,
106+
**extra: Any
81107
) -> _T: ...
82-
def put(self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any) -> _T: ...
83-
def patch(self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any) -> _T: ...
84-
def delete(self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any) -> _T: ...
85-
def generic(
86-
self, method: str, path: str, data: Any = ..., content_type: str | None = ..., secure: bool = ..., **extra: Any
108+
def put(
109+
self,
110+
path: str,
111+
data: Any = ...,
112+
content_type: str = ...,
113+
secure: bool = ...,
114+
*,
115+
headers: dict[str, Any] | None = ...,
116+
**extra: Any
117+
) -> _T: ...
118+
def patch(
119+
self,
120+
path: str,
121+
data: Any = ...,
122+
content_type: str = ...,
123+
secure: bool = ...,
124+
*,
125+
headers: dict[str, Any] | None = ...,
126+
**extra: Any
127+
) -> _T: ...
128+
def delete(
129+
self,
130+
path: str,
131+
data: Any = ...,
132+
content_type: str = ...,
133+
secure: bool = ...,
134+
*,
135+
headers: dict[str, Any] | None = ...,
136+
**extra: Any
87137
) -> _T: ...
88-
89-
class RequestFactory(_RequestFactory[WSGIRequest]): ...
90-
91-
class _AsyncRequestFactory(_RequestFactory[_T]):
92-
def request(self, **request: Any) -> _T: ...
93138
def generic(
94-
self, method: str, path: str, data: Any = ..., content_type: str | None = ..., secure: bool = ..., **extra: Any
139+
self,
140+
method: str,
141+
path: str,
142+
data: Any = ...,
143+
content_type: str | None = ...,
144+
secure: bool = ...,
145+
*,
146+
headers: dict[str, Any] | None = ...,
147+
**extra: Any
95148
) -> _T: ...
96149

150+
class RequestFactory(_RequestFactory[WSGIRequest]): ...
151+
class _AsyncRequestFactory(_RequestFactory[_T]): ...
97152
class AsyncRequestFactory(_AsyncRequestFactory[ASGIRequest]): ...
98153

99154
# fakes to distinguish WSGIRequest and ASGIRequest
@@ -130,39 +185,104 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
130185
handler: ClientHandler
131186
raise_request_exception: bool
132187
exc_info: tuple[type[BaseException], BaseException, TracebackType] | None
188+
extra: dict[str, Any] | None
189+
headers: dict[str, Any]
133190
def __init__(
134-
self, enforce_csrf_checks: bool = ..., raise_request_exception: bool = ..., **defaults: Any
191+
self,
192+
enforce_csrf_checks: bool = ...,
193+
raise_request_exception: bool = ...,
194+
*,
195+
headers: dict[str, Any] | None = ...,
196+
**defaults: Any
135197
) -> None: ...
136-
# Silence type warnings, since this class overrides arguments and return types in an unsafe manner.
137198
def request(self, **request: Any) -> _MonkeyPatchedWSGIResponse: ...
138199
def get( # type: ignore
139-
self, path: str, data: _GetDataType = ..., follow: bool = ..., secure: bool = ..., **extra: Any
200+
self,
201+
path: str,
202+
data: _GetDataType = ...,
203+
follow: bool = ...,
204+
secure: bool = ...,
205+
*,
206+
headers: dict[str, Any] | None = ...,
207+
**extra: Any
140208
) -> _MonkeyPatchedWSGIResponse: ...
141209
def post( # type: ignore
142-
self, path: str, data: Any = ..., content_type: str = ..., follow: bool = ..., secure: bool = ..., **extra: Any
210+
self,
211+
path: str,
212+
data: Any = ...,
213+
content_type: str = ...,
214+
follow: bool = ...,
215+
secure: bool = ...,
216+
*,
217+
headers: dict[str, Any] | None = ...,
218+
**extra: Any
143219
) -> _MonkeyPatchedWSGIResponse: ...
144220
def head( # type: ignore
145-
self, path: str, data: Any = ..., follow: bool = ..., secure: bool = ..., **extra: Any
221+
self,
222+
path: str,
223+
data: Any = ...,
224+
follow: bool = ...,
225+
secure: bool = ...,
226+
*,
227+
headers: dict[str, Any] | None = ...,
228+
**extra: Any
146229
) -> _MonkeyPatchedWSGIResponse: ...
147230
def trace( # type: ignore
148-
self, path: str, data: Any = ..., follow: bool = ..., secure: bool = ..., **extra: Any
231+
self,
232+
path: str,
233+
data: Any = ...,
234+
follow: bool = ...,
235+
secure: bool = ...,
236+
*,
237+
headers: dict[str, Any] | None = ...,
238+
**extra: Any
149239
) -> _MonkeyPatchedWSGIResponse: ...
150240
def put( # type: ignore
151-
self, path: str, data: Any = ..., content_type: str = ..., follow: bool = ..., secure: bool = ..., **extra: Any
241+
self,
242+
path: str,
243+
data: Any = ...,
244+
content_type: str = ...,
245+
follow: bool = ...,
246+
secure: bool = ...,
247+
*,
248+
headers: dict[str, Any] | None = ...,
249+
**extra: Any
152250
) -> _MonkeyPatchedWSGIResponse: ...
153251
def patch( # type: ignore
154-
self, path: str, data: Any = ..., content_type: str = ..., follow: bool = ..., secure: bool = ..., **extra: Any
252+
self,
253+
path: str,
254+
data: Any = ...,
255+
content_type: str = ...,
256+
follow: bool = ...,
257+
secure: bool = ...,
258+
*,
259+
headers: dict[str, Any] | None = ...,
260+
**extra: Any
155261
) -> _MonkeyPatchedWSGIResponse: ...
156262
def delete( # type: ignore
157-
self, path: str, data: Any = ..., content_type: str = ..., follow: bool = ..., secure: bool = ..., **extra: Any
263+
self,
264+
path: str,
265+
data: Any = ...,
266+
content_type: str = ...,
267+
follow: bool = ...,
268+
secure: bool = ...,
269+
*,
270+
headers: dict[str, Any] | None = ...,
271+
**extra: Any
158272
) -> _MonkeyPatchedWSGIResponse: ...
159273

160274
class AsyncClient(ClientMixin, _AsyncRequestFactory[Awaitable[_MonkeyPatchedASGIResponse]]):
161275
handler: AsyncClientHandler
162276
raise_request_exception: bool
163277
exc_info: Any
164-
extra: Any
278+
extra: dict[str, Any] | None
279+
headers: dict[str, Any]
165280
def __init__(
166-
self, enforce_csrf_checks: bool = ..., raise_request_exception: bool = ..., **defaults: Any
281+
self,
282+
enforce_csrf_checks: bool = ...,
283+
raise_request_exception: bool = ...,
284+
*,
285+
headers: dict[str, Any] | None = ...,
286+
**defaults: Any
167287
) -> None: ...
168288
async def request(self, **request: Any) -> _MonkeyPatchedASGIResponse: ...

0 commit comments

Comments
 (0)