MCPcopy Create free account
hub / github.com/aio-libs/aiohttp / test_https_auth

Method test_https_auth

tests/test_proxy.py:1063–1139  ·  view source on GitHub ↗
(self, start_connection: Any, ClientRequestMock: Any)

Source from the content-addressed store, hash-verified

1061 spec_set=True,
1062 )
1063 def test_https_auth(self, start_connection: Any, ClientRequestMock: Any) -> None:
1064 with pytest.warns(DeprecationWarning, match="BasicAuth is deprecated"):
1065 auth = aiohttp.helpers.BasicAuth("user", "pass")
1066 proxy_req = ClientRequest(
1067 "GET",
1068 URL("http://proxy.example.com"),
1069 auth=auth,
1070 loop=self.loop,
1071 )
1072 ClientRequestMock.return_value = proxy_req
1073
1074 proxy_resp = ClientResponse(
1075 "get",
1076 URL("http://proxy.example.com"),
1077 request_info=mock.Mock(),
1078 writer=None,
1079 continue100=None,
1080 timer=TimerNoop(),
1081 traces=[],
1082 loop=self.loop,
1083 stream_writer=mock.create_autospec(
1084 AbstractStreamWriter, spec_set=True, instance=True
1085 ),
1086 session=mock.Mock(),
1087 )
1088 proxy_req.send = mock.AsyncMock(return_value=proxy_resp)
1089 proxy_resp.start = mock.AsyncMock(return_value=mock.Mock(status=200))
1090
1091 async def make_conn():
1092 return aiohttp.TCPConnector()
1093
1094 connector = self.loop.run_until_complete(make_conn())
1095 connector._resolve_host = mock.AsyncMock(
1096 return_value=[
1097 {
1098 "hostname": "hostname",
1099 "host": "127.0.0.1",
1100 "port": 80,
1101 "family": socket.AF_INET,
1102 "proto": 0,
1103 "flags": 0,
1104 }
1105 ]
1106 )
1107
1108 tr, proto = mock.Mock(), mock.Mock()
1109 self.loop.create_connection = mock.AsyncMock(return_value=(tr, proto))
1110 self.loop.start_tls = mock.AsyncMock(return_value=mock.Mock())
1111
1112 self.assertIn("AUTHORIZATION", proxy_req.headers)
1113 self.assertNotIn("PROXY-AUTHORIZATION", proxy_req.headers)
1114
1115 req = ClientRequest(
1116 "GET",
1117 URL("https://www.python.org"),
1118 proxy=URL("http://proxy.example.com"),
1119 loop=self.loop,
1120 )

Callers

nothing calls this directly

Calls 7

closeMethod · 0.95
closeMethod · 0.95
ClientRequestClass · 0.90
ClientResponseClass · 0.90
TimerNoopClass · 0.90
make_connFunction · 0.70
_create_connectionMethod · 0.45

Tested by

no test coverage detected