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

Method test_https_connect_send_error

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

Source from the content-addressed store, hash-verified

861 spec_set=True,
862 )
863 def test_https_connect_send_error(
864 self, start_connection: Any, ClientRequestMock: Any
865 ) -> None:
866 proxy_req = ClientRequest("GET", URL("http://proxy.example"), loop=self.loop)
867 ClientRequestMock.return_value = proxy_req
868 proxy_req.send = mock.AsyncMock(
869 side_effect=aiohttp.ClientConnectionResetError(
870 "Cannot write to closing transport"
871 )
872 )
873
874 async def make_conn():
875 return aiohttp.TCPConnector()
876
877 connector = self.loop.run_until_complete(make_conn())
878 connector._resolve_host = mock.AsyncMock(
879 return_value=[
880 {
881 "hostname": "hostname",
882 "host": "127.0.0.1",
883 "port": 80,
884 "family": socket.AF_INET,
885 "proto": 0,
886 "flags": 0,
887 }
888 ]
889 )
890
891 tr, proto = mock.Mock(), mock.Mock()
892 tr.get_extra_info.return_value = None
893 self.loop.create_connection = mock.AsyncMock(return_value=(tr, proto))
894
895 req = ClientRequest(
896 "GET",
897 URL("https://www.python.org"),
898 proxy=URL("http://proxy.example"),
899 loop=self.loop,
900 )
901 with pytest.raises(
902 aiohttp.ClientConnectionResetError,
903 match="Cannot write to closing transport",
904 ) as exc_info:
905 self.loop.run_until_complete(
906 connector._create_connection(req, None, aiohttp.ClientTimeout())
907 )
908 # The tunnel connection is still referenced from the traceback,
909 # so the proxy connection must have been closed explicitly
910 # rather than by the garbage collector.
911 assert exc_info.value.__traceback__ is not None
912 proto.close.assert_called_once_with()
913
914 @mock.patch("aiohttp.connector.ClientRequest")
915 @mock.patch(

Callers

nothing calls this directly

Calls 3

ClientRequestClass · 0.90
make_connFunction · 0.70
_create_connectionMethod · 0.45

Tested by

no test coverage detected