def test_get_agent_with_http_proxy(): with mock.patch.dict('os.environ', {'http_proxy': 'http://localhost:8000'}): agent = fido.fido.get_agent( mock.Mock(spec=_twisted_web_client().Agent), connect_timeout=None) assert isinstance(agent, _twisted_web_client().ProxyAgent)
def test_headers_remove_content_length_if_body(header): headers = {header: '22'} body = b'{"some_json_data": 30}' bodyProducer, headers = _build_body_producer(body, headers) assert isinstance(bodyProducer, _twisted_web_client().FileBodyProducer) assert headers == {}
def test_get_agent_no_http_proxy_tcp_nodelay(): agent = fido.fido.get_agent(mock.Mock(spec=_twisted_web_client().Agent), connect_timeout=None, tcp_nodelay=True) from fido._client import HTTPConnectionPoolOverride from fido._client import HTTP11ClientFactoryOverride assert isinstance(agent._pool, HTTPConnectionPoolOverride) assert agent._pool._factory == HTTP11ClientFactoryOverride
def test_get_agent_with_http_proxy_tcp_nodelay(): with mock.patch.dict('os.environ', {'http_proxy': 'http://yelp.com:80'}): agent = fido.fido.get_agent( mock.Mock(spec=_twisted_web_client().Agent), connect_timeout=None, tcp_nodelay=True) from fido._client import HTTPConnectionPoolOverride from fido._client import HTTP11ClientFactoryOverride assert isinstance(agent._pool, HTTPConnectionPoolOverride) assert agent._pool._factory == HTTP11ClientFactoryOverride
def test_deferred_errback_chain(): """ Test exception thrown on the deferred correctly triggers the errback chain and it is thrown by EventualResult on result retrieval. """ d = Deferred() mock_agent = mock.Mock() mock_agent.request.return_value = d # careful while patching get_agent cause it's being accessed # by the reactor thread with mock.patch('fido.fido.get_agent', return_value=mock_agent): eventual_result = fido.fido.fetch('http://some_url') # trigger an exception on the deferred d.errback(_twisted_web_client().ResponseFailed(ERROR_MESSAGE)) with pytest.raises(_twisted_web_client().ResponseFailed) as e: eventual_result.wait(timeout=TIMEOUT_TEST) assert e.value.args == (ERROR_MESSAGE, )
def test_deferred_errback_chain(): """ Test exception thrown on the deferred correctly triggers the errback chain and it is thrown by EventualResult on result retrieval. """ d = Deferred() mock_agent = mock.Mock() mock_agent.request.return_value = d # careful while patching get_agent cause it's being accessed # by the reactor thread with mock.patch('fido.fido.get_agent', return_value=mock_agent): eventual_result = fido.fido.fetch('http://some_url') # trigger an exception on the deferred d.errback(_twisted_web_client().ResponseFailed(ERROR_MESSAGE)) with pytest.raises(_twisted_web_client().ResponseFailed) as e: eventual_result.wait(timeout=TIMEOUT_TEST) assert e.value.args == (ERROR_MESSAGE,)
def test_get_agent_no_http_proxy(): with mock.patch.dict('os.environ', clear=True): agent = fido.fido.get_agent( mock.Mock(spec=_twisted_web_client().Agent), connect_timeout=None) assert isinstance(agent, _twisted_web_client().Agent)