예제 #1
0
파일: test_http.py 프로젝트: Houzz/pex
def test_requests_context_retries_connect_timeout():
  with mock.patch.object(
      requests.packages.urllib3.connectionpool.HTTPConnectionPool,
      '_make_request') as mock_make_request:

    url, mock_make_request.side_effect = timeout_side_effect()

    context = RequestsContext(verify=False)

    data = context.read(Link.wrap(url))
    assert data == BLOB
예제 #2
0
def test_requests_context_retries_connect_timeout():
    with mock.patch.object(
            requests.packages.urllib3.connectionpool.HTTPConnectionPool,
            '_make_request') as mock_make_request:

        url, mock_make_request.side_effect = timeout_side_effect()

        context = RequestsContext(verify=False)

        data = context.read(Link.wrap(url))
        assert data == BLOB
예제 #3
0
파일: test_http.py 프로젝트: ewdurbin/pex
def test_requests_context_retries_connect_timeout_retries_exhausted():
  with mock.patch.object(
      requests.packages.urllib3.connectionpool.HTTPConnectionPool,
      '_make_request') as mock_make_request:

    url, mock_make_request.side_effect = timeout_side_effect(num_timeouts=3)

    context = RequestsContext(verify=False, max_retries=2)

    with pytest.raises(Context.Error):
      context.read(Link.wrap(url))
예제 #4
0
파일: test_http.py 프로젝트: Houzz/pex
def test_requests_context_retries_connect_timeout_retries_exhausted():
  with mock.patch.object(
      requests.packages.urllib3.connectionpool.HTTPConnectionPool,
      '_make_request') as mock_make_request:

    url, mock_make_request.side_effect = timeout_side_effect(num_timeouts=3)
    env = Variables(environ={'PEX_HTTP_RETRIES': '2'})

    context = RequestsContext(verify=False, env=env)

    with pytest.raises(Context.Error):
      context.read(Link.wrap(url))
예제 #5
0
def test_requests_context_retries_connect_timeout_retries_exhausted():
    with mock.patch.object(
            requests.packages.urllib3.connectionpool.HTTPConnectionPool,
            '_make_request') as mock_make_request:

        url, mock_make_request.side_effect = timeout_side_effect(
            num_timeouts=3)

        context = RequestsContext(verify=False, max_retries=2)

        with pytest.raises(Context.Error):
            context.read(Link.wrap(url))
예제 #6
0
def test_requests_context_retries_connect_timeout_retries_exhausted():
  with mock.patch.object(
      requests.packages.urllib3.connectionpool.HTTPConnectionPool,
      '_make_request') as mock_make_request:

    url, mock_make_request.side_effect = timeout_side_effect(num_timeouts=3)
    env = Variables(environ={'PEX_HTTP_RETRIES': '2'})

    context = RequestsContext(verify=False, env=env)

    with pytest.raises(Context.Error):
      context.read(Link.wrap(url))
예제 #7
0
파일: test_http.py 프로젝트: Houzz/pex
def test_requests_context():
  context = RequestsContext(verify=False)

  with make_url(BLOB, make_md5(BLOB)) as url:
    assert context.read(Link.wrap(url)) == BLOB

  with make_url(BLOB, make_md5(BLOB)) as url:
    filename = context.fetch(Link.wrap(url))
    with open(filename, 'rb') as fp:
      assert fp.read() == BLOB

  # test local reading
  with named_temporary_file() as tf:
    tf.write(b'goop')
    tf.flush()
    assert context.read(Link.wrap(tf.name)) == b'goop'
예제 #8
0
def test_requests_context():
    context = RequestsContext(verify=False)

    with make_url(BLOB, make_md5(BLOB)) as url:
        assert context.read(Link.wrap(url)) == BLOB

    with make_url(BLOB, make_md5(BLOB)) as url:
        filename = context.fetch(Link.wrap(url))
        with open(filename, 'rb') as fp:
            assert fp.read() == BLOB

    # test local reading
    with temporary_file() as tf:
        tf.write(b'goop')
        tf.flush()
        assert context.read(Link.wrap(tf.name)) == b'goop'
예제 #9
0
def test_requests_context_retries_from_environment():
    retry_count = '42'
    env = Variables({'PEX_HTTP_RETRIES': retry_count})
    assert RequestsContext(verify=False,
                           env=env)._max_retries == int(retry_count)
예제 #10
0
def test_requests_context_invalid_retries():
    env = Variables(environ={'PEX_HTTP_RETRIES': '-1'})
    with pytest.raises(ValueError):
        RequestsContext(verify=False, env=env)
예제 #11
0
def test_requests_context_retries_from_environment():

    retry_count = '42'
    with mock.patch.dict('os.environ', {'PEX_HTTP_RETRIES': retry_count}):
        assert RequestsContext(verify=False)._max_retries == int(retry_count)
예제 #12
0
def test_requests_context_invalid_retries():
    with pytest.raises(ValueError):
        RequestsContext(verify=False, max_retries=-1)
예제 #13
0
 def get_network_context(self):
     # TODO(wickman): Add retry, conn_timeout, threads, etc configuration here.
     return RequestsContext()
예제 #14
0
def test_requests_context_timeout_from_environment():
    timeout = '42'
    env = Variables({'PEX_HTTP_TIMEOUT': timeout})
    assert RequestsContext(verify=False, env=env)._timeout == int(timeout)