@@ -55,107 +55,154 @@ def test_transport_option(monkeypatch):
5555 assert str (Client (transport = transport ).dsn ) == dsn
5656
5757
58- def test_proxy_http_use (monkeypatch ):
59- client = Client ("http://foo@sentry.io/123" , http_proxy = "http://localhost/123" )
60- assert client .transport ._pool .proxy .scheme == "http"
61-
62-
63- def test_proxy_https_use (monkeypatch ):
64- client = Client ("https://foo@sentry.io/123" , http_proxy = "https://localhost/123" )
65- assert client .transport ._pool .proxy .scheme == "https"
66-
67-
68- def test_proxy_both_select_http (monkeypatch ):
69- client = Client (
70- "http://foo@sentry.io/123" ,
71- https_proxy = "https://localhost/123" ,
72- http_proxy = "http://localhost/123" ,
73- )
74- assert client .transport ._pool .proxy .scheme == "http"
75-
76-
77- def test_proxy_both_select_https (monkeypatch ):
78- client = Client (
79- "https://foo@sentry.io/123" ,
80- https_proxy = "https://localhost/123" ,
81- http_proxy = "http://localhost/123" ,
82- )
83- assert client .transport ._pool .proxy .scheme == "https"
84-
85-
86- def test_proxy_http_fallback_http (monkeypatch ):
87- client = Client ("https://foo@sentry.io/123" , http_proxy = "http://localhost/123" )
88- assert client .transport ._pool .proxy .scheme == "http"
89-
90-
91- def test_proxy_none_noenv (monkeypatch ):
92- client = Client ("http://foo@sentry.io/123" )
93- assert client .transport ._pool .proxy is None
94-
95-
96- def test_proxy_none_httpenv_select (monkeypatch ):
97- monkeypatch .setenv ("HTTP_PROXY" , "http://localhost/123" )
98- client = Client ("http://foo@sentry.io/123" )
99- assert client .transport ._pool .proxy .scheme == "http"
100-
101-
102- def test_proxy_none_httpsenv_select (monkeypatch ):
103- monkeypatch .setenv ("HTTPS_PROXY" , "https://localhost/123" )
104- client = Client ("https://foo@sentry.io/123" )
105- assert client .transport ._pool .proxy .scheme == "https"
106-
107-
108- def test_proxy_none_httpenv_fallback (monkeypatch ):
109- monkeypatch .setenv ("HTTP_PROXY" , "http://localhost/123" )
110- client = Client ("https://foo@sentry.io/123" )
111- assert client .transport ._pool .proxy .scheme == "http"
112-
113-
114- def test_proxy_bothselect_bothen (monkeypatch ):
115- monkeypatch .setenv ("HTTP_PROXY" , "http://localhost/123" )
116- monkeypatch .setenv ("HTTPS_PROXY" , "https://localhost/123" )
117- client = Client ("https://foo@sentry.io/123" , http_proxy = "" , https_proxy = "" )
118- assert client .transport ._pool .proxy is None
119-
120-
121- def test_proxy_bothavoid_bothenv (monkeypatch ):
122- monkeypatch .setenv ("HTTP_PROXY" , "http://localhost/123" )
123- monkeypatch .setenv ("HTTPS_PROXY" , "https://localhost/123" )
124- client = Client ("https://foo@sentry.io/123" , http_proxy = None , https_proxy = None )
125- assert client .transport ._pool .proxy .scheme == "https"
126-
127-
128- def test_proxy_bothselect_httpenv (monkeypatch ):
129- monkeypatch .setenv ("HTTP_PROXY" , "http://localhost/123" )
130- client = Client ("https://foo@sentry.io/123" , http_proxy = None , https_proxy = None )
131- assert client .transport ._pool .proxy .scheme == "http"
132-
133-
134- def test_proxy_httpselect_bothenv (monkeypatch ):
135- monkeypatch .setenv ("HTTP_PROXY" , "http://localhost/123" )
136- monkeypatch .setenv ("HTTPS_PROXY" , "https://localhost/123" )
137- client = Client ("https://foo@sentry.io/123" , http_proxy = None , https_proxy = "" )
138- assert client .transport ._pool .proxy .scheme == "http"
139-
140-
141- def test_proxy_httpsselect_bothenv (monkeypatch ):
142- monkeypatch .setenv ("HTTP_PROXY" , "http://localhost/123" )
143- monkeypatch .setenv ("HTTPS_PROXY" , "https://localhost/123" )
144- client = Client ("https://foo@sentry.io/123" , http_proxy = "" , https_proxy = None )
145- assert client .transport ._pool .proxy .scheme == "https"
146-
147-
148- def test_proxy_httpselect_httpsenv (monkeypatch ):
149- monkeypatch .setenv ("HTTPS_PROXY" , "https://localhost/123" )
150- client = Client ("https://foo@sentry.io/123" , http_proxy = None , https_proxy = "" )
151- assert client .transport ._pool .proxy is None
152-
153-
154- def test_proxy_httpsselect_bothenv_http (monkeypatch ):
155- monkeypatch .setenv ("HTTP_PROXY" , "http://localhost/123" )
156- monkeypatch .setenv ("HTTPS_PROXY" , "https://localhost/123" )
157- client = Client ("http://foo@sentry.io/123" , http_proxy = None , https_proxy = None )
158- assert client .transport ._pool .proxy .scheme == "http"
58+ @pytest .mark .parametrize (
59+ "testcase" ,
60+ [
61+ {
62+ "dsn" : "http://foo@sentry.io/123" ,
63+ "env_http_proxy" : None ,
64+ "env_https_proxy" : None ,
65+ "arg_http_proxy" : "http://localhost/123" ,
66+ "arg_https_proxy" : None ,
67+ "expected_proxy_scheme" : "http" ,
68+ },
69+ {
70+ "dsn" : "https://foo@sentry.io/123" ,
71+ "env_http_proxy" : None ,
72+ "env_https_proxy" : None ,
73+ "arg_http_proxy" : "https://localhost/123" ,
74+ "arg_https_proxy" : None ,
75+ "expected_proxy_scheme" : "https" ,
76+ },
77+ {
78+ "dsn" : "http://foo@sentry.io/123" ,
79+ "env_http_proxy" : None ,
80+ "env_https_proxy" : None ,
81+ "arg_http_proxy" : "http://localhost/123" ,
82+ "arg_https_proxy" : "https://localhost/123" ,
83+ "expected_proxy_scheme" : "http" ,
84+ },
85+ {
86+ "dsn" : "https://foo@sentry.io/123" ,
87+ "env_http_proxy" : None ,
88+ "env_https_proxy" : None ,
89+ "arg_http_proxy" : "http://localhost/123" ,
90+ "arg_https_proxy" : "https://localhost/123" ,
91+ "expected_proxy_scheme" : "https" ,
92+ },
93+ {
94+ "dsn" : "https://foo@sentry.io/123" ,
95+ "env_http_proxy" : None ,
96+ "env_https_proxy" : None ,
97+ "arg_http_proxy" : "http://localhost/123" ,
98+ "arg_https_proxy" : None ,
99+ "expected_proxy_scheme" : "http" ,
100+ },
101+ {
102+ "dsn" : "http://foo@sentry.io/123" ,
103+ "env_http_proxy" : None ,
104+ "env_https_proxy" : None ,
105+ "arg_http_proxy" : None ,
106+ "arg_https_proxy" : None ,
107+ "expected_proxy_scheme" : None ,
108+ },
109+ {
110+ "dsn" : "http://foo@sentry.io/123" ,
111+ "env_http_proxy" : "http://localhost/123" ,
112+ "env_https_proxy" : None ,
113+ "arg_http_proxy" : None ,
114+ "arg_https_proxy" : None ,
115+ "expected_proxy_scheme" : "http" ,
116+ },
117+ {
118+ "dsn" : "https://foo@sentry.io/123" ,
119+ "env_http_proxy" : None ,
120+ "env_https_proxy" : "https://localhost/123" ,
121+ "arg_http_proxy" : None ,
122+ "arg_https_proxy" : None ,
123+ "expected_proxy_scheme" : "https" ,
124+ },
125+ {
126+ "dsn" : "https://foo@sentry.io/123" ,
127+ "env_http_proxy" : "http://localhost/123" ,
128+ "env_https_proxy" : None ,
129+ "arg_http_proxy" : None ,
130+ "arg_https_proxy" : None ,
131+ "expected_proxy_scheme" : "http" ,
132+ },
133+ {
134+ "dsn" : "https://foo@sentry.io/123" ,
135+ "env_http_proxy" : "http://localhost/123" ,
136+ "env_https_proxy" : "https://localhost/123" ,
137+ "arg_http_proxy" : "" ,
138+ "arg_https_proxy" : "" ,
139+ "expected_proxy_scheme" : None ,
140+ },
141+ {
142+ "dsn" : "https://foo@sentry.io/123" ,
143+ "env_http_proxy" : "http://localhost/123" ,
144+ "env_https_proxy" : "https://localhost/123" ,
145+ "arg_http_proxy" : None ,
146+ "arg_https_proxy" : None ,
147+ "expected_proxy_scheme" : "https" ,
148+ },
149+ {
150+ "dsn" : "https://foo@sentry.io/123" ,
151+ "env_http_proxy" : "http://localhost/123" ,
152+ "env_https_proxy" : None ,
153+ "arg_http_proxy" : None ,
154+ "arg_https_proxy" : None ,
155+ "expected_proxy_scheme" : "http" ,
156+ },
157+ {
158+ "dsn" : "https://foo@sentry.io/123" ,
159+ "env_http_proxy" : "http://localhost/123" ,
160+ "env_https_proxy" : "https://localhost/123" ,
161+ "arg_http_proxy" : None ,
162+ "arg_https_proxy" : "" ,
163+ "expected_proxy_scheme" : "http" ,
164+ },
165+ {
166+ "dsn" : "https://foo@sentry.io/123" ,
167+ "env_http_proxy" : "http://localhost/123" ,
168+ "env_https_proxy" : "https://localhost/123" ,
169+ "arg_http_proxy" : "" ,
170+ "arg_https_proxy" : None ,
171+ "expected_proxy_scheme" : "https" ,
172+ },
173+ {
174+ "dsn" : "https://foo@sentry.io/123" ,
175+ "env_http_proxy" : None ,
176+ "env_https_proxy" : "https://localhost/123" ,
177+ "arg_http_proxy" : None ,
178+ "arg_https_proxy" : "" ,
179+ "expected_proxy_scheme" : None ,
180+ },
181+ {
182+ "dsn" : "http://foo@sentry.io/123" ,
183+ "env_http_proxy" : "http://localhost/123" ,
184+ "env_https_proxy" : "https://localhost/123" ,
185+ "arg_http_proxy" : None ,
186+ "arg_https_proxy" : None ,
187+ "expected_proxy_scheme" : "http" ,
188+ },
189+ ],
190+ )
191+ def test_proxy (monkeypatch , testcase ):
192+ if testcase ["env_http_proxy" ] is not None :
193+ monkeypatch .setenv ("HTTP_PROXY" , testcase ["env_http_proxy" ])
194+ if testcase ["env_https_proxy" ] is not None :
195+ monkeypatch .setenv ("HTTPS_PROXY" , testcase ["env_https_proxy" ])
196+ kwargs = {}
197+ if testcase ["arg_http_proxy" ] is not None :
198+ kwargs ["http_proxy" ] = testcase ["arg_http_proxy" ]
199+ if testcase ["arg_https_proxy" ] is not None :
200+ kwargs ["https_proxy" ] = testcase ["arg_https_proxy" ]
201+ client = Client (testcase ["dsn" ], ** kwargs )
202+ if testcase ["expected_proxy_scheme" ] is None :
203+ assert client .transport ._pool .proxy is None
204+ else :
205+ assert client .transport ._pool .proxy .scheme == testcase ["expected_proxy_scheme" ]
159206
160207
161208def test_simple_transport (sentry_init ):
0 commit comments