| 181 | return result |
| 182 | |
| 183 | def _build_request( |
| 184 | self, |
| 185 | method: str, |
| 186 | path: str, |
| 187 | body: Union[str, bytes, None] = None, |
| 188 | headers: Optional[Dict[str, str]] = None, |
| 189 | query_params: Optional[Dict[str, str]] = None, |
| 190 | form_data: Optional[Dict[str, str]] = None, |
| 191 | files: Optional[Dict[str, bytes]] = None, |
| 192 | ) -> Request: |
| 193 | qp = QueryParams() |
| 194 | if query_params: |
| 195 | for k, v in query_params.items(): |
| 196 | qp.set(k, v) |
| 197 | |
| 198 | h = Headers(headers or {}) |
| 199 | |
| 200 | body_val: Union[str, bytes] = "" |
| 201 | if body is not None: |
| 202 | body_val = body if isinstance(body, bytes) else body.encode("utf-8") |
| 203 | |
| 204 | return Request( |
| 205 | qp, |
| 206 | h, |
| 207 | {}, |
| 208 | body_val, |
| 209 | method, |
| 210 | Url("http", "testclient", path), |
| 211 | form_data or {}, |
| 212 | files or {}, |
| 213 | None, |
| 214 | "127.0.0.1", |
| 215 | ) |
| 216 | |
| 217 | def _execute(self, method: str, path: str, **kwargs) -> TestResponse: |
| 218 | request = self._build_request(method, path, **kwargs) |