mocker.pyi 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. # Stubs for requests_mock.mocker
  2. from json import JSONEncoder
  3. from http.cookiejar import CookieJar
  4. from io import IOBase
  5. from typing import Any, Callable, Dict, List, Optional, Pattern, Type, TypeVar, Union
  6. from requests import Response, Session
  7. from urllib3.response import HTTPResponse
  8. from requests_mock.adapter import AnyMatcher, _Matcher, Callback, AdditionalMatcher
  9. from requests_mock.request import Request
  10. DELETE: str
  11. GET: str
  12. HEAD: str
  13. OPTIONS: str
  14. PATCH: str
  15. POST: str
  16. PUT: str
  17. class MockerCore:
  18. case_sensitive: bool = ...
  19. def __init__(self, **kwargs: Any) -> None: ...
  20. def start(self) -> None: ...
  21. def stop(self) -> None: ...
  22. def add_matcher(self, matcher: Callable[[Request], Optional[Response]]) -> None: ...
  23. @property
  24. def request_history(self) -> List[Request]: ...
  25. @property
  26. def last_request(self) -> Optional[Request]: ...
  27. @property
  28. def called(self) -> bool: ...
  29. @property
  30. def called_once(self) -> bool: ...
  31. @property
  32. def call_count(self) -> int: ...
  33. def reset(self) -> None: ...
  34. def reset_mock(self) -> None: ...
  35. def register_uri(
  36. self,
  37. method: Union[str, AnyMatcher],
  38. url: Union[str, Pattern[str], AnyMatcher],
  39. response_list: Optional[List[Dict[str, Any]]] = ...,
  40. *,
  41. request_headers: Dict[str, str] = ...,
  42. complete_qs: bool = ...,
  43. status_code: int = ...,
  44. reason: str = ...,
  45. headers: Dict[str, str] = ...,
  46. cookies: Union[CookieJar, Dict[str, str]] = ...,
  47. json: Union[Any, Callback[Any]] = ...,
  48. text: Union[str, Callback[str]] = ...,
  49. content: Union[bytes, Callback[bytes]] = ...,
  50. body: Union[IOBase, Callback[IOBase]] = ...,
  51. raw: HTTPResponse = ...,
  52. exc: Union[Exception, Type[Exception]] = ...,
  53. additional_matcher: AdditionalMatcher = ...,
  54. json_encoder: Optional[Type[JSONEncoder]] = ...,
  55. **kwargs: Any,
  56. ) -> _Matcher: ...
  57. def request(
  58. self,
  59. method: Union[str, AnyMatcher],
  60. url: Union[str, Pattern[str], AnyMatcher],
  61. response_list: Optional[List[Dict[str, Any]]] = ...,
  62. *,
  63. request_headers: Dict[str, str] = ...,
  64. complete_qs: bool = ...,
  65. status_code: int = ...,
  66. reason: str = ...,
  67. headers: Dict[str, str] = ...,
  68. cookies: Union[CookieJar, Dict[str, str]] = ...,
  69. json: Union[Any, Callback[Any]] = ...,
  70. text: Union[str, Callback[str]] = ...,
  71. content: Union[bytes, Callback[bytes]] = ...,
  72. body: Union[IOBase, Callback[IOBase]] = ...,
  73. raw: HTTPResponse = ...,
  74. exc: Union[Exception, Type[Exception]] = ...,
  75. additional_matcher: AdditionalMatcher = ...,
  76. json_encoder: Optional[Type[JSONEncoder]] = ...,
  77. **kwargs: Any,
  78. ) -> _Matcher: ...
  79. def get(
  80. self,
  81. url: Union[str, Pattern[str], AnyMatcher],
  82. response_list: Optional[List[Dict[str, Any]]] = ...,
  83. *,
  84. request_headers: Dict[str, str] = ...,
  85. complete_qs: bool = ...,
  86. status_code: int = ...,
  87. reason: str = ...,
  88. headers: Dict[str, str] = ...,
  89. cookies: Union[CookieJar, Dict[str, str]] = ...,
  90. json: Union[Any, Callback[Any]] = ...,
  91. text: Union[str, Callback[str]] = ...,
  92. content: Union[bytes, Callback[bytes]] = ...,
  93. body: Union[IOBase, Callback[IOBase]] = ...,
  94. raw: HTTPResponse = ...,
  95. exc: Union[Exception, Type[Exception]] = ...,
  96. additional_matcher: AdditionalMatcher = ...,
  97. json_encoder: Optional[Type[JSONEncoder]] = ...,
  98. **kwargs: Any,
  99. ) -> _Matcher: ...
  100. def head(
  101. self,
  102. url: Union[str, Pattern[str], AnyMatcher],
  103. response_list: Optional[List[Dict[str, Any]]] = ...,
  104. *,
  105. request_headers: Dict[str, str] = ...,
  106. complete_qs: bool = ...,
  107. status_code: int = ...,
  108. reason: str = ...,
  109. headers: Dict[str, str] = ...,
  110. cookies: Union[CookieJar, Dict[str, str]] = ...,
  111. json: Union[Any, Callback[Any]] = ...,
  112. text: Union[str, Callback[str]] = ...,
  113. content: Union[bytes, Callback[bytes]] = ...,
  114. body: Union[IOBase, Callback[IOBase]] = ...,
  115. raw: HTTPResponse = ...,
  116. exc: Union[Exception, Type[Exception]] = ...,
  117. additional_matcher: AdditionalMatcher = ...,
  118. json_encoder: Optional[Type[JSONEncoder]] = ...,
  119. **kwargs: Any,
  120. ) -> _Matcher: ...
  121. def options(
  122. self,
  123. url: Union[str, Pattern[str], AnyMatcher],
  124. response_list: Optional[List[Dict[str, Any]]] = ...,
  125. *,
  126. request_headers: Dict[str, str] = ...,
  127. complete_qs: bool = ...,
  128. status_code: int = ...,
  129. reason: str = ...,
  130. headers: Dict[str, str] = ...,
  131. cookies: Union[CookieJar, Dict[str, str]] = ...,
  132. json: Union[Any, Callback[Any]] = ...,
  133. text: Union[str, Callback[str]] = ...,
  134. content: Union[bytes, Callback[bytes]] = ...,
  135. body: Union[IOBase, Callback[IOBase]] = ...,
  136. raw: HTTPResponse = ...,
  137. exc: Union[Exception, Type[Exception]] = ...,
  138. additional_matcher: AdditionalMatcher = ...,
  139. json_encoder: Optional[Type[JSONEncoder]] = ...,
  140. **kwargs: Any,
  141. ) -> _Matcher: ...
  142. def post(
  143. self,
  144. url: Union[str, Pattern[str], AnyMatcher],
  145. response_list: Optional[List[Dict[str, Any]]] = ...,
  146. *,
  147. request_headers: Dict[str, str] = ...,
  148. complete_qs: bool = ...,
  149. status_code: int = ...,
  150. reason: str = ...,
  151. headers: Dict[str, str] = ...,
  152. cookies: Union[CookieJar, Dict[str, str]] = ...,
  153. json: Union[Any, Callback[Any]] = ...,
  154. text: Union[str, Callback[str]] = ...,
  155. content: Union[bytes, Callback[bytes]] = ...,
  156. body: Union[IOBase, Callback[IOBase]] = ...,
  157. raw: HTTPResponse = ...,
  158. exc: Union[Exception, Type[Exception]] = ...,
  159. additional_matcher: AdditionalMatcher = ...,
  160. json_encoder: Optional[Type[JSONEncoder]] = ...,
  161. **kwargs: Any,
  162. ) -> _Matcher: ...
  163. def put(
  164. self,
  165. url: Union[str, Pattern[str], AnyMatcher],
  166. response_list: Optional[List[Dict[str, Any]]] = ...,
  167. *,
  168. request_headers: Dict[str, str] = ...,
  169. complete_qs: bool = ...,
  170. status_code: int = ...,
  171. reason: str = ...,
  172. headers: Dict[str, str] = ...,
  173. cookies: Union[CookieJar, Dict[str, str]] = ...,
  174. json: Union[Any, Callback[Any]] = ...,
  175. text: Union[str, Callback[str]] = ...,
  176. content: Union[bytes, Callback[bytes]] = ...,
  177. body: Union[IOBase, Callback[IOBase]] = ...,
  178. raw: HTTPResponse = ...,
  179. exc: Union[Exception, Type[Exception]] = ...,
  180. additional_matcher: AdditionalMatcher = ...,
  181. json_encoder: Optional[Type[JSONEncoder]] = ...,
  182. **kwargs: Any,
  183. ) -> _Matcher: ...
  184. def patch(
  185. self,
  186. url: Union[str, Pattern[str], AnyMatcher],
  187. response_list: Optional[List[Dict[str, Any]]] = ...,
  188. *,
  189. request_headers: Dict[str, str] = ...,
  190. complete_qs: bool = ...,
  191. status_code: int = ...,
  192. reason: str = ...,
  193. headers: Dict[str, str] = ...,
  194. cookies: Union[CookieJar, Dict[str, str]] = ...,
  195. json: Union[Any, Callback[Any]] = ...,
  196. text: Union[str, Callback[str]] = ...,
  197. content: Union[bytes, Callback[bytes]] = ...,
  198. body: Union[IOBase, Callback[IOBase]] = ...,
  199. raw: HTTPResponse = ...,
  200. exc: Union[Exception, Type[Exception]] = ...,
  201. additional_matcher: AdditionalMatcher = ...,
  202. json_encoder: Optional[Type[JSONEncoder]] = ...,
  203. **kwargs: Any,
  204. ) -> _Matcher: ...
  205. def delete(
  206. self,
  207. url: Union[str, Pattern[str], AnyMatcher],
  208. response_list: Optional[List[Dict[str, Any]]] = ...,
  209. *,
  210. request_headers: Dict[str, str] = ...,
  211. complete_qs: bool = ...,
  212. status_code: int = ...,
  213. reason: str = ...,
  214. headers: Dict[str, str] = ...,
  215. cookies: Union[CookieJar, Dict[str, str]] = ...,
  216. json: Union[Any, Callback[Any]] = ...,
  217. text: Union[str, Callback[str]] = ...,
  218. content: Union[bytes, Callback[bytes]] = ...,
  219. body: Union[IOBase, Callback[IOBase]] = ...,
  220. raw: HTTPResponse = ...,
  221. exc: Union[Exception, Type[Exception]] = ...,
  222. additional_matcher: AdditionalMatcher = ...,
  223. json_encoder: Optional[Type[JSONEncoder]] = ...,
  224. **kwargs: Any,
  225. ) -> _Matcher: ...
  226. _T = TypeVar('_T')
  227. class Mocker(MockerCore):
  228. TEST_PREFIX: str = ...
  229. real_http: bool = ...
  230. def __init__(
  231. self,
  232. kw: str = ...,
  233. case_sensitive: bool = ...,
  234. adapter: Any = ...,
  235. session: Optional[Session] = ...,
  236. real_http: bool = ...,
  237. json_encoder: Optional[Type[JSONEncoder]] = ...,
  238. ) -> None: ...
  239. def __enter__(self) -> Any: ...
  240. def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ...
  241. def __call__(self, obj: Any) -> Any: ...
  242. def copy(self) -> Mocker: ...
  243. def decorate_callable(self, func: Callable[..., _T]) -> Callable[..., _T]: ...
  244. def decorate_class(self, klass: Type[_T]) -> Type[_T]: ...
  245. mock = Mocker