Skip to content
Myr

test_config.py

This file

Path

tests/test_config.py

205 lines · 5.8 KiB · Python

Last changed by

made dependencies on certifi and httpcore only load when required (#3377)Joe Marshallbefore adoptione9cabc8

History of this file

Take it

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

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

line 1why, one step back
1import ssl

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

line 2why, one step back
2import typing

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 3–11why, one step back
3from pathlib import Path
45import certifi6import pytest78import httpx91011def test_load_ssl_config():

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

line 12why, one step back
12 context = httpx.SSLContext()

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 13–16why, one step back
13 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
14 assert context.check_hostname is True1516

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

line 17why, one step back
17def test_load_ssl_config_verify_non_existing_file():

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

line 18why, one step back
18 with pytest.raises(IOError):

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

lines 19–20why, one step back
19 context = httpx.SSLContext()
20 context.load_verify_locations(cafile="/path/to/nowhere")

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 21–22why, one step back
21
22

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

lines 23–26why, one step back
23def test_load_ssl_with_keylog(monkeypatch: typing.Any) -> None:
24 monkeypatch.setenv("SSLKEYLOGFILE", "test")25 context = httpx.SSLContext()26 assert context.keylog_filename == "test"

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 27–28why, one step back
27
28

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

lines 29–31why, one step back
29def test_load_ssl_config_verify_existing_file():
30 context = httpx.SSLContext()31 context.load_verify_locations(capath=certifi.where())

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 32–36why, one step back
32 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
33 assert context.check_hostname is True343536def test_load_ssl_config_verify_directory():

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

lines 37–38why, one step back
37 context = httpx.SSLContext()
38 context.load_verify_locations(capath=Path(certifi.where()).parent)

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 39–43why, one step back
39 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
40 assert context.check_hostname is True414243def test_load_ssl_config_cert_and_key(cert_pem_file, cert_private_key_file):

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

lines 44–45why, one step back
44 context = httpx.SSLContext()
45 context.load_cert_chain(cert_pem_file, cert_private_key_file)

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 46–53why, one step back
46 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
47 assert context.check_hostname is True484950@pytest.mark.parametrize("password", [b"password", "password"])51def test_load_ssl_config_cert_and_encrypted_key(52 cert_pem_file, cert_encrypted_private_key_file, password53):

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

lines 54–55why, one step back
54 context = httpx.SSLContext()
55 context.load_cert_chain(cert_pem_file, cert_encrypted_private_key_file, password)

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 56–63why, one step back
56 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
57 assert context.check_hostname is True585960def test_load_ssl_config_cert_and_key_invalid_password(61 cert_pem_file, cert_encrypted_private_key_file62):63 with pytest.raises(ssl.SSLError):

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

lines 64–66why, one step back
64 context = httpx.SSLContext()
65 context.load_cert_chain(66 cert_pem_file, cert_encrypted_private_key_file, "password1"

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 67–71why, one step back
67 )
686970def test_load_ssl_config_cert_without_key_raises(cert_pem_file):71 with pytest.raises(ssl.SSLError):

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

lines 72–73why, one step back
72 context = httpx.SSLContext()
73 context.load_cert_chain(cert_pem_file)

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 74–76why, one step back
74
7576def test_load_ssl_config_no_verify():

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

line 77why, one step back
77 context = httpx.SSLContext(verify=False)

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 78–81why, one step back
78 assert context.verify_mode == ssl.VerifyMode.CERT_NONE
79 assert context.check_hostname is False8081

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

lines 82–86why, one step back
82def test_SSLContext_with_get_request(server, cert_pem_file):
83 context = httpx.SSLContext()84 context.load_verify_locations(cert_pem_file)85 response = httpx.get(server.url, ssl_context=context)86 assert response.status_code == 200

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 87–88why, one step back
87
88

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

lines 89–90why, one step back
89def test_SSLContext_repr():
90 ssl_context = httpx.SSLContext()

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

line 91why, one step back
91

Introduce new `SSLContext` API & escalate deprecations. (#3319)Tom Christiebefore adoption8e36f2b

line 92why, one step back
92 assert repr(ssl_context) == "<SSLContext(verify=True)>"

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 93–96why, one step back
93
9495def test_limits_repr():96 limits = httpx.Limits(max_connections=100)

Ruff linter: Use the default line-length (#2922)T-256before adoptionfd60b18

lines 97–100why, one step back
97 expected = (
98 "Limits(max_connections=100, max_keepalive_connections=None,"99 " keepalive_expiry=5.0)"100 )

Drop private imports from test_urlparse.py (#2572)Florimond Mancabefore adoptiona934c36

lines 101–190why, one step back
101 assert repr(limits) == expected
102103104def test_limits_eq():105 limits = httpx.Limits(max_connections=100)106 assert limits == httpx.Limits(max_connections=100)107108109def test_timeout_eq():110 timeout = httpx.Timeout(timeout=5.0)111 assert timeout == httpx.Timeout(timeout=5.0)112113114def test_timeout_all_parameters_set():115 timeout = httpx.Timeout(connect=5.0, read=5.0, write=5.0, pool=5.0)116 assert timeout == httpx.Timeout(timeout=5.0)117118119def test_timeout_from_nothing():120 timeout = httpx.Timeout(None)121 assert timeout.connect is None122 assert timeout.read is None123 assert timeout.write is None124 assert timeout.pool is None125126127def test_timeout_from_none():128 timeout = httpx.Timeout(timeout=None)129 assert timeout == httpx.Timeout(None)130131132def test_timeout_from_one_none_value():133 timeout = httpx.Timeout(None, read=None)134 assert timeout == httpx.Timeout(None)135136137def test_timeout_from_one_value():138 timeout = httpx.Timeout(None, read=5.0)139 assert timeout == httpx.Timeout(timeout=(None, 5.0, None, None))140141142def test_timeout_from_one_value_and_default():143 timeout = httpx.Timeout(5.0, pool=60.0)144 assert timeout == httpx.Timeout(timeout=(5.0, 5.0, 5.0, 60.0))145146147def test_timeout_missing_default():148 with pytest.raises(ValueError):149 httpx.Timeout(pool=60.0)150151152def test_timeout_from_tuple():153 timeout = httpx.Timeout(timeout=(5.0, 5.0, 5.0, 5.0))154 assert timeout == httpx.Timeout(timeout=5.0)155156157def test_timeout_from_config_instance():158 timeout = httpx.Timeout(timeout=5.0)159 assert httpx.Timeout(timeout) == httpx.Timeout(timeout=5.0)160161162def test_timeout_repr():163 timeout = httpx.Timeout(timeout=5.0)164 assert repr(timeout) == "Timeout(timeout=5.0)"165166 timeout = httpx.Timeout(None, read=5.0)167 assert repr(timeout) == "Timeout(connect=None, read=5.0, write=None, pool=None)"168169170def test_proxy_from_url():171 proxy = httpx.Proxy("https://example.com")172173 assert str(proxy.url) == "https://example.com"174 assert proxy.auth is None175 assert proxy.headers == {}176 assert repr(proxy) == "Proxy('https://example.com')"177178179def test_proxy_with_auth_from_url():180 proxy = httpx.Proxy("https://username:password@example.com")181182 assert str(proxy.url) == "https://example.com"183 assert proxy.auth == ("username", "password")184 assert proxy.headers == {}185 assert repr(proxy) == "Proxy('https://example.com', auth=('username', '********'))"186187188def test_invalid_proxy_scheme():189 with pytest.raises(ValueError):190 httpx.Proxy("invalid://example.com")

made dependencies on certifi and httpcore only load when required (#3377)Joe Marshallbefore adoptione9cabc8

lines 191–205why, one step back
191
192193def test_certifi_lazy_loading():194 global httpx, certifi195 import sys196197 del sys.modules["httpx"]198 del sys.modules["certifi"]199 del httpx200 del certifi201 import httpx202203 assert "certifi" not in sys.modules204 _context = httpx.SSLContext()205 assert "certifi" in sys.modules