예제 #1
0
    def test_exceptions(self):
        import aiohttp

        exceptions = aiohttp_.AiohttpClient.exceptions

        with pytest.raises(exceptions.BaseClientException):
            raise aiohttp.ClientError()

        with pytest.raises(exceptions.BaseClientException):
            # Test polymorphism
            raise aiohttp.InvalidURL("invalid")

        with pytest.raises(exceptions.ConnectionError):
            raise aiohttp.ClientConnectionError()

        with pytest.raises(exceptions.ConnectionTimeout):
            raise aiohttp.ClientConnectorError.__new__(
                aiohttp.ClientConnectorError)

        with pytest.raises(exceptions.ServerTimeout):
            raise aiohttp.ServerTimeoutError()

        with pytest.raises(exceptions.SSLError):
            raise aiohttp.ClientSSLError.__new__(aiohttp.ClientSSLError)

        with pytest.raises(exceptions.InvalidURL):
            raise aiohttp.InvalidURL("invalid")
예제 #2
0
 async def _create_connection(self, req, *args, **kwargs):
     # connection timeout
     try:
         with CeilTimeout(self.__wrapped_conn_timeout, loop=self._loop):
             return await super()._create_connection(req, *args, **kwargs)
     except asyncio.TimeoutError as exc:
         raise aiohttp.ServerTimeoutError('Connection timeout '
                                          'to host {0}'.format(
                                              req.url)) from exc
예제 #3
0
    async def test_get_index(self):
        status, index = await archive.get_index(self.cfg.omega.urls.archive)
        self.assertEqual(200, status)
        self.assertListEqual([202103, 202102, 202101], index.get("stock"))

        func = "omega.fetcher.archive.get_file"
        for side_effect in [
                aiohttp.ServerTimeoutError(),
                YAMLError(),
                Exception()
        ]:
            with mock.patch(func, side_effect=side_effect):
                status, index = await archive.get_index(
                    self.cfg.omega.urls.archive)
                self.assertEqual(500, status)
                self.assertEqual(index, None)
예제 #4
0
    async def test_get_file_connection_error(self, mock_get):
        mock_get.side_effect = aiohttp.ServerTimeoutError()

        url, _ = await archive.get_file("http://mock/2019-11-stock.tgz")
        self.assertEqual("http://mock/2019-11-stock.tgz", url)
        self.assertRaises(aiohttp.ServerTimeoutError)