Skip to content
Myr

test_config.py

This file

Path

tests/test_config.py

237 lines · 7.0 KiB · Python

Last changed by

Rename PoolLimits to Limits (#1113)Florimond Mancabefore adoptionf67e925

History of this file

Take it

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

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 1–12why, one step back
1import os
2import ssl3import sys4from pathlib import Path56import certifi7import pytest89import httpx101112def test_load_ssl_config():

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 13why, one step back
13 context = httpx.create_ssl_context()

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 14–19why, one step back
14 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
15 assert context.check_hostname is True161718def test_load_ssl_config_verify_non_existing_path():19 with pytest.raises(IOError):

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 20why, one step back
20 httpx.create_ssl_context(verify="/path/to/nowhere")

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 21–23why, one step back
21
2223def test_load_ssl_config_verify_existing_file():

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 24why, one step back
24 context = httpx.create_ssl_context(verify=certifi.where())

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 25–29why, one step back
25 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
26 assert context.check_hostname is True272829@pytest.mark.parametrize("config", ("SSL_CERT_FILE", "SSL_CERT_DIR"))

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

lines 30–32why, one step back
30def test_load_ssl_config_verify_env_file(
31 https_server, ca_cert_pem_file, config, cert_authority32):

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 33–37why, one step back
33 os.environ[config] = (
34 ca_cert_pem_file35 if config.endswith("_FILE")36 else str(Path(ca_cert_pem_file).parent)37 )

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

lines 38–40why, one step back
38 context = httpx.create_ssl_context(trust_env=True)
39 cert_authority.configure_trust(context)40

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 41–42why, one step back
41 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
42 assert context.check_hostname is True

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 43why, one step back
43 assert len(context.get_ca_certs()) == 1

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 44–47why, one step back
44
4546def test_load_ssl_config_verify_directory():47 path = Path(certifi.where()).parent

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 48why, one step back
48 context = httpx.create_ssl_context(verify=str(path))

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 49–53why, one step back
49 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
50 assert context.check_hostname is True515253def test_load_ssl_config_cert_and_key(cert_pem_file, cert_private_key_file):

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 54why, one step back
54 context = httpx.create_ssl_context(cert=(cert_pem_file, cert_private_key_file))

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 55–62why, one step back
55 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
56 assert context.check_hostname is True575859@pytest.mark.parametrize("password", [b"password", "password"])60def test_load_ssl_config_cert_and_encrypted_key(61 cert_pem_file, cert_encrypted_private_key_file, password62):

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 63why, one step back
63 context = httpx.create_ssl_context(

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 64–73why, one step back
64 cert=(cert_pem_file, cert_encrypted_private_key_file, password)
65 )66 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED67 assert context.check_hostname is True686970def test_load_ssl_config_cert_and_key_invalid_password(71 cert_pem_file, cert_encrypted_private_key_file72):73 with pytest.raises(ssl.SSLError):

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

lines 74–76why, one step back
74 httpx.create_ssl_context(
75 cert=(cert_pem_file, cert_encrypted_private_key_file, "password1")76 )

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 77–80why, one step back
77
7879def test_load_ssl_config_cert_without_key_raises(cert_pem_file):80 with pytest.raises(ssl.SSLError):

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 81why, one step back
81 httpx.create_ssl_context(cert=cert_pem_file)

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 82–84why, one step back
82
8384def test_load_ssl_config_no_verify():

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 85why, one step back
85 context = httpx.create_ssl_context(verify=False)

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 86–91why, one step back
86 assert context.verify_mode == ssl.VerifyMode.CERT_NONE
87 assert context.check_hostname is False888990def test_load_ssl_context():91 ssl_context = ssl.create_default_context()

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 92why, one step back
92 context = httpx.create_ssl_context(verify=ssl_context)

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

line 93why, one step back
93

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 94why, one step back
94 assert context is ssl_context

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 95–96why, one step back
95
96

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

lines 97–100why, one step back
97def test_create_ssl_context_with_get_request(server, cert_pem_file):
98 context = httpx.create_ssl_context(verify=cert_pem_file)99 response = httpx.get(server.url, verify=context)100 assert response.status_code == 200

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 101–103why, one step back
101
102103def test_limits_repr():

Rename PoolLimits to Limits (#1113)Florimond Mancabefore adoptionf67e925

lines 104–105why, one step back
104 limits = httpx.Limits(max_connections=100)
105 assert repr(limits) == "Limits(max_keepalive=None, max_connections=100)"

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 106–108why, one step back
106
107108def test_limits_eq():

Rename PoolLimits to Limits (#1113)Florimond Mancabefore adoptionf67e925

lines 109–115why, one step back
109 limits = httpx.Limits(max_connections=100)
110 assert limits == httpx.Limits(max_connections=100)111112113def test_pool_limits_deprecated():114 with pytest.warns(DeprecationWarning):115 httpx.PoolLimits()

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 116–122why, one step back
116
117118def test_timeout_eq():119 timeout = httpx.Timeout(timeout=5.0)120 assert timeout == httpx.Timeout(timeout=5.0)121122

httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4

line 123why, one step back
123def test_timeout_all_parameters_set():

Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5

line 124why, one step back
124 timeout = httpx.Timeout(connect=5.0, read=5.0, write=5.0, pool=5.0)

httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4

lines 125–127why, one step back
125 assert timeout == httpx.Timeout(timeout=5.0)
126127

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

line 128why, one step back
128def test_timeout_from_nothing():

httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4

line 129why, one step back
129 timeout = httpx.Timeout(None)

Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5

lines 130–133why, one step back
130 assert timeout.connect is None
131 assert timeout.read is None132 assert timeout.write is None133 assert timeout.pool is None

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 134–137why, one step back
134
135136def test_timeout_from_none():137 timeout = httpx.Timeout(timeout=None)

httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4

line 138why, one step back
138 assert timeout == httpx.Timeout(None)

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 139–141why, one step back
139
140141def test_timeout_from_one_none_value():

Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5

line 142why, one step back
142 timeout = httpx.Timeout(None, read=None)

httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4

line 143why, one step back
143 assert timeout == httpx.Timeout(None)

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 144–146why, one step back
144
145146def test_timeout_from_one_value():

Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5

line 147why, one step back
147 timeout = httpx.Timeout(None, read=5.0)

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 148–151why, one step back
148 assert timeout == httpx.Timeout(timeout=(None, 5.0, None, None))
149150151def test_timeout_from_one_value_and_default():

Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5

line 152why, one step back
152 timeout = httpx.Timeout(5.0, pool=60.0)

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 153–155why, one step back
153 assert timeout == httpx.Timeout(timeout=(5.0, 5.0, 5.0, 60.0))
154155

httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4

lines 156–157why, one step back
156def test_timeout_missing_default():
157 with pytest.warns(DeprecationWarning):

Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5

line 158why, one step back
158 timeout = httpx.Timeout(pool=60.0)

httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4

lines 159–161why, one step back
159 assert timeout == httpx.Timeout(timeout=(None, None, None, 60.0))
160161

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 162–175why, one step back
162def test_timeout_from_tuple():
163 timeout = httpx.Timeout(timeout=(5.0, 5.0, 5.0, 5.0))164 assert timeout == httpx.Timeout(timeout=5.0)165166167def test_timeout_from_config_instance():168 timeout = httpx.Timeout(timeout=5.0)169 assert httpx.Timeout(timeout) == httpx.Timeout(timeout=5.0)170171172def test_timeout_repr():173 timeout = httpx.Timeout(timeout=5.0)174 assert repr(timeout) == "Timeout(timeout=5.0)"175

Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5

lines 176–177why, one step back
176 timeout = httpx.Timeout(None, read=5.0)
177 assert repr(timeout) == "Timeout(connect=None, read=5.0, write=None, pool=None)"

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 178–188why, one step back
178
179180@pytest.mark.skipif(181 not hasattr(ssl.SSLContext, "keylog_filename"),182 reason="requires OpenSSL 1.1.1 or higher",183)184@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")185def test_ssl_config_support_for_keylog_file(tmpdir, monkeypatch): # pragma: nocover186 with monkeypatch.context() as m:187 m.delenv("SSLKEYLOGFILE", raising=False)188

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 189why, one step back
189 context = httpx.create_ssl_context(trust_env=True)

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

line 190why, one step back
190

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 191why, one step back
191 assert context.keylog_filename is None # type: ignore

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

lines 192–197why, one step back
192
193 filename = str(tmpdir.join("test.log"))194195 with monkeypatch.context() as m:196 m.setenv("SSLKEYLOGFILE", filename)197

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 198why, one step back
198 context = httpx.create_ssl_context(trust_env=True)

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

line 199why, one step back
199

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 200why, one step back
200 assert context.keylog_filename == filename # type: ignore

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

line 201why, one step back
201

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 202why, one step back
202 context = httpx.create_ssl_context(trust_env=False)

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

line 203why, one step back
203

Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a

line 204why, one step back
204 assert context.keylog_filename is None # type: ignore

Prep for introducing SyncClient (#713)Tom Christiebefore adoptionf17ab37

lines 205–206why, one step back
205
206

Detect credentials in proxy URLs and create Proxy-authorization header (#780)Yeray Diaz Diazbefore adoptionb234203

lines 207–212why, one step back
207@pytest.mark.parametrize(
208 "url,expected_url,expected_headers,expected_mode",209 [210 ("https://example.com", "https://example.com", {}, "DEFAULT"),211 (212 "https://user:pass@example.com",

URL.port becomes Optional[int] (#1080)Tom Christiebefore adoptionc089480

line 213why, one step back
213 "https://example.com",

Detect credentials in proxy URLs and create Proxy-authorization header (#780)Yeray Diaz Diazbefore adoptionb234203

lines 214–227why, one step back
214 {"proxy-authorization": "Basic dXNlcjpwYXNz"},
215 "DEFAULT",216 ),217 ],218)219def test_proxy_from_url(url, expected_url, expected_headers, expected_mode):220 proxy = httpx.Proxy(url)221222 assert str(proxy.url) == expected_url223 assert dict(proxy.headers) == expected_headers224 assert proxy.mode == expected_mode225 assert repr(proxy) == "Proxy(url='{}', headers={}, mode='{}')".format(226 expected_url, str(expected_headers), expected_mode227 )

Prep for introducing SyncClient (#713)Tom Christiebefore adoptionf17ab37

lines 228–237why, one step back
228
229230def test_invalid_proxy_scheme():231 with pytest.raises(ValueError):232 httpx.Proxy("invalid://example.com")233234235def test_invalid_proxy_mode():236 with pytest.raises(ValueError):237 httpx.Proxy("https://example.com", mode="INVALID")