Skip to content
Myr

test_proxies.py

This file

Path

tests/client/test_proxies.py

90 lines · 3.1 KiB · Python

Last changed by

Prep for introducing SyncClient (#713)Tom Christiebefore adoptionf17ab37

History of this file

Take it

The walk stopped after 200 commits: lines older than 1b82a2a point at it.

Fix invalid f-string (#375)秋葉before adoption1b82a2a

lines 1–14why, one step back
1import pytest
23import 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 back
15 (httpx.Proxy("http://127.0.0.1"), [("all", "http://127.0.0.1")]),

Fix invalid f-string (#375)秋葉before adoption1b82a2a

line 16why, one step back
16 (

Prep for introducing SyncClient (#713)Tom Christiebefore adoptionf17ab37

line 17why, one step back
17 {"https": httpx.Proxy("https://127.0.0.1"), "all": "http://127.0.0.1"},

Fix invalid f-string (#375)秋葉before adoption1b82a2a

lines 18–22why, one step back
18 [("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 back
23 client = httpx.AsyncClient(proxies=proxies)

Fix invalid f-string (#375)秋葉before adoption1b82a2a

lines 24–29why, one step back
24
25 for proxy_key, url in expected_proxies:26 assert proxy_key in client.proxies27 assert client.proxies[proxy_key].proxy_url == url2829 assert len(expected_proxies) == len(client.proxies)

Propogate HTTPProxy config from Client(#377)Seth Michael Larsonbefore adoption336d22d

lines 30–31why, one step back
30
31

Get test suite back to ~100% line coverage (#406)Seth Michael Larsonbefore adoption05f5dc2

lines 32–77why, one step back
32PROXY_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)77def test_dispatcher_for_request(url, proxies, expected):

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

line 78why, one step back
78 client = httpx.AsyncClient(proxies=proxies)

Clean up '_dispatcher_for_request' into 'dispatcher_for_url' (#561)Tom Christiebefore adoptione045b86

line 79why, one step back
79 dispatcher = client.dispatcher_for_url(httpx.URL(url))

Get test suite back to ~100% line coverage (#406)Seth Michael Larsonbefore adoption05f5dc2

lines 80–89why, one step back
80
81 if expected is None:82 assert dispatcher is client.dispatch83 else:84 assert isinstance(dispatcher, httpx.HTTPProxy)85 assert dispatcher.proxy_url == expected868788def test_unsupported_proxy_scheme():89 with pytest.raises(ValueError):

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

line 90why, one step back
90 httpx.AsyncClient(proxies="ftp://127.0.0.1")