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

Method test_https_connect_http_proxy_error

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

Source from the content-addressed store, hash-verified

727 spec_set=True,
728 )
729 def test_https_connect_http_proxy_error(
730 self, start_connection: Any, ClientRequestMock: Any
731 ) -> None:
732 proxy_req = ClientRequest(
733 "GET", URL("http://proxy.example.com"), loop=self.loop
734 )
735 ClientRequestMock.return_value = proxy_req
736
737 proxy_resp = ClientResponse(
738 "get",
739 URL("http://proxy.example.com"),
740 request_info=mock.Mock(),
741 writer=None,
742 continue100=None,
743 timer=TimerNoop(),
744 traces=[],
745 loop=self.loop,
746 stream_writer=mock.create_autospec(
747 AbstractStreamWriter, spec_set=True, instance=True
748 ),
749 session=mock.Mock(),
750 )
751 proxy_req.send = mock.AsyncMock(return_value=proxy_resp)
752 proxy_resp.start = mock.AsyncMock(
753 return_value=mock.Mock(status=400, reason="bad request")
754 )
755
756 async def make_conn():
757 return aiohttp.TCPConnector()
758
759 connector = self.loop.run_until_complete(make_conn())
760 connector._resolve_host = mock.AsyncMock(
761 return_value=[
762 {
763 "hostname": "hostname",
764 "host": "127.0.0.1",
765 "port": 80,
766 "family": socket.AF_INET,
767 "proto": 0,
768 "flags": 0,
769 }
770 ]
771 )
772
773 tr, proto = mock.Mock(), mock.Mock()
774 tr.get_extra_info.return_value = None
775 self.loop.create_connection = mock.AsyncMock(return_value=(tr, proto))
776
777 req = ClientRequest(
778 "GET",
779 URL("https://www.python.org"),
780 proxy=URL("http://proxy.example.com"),
781 loop=self.loop,
782 )
783 with self.assertRaisesRegex(
784 aiohttp.ClientHttpProxyError, "400, message='bad request'"
785 ):
786 self.loop.run_until_complete(

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