(
self, start_connection: Any, ClientRequestMock: Any
)
| 798 | spec_set=True, |
| 799 | ) |
| 800 | def test_https_connect_resp_start_error( |
| 801 | self, start_connection: Any, ClientRequestMock: Any |
| 802 | ) -> None: |
| 803 | proxy_req = ClientRequest( |
| 804 | "GET", URL("http://proxy.example.com"), loop=self.loop |
| 805 | ) |
| 806 | ClientRequestMock.return_value = proxy_req |
| 807 | |
| 808 | proxy_resp = ClientResponse( |
| 809 | "get", |
| 810 | URL("http://proxy.example.com"), |
| 811 | request_info=mock.Mock(), |
| 812 | writer=None, |
| 813 | continue100=None, |
| 814 | timer=TimerNoop(), |
| 815 | traces=[], |
| 816 | loop=self.loop, |
| 817 | stream_writer=mock.create_autospec( |
| 818 | AbstractStreamWriter, spec_set=True, instance=True |
| 819 | ), |
| 820 | session=mock.Mock(), |
| 821 | ) |
| 822 | proxy_req.send = mock.AsyncMock(return_value=proxy_resp) |
| 823 | proxy_resp.start = mock.AsyncMock(side_effect=OSError("error message")) |
| 824 | |
| 825 | async def make_conn(): |
| 826 | return aiohttp.TCPConnector() |
| 827 | |
| 828 | connector = self.loop.run_until_complete(make_conn()) |
| 829 | connector._resolve_host = mock.AsyncMock( |
| 830 | return_value=[ |
| 831 | { |
| 832 | "hostname": "hostname", |
| 833 | "host": "127.0.0.1", |
| 834 | "port": 80, |
| 835 | "family": socket.AF_INET, |
| 836 | "proto": 0, |
| 837 | "flags": 0, |
| 838 | } |
| 839 | ] |
| 840 | ) |
| 841 | |
| 842 | tr, proto = mock.Mock(), mock.Mock() |
| 843 | tr.get_extra_info.return_value = None |
| 844 | self.loop.create_connection = mock.AsyncMock(return_value=(tr, proto)) |
| 845 | |
| 846 | req = ClientRequest( |
| 847 | "GET", |
| 848 | URL("https://www.python.org"), |
| 849 | proxy=URL("http://proxy.example.com"), |
| 850 | loop=self.loop, |
| 851 | ) |
| 852 | with self.assertRaisesRegex(OSError, "error message"): |
| 853 | self.loop.run_until_complete( |
| 854 | connector._create_connection(req, None, aiohttp.ClientTimeout()) |
| 855 | ) |
| 856 | |
| 857 | @mock.patch("aiohttp.connector.ClientRequest") |
nothing calls this directly
no test coverage detected