Skip to content

Commit 3dae923

Browse files
authored
Bugfix: use proxies from settings (#306)
* fix proxy bug, add tests * changelog
1 parent dc93438 commit 3dae923

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
1616

1717
- `sdk.legalhold.get_all_events()` to search for legal hold events.
1818

19+
### Fixed
20+
21+
- Bug where proxy settings were not being applied correctly.
22+
1923
## 1.12.0 - 2021-02-25
2024

2125
### Added

src/py42/services/_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def request(
188188
timeout=timeout,
189189
verify=settings.verify_ssl_certs,
190190
cert=cert,
191-
proxies=proxies,
191+
proxies=proxies or settings.proxies,
192192
)
193193

194194
if not stream and response is not None:

tests/services/test_connection.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from requests import Response
55
from tests.conftest import TEST_DEVICE_GUID
66

7+
import py42.settings as settings
78
from py42.exceptions import Py42DeviceNotConnectedError
89
from py42.exceptions import Py42Error
910
from py42.exceptions import Py42FeatureUnavailableError
@@ -88,6 +89,13 @@ def mock_not_connected_server_conn(mocker):
8889
return mock_conn
8990

9091

92+
@pytest.fixture
93+
def proxy_set():
94+
settings.proxies = {"https": "http://localhost:9999"}
95+
yield
96+
settings.proxies = None
97+
98+
9199
class MockPreparedRequest(object):
92100
def __init__(self, method, url, data=None):
93101
self._method = method
@@ -384,3 +392,20 @@ def test_connection_request_when_not_give_accept_header_sets_accept_to_applicati
384392
connection.put(URL, data='{"foo":"bar"}')
385393
request = success_requests_session.prepare_request.call_args[0][0]
386394
assert request.headers["Accept"] == "application/json"
395+
396+
def test_connection_request_when_proxies_set_passes_proxies_arg_to_session_send(
397+
self, proxy_set, mock_host_resolver, mock_auth, success_requests_session
398+
):
399+
connection = Connection(
400+
mock_host_resolver, mock_auth, session=success_requests_session
401+
)
402+
url = "https://example.com"
403+
connection.get(url)
404+
connection.post(url)
405+
connection.options(url)
406+
connection.put(url)
407+
connection.patch(url)
408+
connection.head(url)
409+
connection.delete(url)
410+
for call in success_requests_session.send.call_args_list:
411+
assert call[1]["proxies"] == {"https": "http://localhost:9999"}

0 commit comments

Comments
 (0)