Skip to content
Myr

test_config.py

This file

Path

tests/test_config.py

184 lines · 5.4 KiB · Python

Last changed by

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

History of this file

Take it

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

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

line 1why, one step back
1import ssl

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

line 2why, one step back
2import typing

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

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

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

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

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

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():

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

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

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

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

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

line 20why, one step back
20 context.load_verify_locations(cafile="/path/to/nowhere")

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

lines 21–22why, one step back
21
22

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

lines 23–24why, one step back
23def test_load_ssl_with_keylog(monkeypatch: typing.Any) -> None:
24 monkeypatch.setenv("SSLKEYLOGFILE", "test")

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

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

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

line 26why, one step back
26 assert context.keylog_filename == "test"

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

lines 27–28why, one step back
27
28

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

line 29why, one step back
29def test_load_ssl_config_verify_existing_file():

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

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

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

line 31why, one step back
31 context.load_verify_locations(capath=certifi.where())

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

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():

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

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

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

line 38why, one step back
38 context.load_verify_locations(capath=Path(certifi.where()).parent)

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

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):

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

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

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

line 45why, one step back
45 context.load_cert_chain(cert_pem_file, cert_private_key_file)

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

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):

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

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

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

line 55why, one step back
55 context.load_cert_chain(cert_pem_file, cert_encrypted_private_key_file, password)

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

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):

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

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

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

lines 65–66why, one step back
65 context.load_cert_chain(
66 cert_pem_file, cert_encrypted_private_key_file, "password1"

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

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):

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

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

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

line 73why, one step back
73 context.load_cert_chain(cert_pem_file)

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

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

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

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

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

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

line 82why, one step back
82def test_SSLContext_with_get_request(server, cert_pem_file):

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

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

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

line 84why, one step back
84 context.load_verify_locations(cert_pem_file)

Graceful upgrade path for 0.28. (#3394)Tom Christiebefore adoption1805ee0

line 85why, one step back
85 response = httpx.get(server.url, verify=context)

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

line 86why, one step back
86 assert response.status_code == 200

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

lines 87–90why, one step back
87
8889def test_limits_repr():90 limits = httpx.Limits(max_connections=100)

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

lines 91–94why, one step back
91 expected = (
92 "Limits(max_connections=100, max_keepalive_connections=None,"93 " keepalive_expiry=5.0)"94 )

Bump coverage from 7.2.1 to 7.2.2 (#2641)dependabot[bot]before adoptionab8177c

lines 95–184why, one step back
95 assert repr(limits) == expected
969798def test_limits_eq():99 limits = httpx.Limits(max_connections=100)100 assert limits == httpx.Limits(max_connections=100)101102103def test_timeout_eq():104 timeout = httpx.Timeout(timeout=5.0)105 assert timeout == httpx.Timeout(timeout=5.0)106107108def test_timeout_all_parameters_set():109 timeout = httpx.Timeout(connect=5.0, read=5.0, write=5.0, pool=5.0)110 assert timeout == httpx.Timeout(timeout=5.0)111112113def test_timeout_from_nothing():114 timeout = httpx.Timeout(None)115 assert timeout.connect is None116 assert timeout.read is None117 assert timeout.write is None118 assert timeout.pool is None119120121def test_timeout_from_none():122 timeout = httpx.Timeout(timeout=None)123 assert timeout == httpx.Timeout(None)124125126def test_timeout_from_one_none_value():127 timeout = httpx.Timeout(None, read=None)128 assert timeout == httpx.Timeout(None)129130131def test_timeout_from_one_value():132 timeout = httpx.Timeout(None, read=5.0)133 assert timeout == httpx.Timeout(timeout=(None, 5.0, None, None))134135136def test_timeout_from_one_value_and_default():137 timeout = httpx.Timeout(5.0, pool=60.0)138 assert timeout == httpx.Timeout(timeout=(5.0, 5.0, 5.0, 60.0))139140141def test_timeout_missing_default():142 with pytest.raises(ValueError):143 httpx.Timeout(pool=60.0)144145146def test_timeout_from_tuple():147 timeout = httpx.Timeout(timeout=(5.0, 5.0, 5.0, 5.0))148 assert timeout == httpx.Timeout(timeout=5.0)149150151def test_timeout_from_config_instance():152 timeout = httpx.Timeout(timeout=5.0)153 assert httpx.Timeout(timeout) == httpx.Timeout(timeout=5.0)154155156def test_timeout_repr():157 timeout = httpx.Timeout(timeout=5.0)158 assert repr(timeout) == "Timeout(timeout=5.0)"159160 timeout = httpx.Timeout(None, read=5.0)161 assert repr(timeout) == "Timeout(connect=None, read=5.0, write=None, pool=None)"162163164def test_proxy_from_url():165 proxy = httpx.Proxy("https://example.com")166167 assert str(proxy.url) == "https://example.com"168 assert proxy.auth is None169 assert proxy.headers == {}170 assert repr(proxy) == "Proxy('https://example.com')"171172173def test_proxy_with_auth_from_url():174 proxy = httpx.Proxy("https://username:password@example.com")175176 assert str(proxy.url) == "https://example.com"177 assert proxy.auth == ("username", "password")178 assert proxy.headers == {}179 assert repr(proxy) == "Proxy('https://example.com', auth=('username', '********'))"180181182def test_invalid_proxy_scheme():183 with pytest.raises(ValueError):184 httpx.Proxy("invalid://example.com")