Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
[API-5329] Yehor/api 5329 added bs proxy support (#136)
Browse files Browse the repository at this point in the history
* Brought back env proxy settings support since we use overrided flow present in requests.request method

* Fixed issue with exception at history loggin on 0 requests case

* Added case for wrong proxy setup

* Comments cleanup

* Dopped unused variable
  • Loading branch information
nimnull authored and Axik committed Aug 16, 2018
1 parent b03b681 commit 7b7ad81
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
6 changes: 5 additions & 1 deletion datarobot_batch_scoring/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from time import time
from concurrent.futures import FIRST_COMPLETED
from concurrent.futures import wait

from requests.utils import get_environ_proxies

try:
from futures import ThreadPoolExecutor
except ImportError:
Expand Down Expand Up @@ -106,7 +109,8 @@ def _request(self, request):

try:
prepared = self.session.prepare_request(request)
self.session.send(prepared, timeout=self._timeout)
proxies = get_environ_proxies(prepared.url)
self.session.send(prepared, timeout=self._timeout, proxies=proxies)
except Exception as exc:
code = 400
exc_tuple = (
Expand Down
2 changes: 2 additions & 0 deletions datarobot_batch_scoring/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ def warn_if_redirected(req, ui):
test whether a request was redirect.
Log a warning to the user if it was redirected
"""
if req is None:
return
history = req.history
if history:
first = history[0]
Expand Down
42 changes: 42 additions & 0 deletions tests/test_network.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest

from datarobot_batch_scoring.batch_scoring import run_batch_predictions
Expand Down Expand Up @@ -294,3 +296,43 @@ def test_lost_retry(live_server, tmpdir, ui):
expected = f.read().splitlines()
expected.sort()
assert actual == expected


def test_os_env_proxy_handling(live_server, tmpdir, ui):
os.environ["HTTP_PROXY"] = "http://localhost"

out = tmpdir.join('out.csv')
base_url = '{webhost}/predApi/v1.0/'.format(webhost=live_server.url())
with pytest.raises(SystemExit):
ret = run_batch_predictions(
base_url=base_url,
base_headers={},
user='username',
pwd='password',
api_token=None,
create_api_token=False,
pid='56dd9570018e213242dfa93c',
lid='56dd9570018e213242dfa93d',
import_id=None,
n_retry=1,
concurrent=2,
resume=False,
n_samples=1,
out_file=str(out),
keep_cols=None,
delimiter=None,
dataset='tests/fixtures/temperatura_predict.csv.gz',
pred_name=None,
timeout=None,
ui=ui,
auto_sample=False,
fast_mode=False,
dry_run=False,
encoding='',
skip_dialect=False
)
assert ret is 1

logs = read_logs()
assert "Failed to establish a new connection" in logs
os.environ["HTTP_PROXY"] = ""

0 comments on commit 7b7ad81

Please sign in to comment.