( # type: ignore[misc]
loop: asyncio.AbstractEventLoop,
test_case: str,
wait_for_con: bool,
expect_proxy_auth_header: bool,
)
| 3255 | ], |
| 3256 | ) |
| 3257 | async def test_connect_reuse_proxy_headers( # type: ignore[misc] |
| 3258 | loop: asyncio.AbstractEventLoop, |
| 3259 | test_case: str, |
| 3260 | wait_for_con: bool, |
| 3261 | expect_proxy_auth_header: bool, |
| 3262 | ) -> None: |
| 3263 | proto = create_mocked_conn(loop) |
| 3264 | proto.is_connected.return_value = True |
| 3265 | |
| 3266 | if test_case != "dont_use_proxy": |
| 3267 | proxy = ( |
| 3268 | URL("http://user:password@example.com") |
| 3269 | if test_case == "use_proxy_with_embedded_auth" |
| 3270 | else URL("http://example.com") |
| 3271 | ) |
| 3272 | proxy_headers = ( |
| 3273 | CIMultiDict({hdrs.AUTHORIZATION: "Basic dXNlcjpwYXNzd29yZA=="}) |
| 3274 | if test_case == "use_proxy_with_auth_headers" |
| 3275 | else None |
| 3276 | ) |
| 3277 | else: |
| 3278 | proxy = None |
| 3279 | proxy_headers = None |
| 3280 | key = ConnectionKey( |
| 3281 | "localhost", |
| 3282 | 80, |
| 3283 | False, |
| 3284 | True, |
| 3285 | proxy, |
| 3286 | None, |
| 3287 | hash(tuple(proxy_headers.items())) if proxy_headers else None, |
| 3288 | ) |
| 3289 | req = ClientRequest( |
| 3290 | "GET", |
| 3291 | URL("http://localhost:80"), |
| 3292 | loop=loop, |
| 3293 | response_class=mock.Mock(), |
| 3294 | proxy=proxy, |
| 3295 | proxy_headers=proxy_headers, |
| 3296 | ) |
| 3297 | |
| 3298 | conn = aiohttp.BaseConnector(limit=1) |
| 3299 | |
| 3300 | async def _create_con(*args: Any, **kwargs: Any) -> None: |
| 3301 | conn._conns[key] = deque([(proto, loop.time())]) |
| 3302 | |
| 3303 | with contextlib.ExitStack() as stack: |
| 3304 | if wait_for_con: |
| 3305 | # Simulate no available connections |
| 3306 | stack.enter_context( |
| 3307 | mock.patch.object( |
| 3308 | conn, "_available_connections", autospec=True, return_value=0 |
| 3309 | ) |
| 3310 | ) |
| 3311 | # Upon waiting for a connection, populate _conns with our proto, |
| 3312 | # mocking a connection becoming immediately available |
| 3313 | stack.enter_context( |
| 3314 | mock.patch.object( |
nothing calls this directly
no test coverage detected
searching dependent graphs…