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
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))
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))
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))
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'
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'
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)
def test_requests_context_invalid_retries(): env = Variables(environ={'PEX_HTTP_RETRIES': '-1'}) with pytest.raises(ValueError): RequestsContext(verify=False, env=env)
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)
def test_requests_context_invalid_retries(): with pytest.raises(ValueError): RequestsContext(verify=False, max_retries=-1)
def get_network_context(self): # TODO(wickman): Add retry, conn_timeout, threads, etc configuration here. return RequestsContext()
def test_requests_context_timeout_from_environment(): timeout = '42' env = Variables({'PEX_HTTP_TIMEOUT': timeout}) assert RequestsContext(verify=False, env=env)._timeout == int(timeout)