11# (C) 2021 GoodData Corporation
2- from gooddata_sdk import GoodDataApiClient
2+ import os
3+ from unittest import mock
4+
5+ from gooddata_sdk import GoodDataApiClient , GoodDataSdk
36
47
58def test_http_headers_precedence ():
@@ -12,3 +15,62 @@ def test_http_headers_precedence():
1215 agent = c ._api_client .default_headers ["User-Agent" ]
1316 assert agent .startswith ("gooddata" )
1417 assert agent .endswith ("yes" )
18+
19+
20+ class TestProxy :
21+ """Proxy configuration for the underlying urllib3 pool manager."""
22+
23+ @mock .patch .dict (os .environ , {}, clear = True )
24+ def test_no_proxy_when_env_empty (self ):
25+ c = GoodDataApiClient ("https://example.com" , "token" )
26+ assert c ._api_config .proxy is None
27+
28+ def test_explicit_proxy (self ):
29+ c = GoodDataApiClient ("https://example.com" , "token" , proxy = "http://myproxy:8080" )
30+ assert c ._api_config .proxy == "http://myproxy:8080"
31+
32+ @mock .patch .dict (os .environ , {"HTTPS_PROXY" : "http://envproxy:3128" }, clear = True )
33+ def test_proxy_from_https_proxy_env (self ):
34+ c = GoodDataApiClient ("https://example.com" , "token" )
35+ assert c ._api_config .proxy == "http://envproxy:3128"
36+
37+ @mock .patch .dict (os .environ , {"https_proxy" : "http://lower:3128" }, clear = True )
38+ def test_proxy_from_lowercase_https_proxy_env (self ):
39+ c = GoodDataApiClient ("https://example.com" , "token" )
40+ assert c ._api_config .proxy == "http://lower:3128"
41+
42+ @mock .patch .dict (os .environ , {"HTTP_PROXY" : "http://httpproxy:3128" }, clear = True )
43+ def test_proxy_from_http_proxy_env (self ):
44+ c = GoodDataApiClient ("https://example.com" , "token" )
45+ assert c ._api_config .proxy == "http://httpproxy:3128"
46+
47+ @mock .patch .dict (
48+ os .environ ,
49+ {
50+ "HTTPS_PROXY" : "http://preferred:3128" ,
51+ "HTTP_PROXY" : "http://fallback:3128" ,
52+ },
53+ clear = True ,
54+ )
55+ def test_https_proxy_takes_precedence_over_http_proxy (self ):
56+ c = GoodDataApiClient ("https://example.com" , "token" )
57+ assert c ._api_config .proxy == "http://preferred:3128"
58+
59+ @mock .patch .dict (os .environ , {"HTTPS_PROXY" : "http://envproxy:3128" }, clear = True )
60+ def test_explicit_proxy_overrides_env (self ):
61+ c = GoodDataApiClient ("https://example.com" , "token" , proxy = "http://explicit:8080" )
62+ assert c ._api_config .proxy == "http://explicit:8080"
63+
64+ def test_sdk_create_with_explicit_proxy (self ):
65+ sdk = GoodDataSdk .create ("https://example.com" , "token" , proxy = "http://myproxy:8080" )
66+ assert sdk .client ._api_config .proxy == "http://myproxy:8080"
67+
68+ @mock .patch .dict (os .environ , {"HTTPS_PROXY" : "http://envproxy:3128" }, clear = True )
69+ def test_sdk_create_picks_up_env_proxy (self ):
70+ sdk = GoodDataSdk .create ("https://example.com" , "token" )
71+ assert sdk .client ._api_config .proxy == "http://envproxy:3128"
72+
73+ @mock .patch .dict (os .environ , {}, clear = True )
74+ def test_sdk_create_no_proxy_when_env_empty (self ):
75+ sdk = GoodDataSdk .create ("https://example.com" , "token" )
76+ assert sdk .client ._api_config .proxy is None
0 commit comments