示例#1
0
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)
示例#2
0
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 == {}
示例#3
0
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 == {}
示例#4
0
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
示例#5
0
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
示例#6
0
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, )
示例#7
0
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,)
示例#8
0
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)
示例#9
0
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)
示例#10
0
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)