test_proxies.py
This file
Path
tests/client/test_proxies.py
130 lines · 4.2 KiB · Python
Last changed by
Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067
History of this fileTake it
The walk stopped after 200 commits: lines older than 1e23855 point at it.
Warn if cert / verify / trust_env are passed to client.request() (#597)Tom Christiebefore adoption1e23855
lines 1–14why, one step back1import pytest23import httpx456@pytest.mark.parametrize(7 ["proxies", "expected_proxies"],8 [9 ("http://127.0.0.1", [("all", "http://127.0.0.1")]),10 ({"all": "http://127.0.0.1"}, [("all", "http://127.0.0.1")]),11 (12 {"http": "http://127.0.0.1", "https": "https://127.0.0.1"},13 [("http", "http://127.0.0.1"), ("https", "https://127.0.0.1")],14 ),Prep for introducing SyncClient (#713)Tom Christiebefore adoptionf17ab37
line 15why, one step back15 (httpx.Proxy("http://127.0.0.1"), [("all", "http://127.0.0.1")]),Warn if cert / verify / trust_env are passed to client.request() (#597)Tom Christiebefore adoption1e23855
line 16why, one step back16 (Prep for introducing SyncClient (#713)Tom Christiebefore adoptionf17ab37
line 17why, one step back17 {"https": httpx.Proxy("https://127.0.0.1"), "all": "http://127.0.0.1"},Warn if cert / verify / trust_env are passed to client.request() (#597)Tom Christiebefore adoption1e23855
lines 18–22why, one step back18 [("all", "http://127.0.0.1"), ("https", "https://127.0.0.1")],19 ),20 ],21)22def test_proxies_parameter(proxies, expected_proxies):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 23why, one step back23 client = httpx.AsyncClient(proxies=proxies)Warn if cert / verify / trust_env are passed to client.request() (#597)Tom Christiebefore adoption1e23855
lines 24–26why, one step back2425 for proxy_key, url in expected_proxies:26 assert proxy_key in client.proxiesHttpcore interface (#804)Tom Christiebefore adoption3046e92
line 27why, one step back27 assert client.proxies[proxy_key].proxy_origin == httpx.URL(url).raw[:3]Warn if cert / verify / trust_env are passed to client.request() (#597)Tom Christiebefore adoption1e23855
lines 28–76why, one step back2829 assert len(expected_proxies) == len(client.proxies)303132PROXY_URL = "http://[::1]"333435@pytest.mark.parametrize(36 ["url", "proxies", "expected"],37 [38 ("http://example.com", None, None),39 ("http://example.com", {}, None),40 ("http://example.com", {"https": PROXY_URL}, None),41 ("http://example.com", {"http://example.net": PROXY_URL}, None),42 ("http://example.com:443", {"http://example.com": PROXY_URL}, None),43 ("http://example.com", {"all": PROXY_URL}, PROXY_URL),44 ("http://example.com", {"http": PROXY_URL}, PROXY_URL),45 ("http://example.com", {"all://example.com": PROXY_URL}, PROXY_URL),46 ("http://example.com", {"all://example.com:80": PROXY_URL}, PROXY_URL),47 ("http://example.com", {"http://example.com": PROXY_URL}, PROXY_URL),48 ("http://example.com", {"http://example.com:80": PROXY_URL}, PROXY_URL),49 ("http://example.com:8080", {"http://example.com:8080": PROXY_URL}, PROXY_URL),50 ("http://example.com:8080", {"http://example.com": PROXY_URL}, None),51 (52 "http://example.com",53 {54 "all": PROXY_URL + ":1",55 "http": PROXY_URL + ":2",56 "all://example.com": PROXY_URL + ":3",57 "http://example.com": PROXY_URL + ":4",58 },59 PROXY_URL + ":4",60 ),61 (62 "http://example.com",63 {64 "all": PROXY_URL + ":1",65 "http": PROXY_URL + ":2",66 "all://example.com": PROXY_URL + ":3",67 },68 PROXY_URL + ":3",69 ),70 (71 "http://example.com",72 {"all": PROXY_URL + ":1", "http": PROXY_URL + ":2"},73 PROXY_URL + ":2",74 ),75 ],76)Transport API (#963)Yeray Diaz Diazbefore adoptiond2816c9
line 77why, one step back77def test_transport_for_request(url, proxies, expected):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 78why, one step back78 client = httpx.AsyncClient(proxies=proxies)Transport API (#963)Yeray Diaz Diazbefore adoptiond2816c9
line 79why, one step back79 transport = client.transport_for_url(httpx.URL(url))Warn if cert / verify / trust_env are passed to client.request() (#597)Tom Christiebefore adoption1e23855
lines 80–81why, one step back8081 if expected is None:Transport API (#963)Yeray Diaz Diazbefore adoptiond2816c9
line 82why, one step back82 assert transport is client.transportWarn if cert / verify / trust_env are passed to client.request() (#597)Tom Christiebefore adoption1e23855
line 83why, one step back83 else:Transport API (#963)Yeray Diaz Diazbefore adoptiond2816c9
line 84why, one step back84 assert transport.proxy_origin == httpx.URL(expected).raw[:3]Warn if cert / verify / trust_env are passed to client.request() (#597)Tom Christiebefore adoption1e23855
lines 85–86why, one step back8586Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067
lines 87–97why, one step back87@pytest.mark.asyncio88async def test_async_proxy_close():89 client = httpx.AsyncClient(proxies={"all": PROXY_URL})90 await client.aclose()919293def test_sync_proxy_close():94 client = httpx.Client(proxies={"all": PROXY_URL})95 client.close()9697Warn if cert / verify / trust_env are passed to client.request() (#597)Tom Christiebefore adoption1e23855
lines 98–99why, one step back98def test_unsupported_proxy_scheme():99 with pytest.raises(ValueError):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 100why, one step back100 httpx.AsyncClient(proxies="ftp://127.0.0.1")Enable NO_PROXY environment variable support (#835)Evan Lurveybefore adoption707e54c
lines 101–118why, one step back101102103@pytest.mark.parametrize(104 ["url", "env", "expected"],105 [106 ("http://google.com", {}, None),107 (108 "http://google.com",109 {"HTTP_PROXY": "http://example.com"},110 "http://example.com",111 ),112 (113 "http://google.com",114 {"HTTP_PROXY": "http://example.com", "NO_PROXY": "google.com"},115 None,116 ),117 ],118)Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
lines 119–120why, one step back119@pytest.mark.parametrize("client_class", [httpx.Client, httpx.AsyncClient])120def test_proxies_environ(monkeypatch, client_class, url, env, expected):Enable NO_PROXY environment variable support (#835)Evan Lurveybefore adoption707e54c
lines 121–123why, one step back121 for name, value in env.items():122 monkeypatch.setenv(name, value)123Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
line 124why, one step back124 client = client_class()Transport API (#963)Yeray Diaz Diazbefore adoptiond2816c9
line 125why, one step back125 transport = client.transport_for_url(httpx.URL(url))Enable NO_PROXY environment variable support (#835)Evan Lurveybefore adoption707e54c
lines 126–127why, one step back126127 if expected is None:Transport API (#963)Yeray Diaz Diazbefore adoptiond2816c9
line 128why, one step back128 assert transport == client.transportEnable NO_PROXY environment variable support (#835)Evan Lurveybefore adoption707e54c
line 129why, one step back129 else:Transport API (#963)Yeray Diaz Diazbefore adoptiond2816c9
line 130why, one step back130 assert transport.proxy_origin == httpx.URL(expected).raw[:3]