def _configure(self, **kwargs): self.connection = ConnectionConfiguration(**kwargs) self.user_agent_policy = policies.UserAgentPolicy(**kwargs) self.headers_policy = policies.HeadersPolicy(**kwargs) self.proxy_policy = policies.ProxyPolicy(**kwargs) self.logging_policy = policies.NetworkTraceLoggingPolicy(**kwargs) self.retry_policy = policies.AsyncRetryPolicy(**kwargs) self.redirect_policy = policies.AsyncRedirectPolicy(**kwargs)
def __init__(self, *, session: Optional[aiohttp.ClientSession] = None, loop=None, session_owner=True, **kwargs): if loop and sys.version_info >= (3, 10): raise ValueError("Starting with Python 3.10, asyncio doesn’t support loop as a parameter anymore") self._loop = loop self._session_owner = session_owner self.session = session self.connection_config = ConnectionConfiguration(**kwargs) self._use_env_settings = kwargs.pop('use_env_settings', True)
def __init__(self, *, session=None, loop=None, session_owner=True, **kwargs): self._loop = loop self._session_owner = session_owner self.session = session self.connection_config = ConnectionConfiguration(**kwargs) self._use_env_settings = kwargs.pop('use_env_settings', True)
def _set_universal(self, **kwargs): Configuration.__init__(self) self.connection = kwargs.get("connection_configuration", ConnectionConfiguration(**kwargs)) self.user_agent_policy = kwargs.get("user_agent_policy", UserAgentPolicy(**kwargs)) self.proxy_policy = kwargs.get("proxy_policy", ProxyPolicy(**kwargs)) self.logging_policy = kwargs.get("logging_policy", NetworkTraceLoggingPolicy(**kwargs)) self.headers_policy = kwargs.get("headers_policy", HeadersPolicy(**kwargs))
def test_retry_timeout(): timeout = 1 def send(request, **kwargs): assert kwargs["connection_timeout"] <= timeout, "policy should set connection_timeout not to exceed timeout" raise ServiceResponseError("oops") transport = Mock( spec=HttpTransport, send=Mock(wraps=send), connection_config=ConnectionConfiguration(connection_timeout=timeout * 2), sleep=time.sleep, ) pipeline = Pipeline(transport, [RetryPolicy(timeout=timeout)]) with pytest.raises(ServiceResponseTimeoutError): response = pipeline.run(HttpRequest("GET", "http://127.0.0.1/"))
async def test_retry_timeout(http_request): timeout = 1 def send(request, **kwargs): assert kwargs[ "connection_timeout"] <= timeout, "policy should set connection_timeout not to exceed timeout" raise ServiceResponseError("oops") transport = Mock( spec=AsyncHttpTransport, send=Mock(wraps=send), connection_config=ConnectionConfiguration(connection_timeout=timeout * 2), sleep=asyncio.sleep, ) pipeline = AsyncPipeline(transport, [AsyncRetryPolicy(timeout=timeout)]) with pytest.raises(ServiceResponseTimeoutError): await pipeline.run(http_request("GET", "http://localhost/"))
def __init__(self, **kwargs): # type: (Any) -> None self.session = kwargs.get('session', None) self._session_owner = kwargs.get('session_owner', True) self.connection_config = ConnectionConfiguration(**kwargs) self._use_env_settings = kwargs.pop('use_env_settings', True)