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

Method test_https_connect

tests/test_proxy.py:527–589  ·  view source on GitHub ↗
(
        self, start_connection: mock.Mock, ClientRequestMock: mock.Mock
    )

Source from the content-addressed store, hash-verified

525 spec_set=True,
526 )
527 def test_https_connect(
528 self, start_connection: mock.Mock, ClientRequestMock: mock.Mock
529 ) -> None:
530 proxy_req = ClientRequest(
531 "GET", URL("http://proxy.example.com"), loop=self.loop
532 )
533 ClientRequestMock.return_value = proxy_req
534
535 proxy_resp = ClientResponse(
536 "get",
537 URL("http://proxy.example.com"),
538 request_info=mock.Mock(),
539 writer=None,
540 continue100=None,
541 timer=TimerNoop(),
542 traces=[],
543 loop=self.loop,
544 stream_writer=mock.create_autospec(
545 AbstractStreamWriter, spec_set=True, instance=True
546 ),
547 session=mock.Mock(),
548 )
549 proxy_req.send = mock.AsyncMock(return_value=proxy_resp)
550 proxy_resp.start = mock.AsyncMock(return_value=mock.Mock(status=200))
551
552 async def make_conn():
553 return aiohttp.TCPConnector()
554
555 connector = self.loop.run_until_complete(make_conn())
556 connector._resolve_host = mock.AsyncMock(
557 return_value=[
558 {
559 "hostname": "hostname",
560 "host": "127.0.0.1",
561 "port": 80,
562 "family": socket.AF_INET,
563 "proto": 0,
564 "flags": 0,
565 }
566 ]
567 )
568
569 tr, proto = mock.Mock(), mock.Mock()
570 self.loop.create_connection = mock.AsyncMock(return_value=(tr, proto))
571 self.loop.start_tls = mock.AsyncMock(return_value=mock.Mock())
572
573 req = ClientRequest(
574 "GET",
575 URL("https://www.python.org"),
576 proxy=URL("http://proxy.example.com"),
577 loop=self.loop,
578 )
579 self.loop.run_until_complete(
580 connector._create_connection(req, None, aiohttp.ClientTimeout())
581 )
582
583 self.assertEqual(req.url.path, "/")
584 self.assertEqual(proxy_req.method, "CONNECT")

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