Skip to content
Myr

test_config.py

This file

Path

tests/test_config.py

133 lines · 4.0 KiB · Python

Last changed by

Use pathlib.Path instead of os.path functions (#188)Stephen Brown IIbefore adoptionfde30b8

History of this file

Take it

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 1–4why, one step back
1import ssl
23import pytest4

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 5why, one step back
5import httpx

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 6–9why, one step back
6
78@pytest.mark.asyncio9async def test_load_ssl_config():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 10why, one step back
10 ssl_config = httpx.SSLConfig()

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 11–12why, one step back
11 context = await ssl_config.load_ssl_context()
12 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 13why, one step back
13 assert context.check_hostname is True

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 14–17why, one step back
14
1516@pytest.mark.asyncio17async def test_load_ssl_config_verify_non_existing_path():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 18why, one step back
18 ssl_config = httpx.SSLConfig(verify="/path/to/nowhere")

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 19–24why, one step back
19 with pytest.raises(IOError):
20 await ssl_config.load_ssl_context()212223@pytest.mark.asyncio24async def test_load_ssl_config_verify_existing_file():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 25why, one step back
25 ssl_config = httpx.SSLConfig(verify=httpx.config.DEFAULT_CA_BUNDLE_PATH)

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 26–27why, one step back
26 context = await ssl_config.load_ssl_context()
27 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 28why, one step back
28 assert context.check_hostname is True

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 29–32why, one step back
29
3031@pytest.mark.asyncio32async def test_load_ssl_config_verify_directory():

Use pathlib.Path instead of os.path functions (#188)Stephen Brown IIbefore adoptionfde30b8

line 33why, one step back
33 path = httpx.config.DEFAULT_CA_BUNDLE_PATH.parent

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 34why, one step back
34 ssl_config = httpx.SSLConfig(verify=path)

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 35–36why, one step back
35 context = await ssl_config.load_ssl_context()
36 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 37why, one step back
37 assert context.check_hostname is True

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 38–40why, one step back
38
3940@pytest.mark.asyncio

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 41why, one step back
41async def test_load_ssl_config_cert_and_key(cert_pem_file, cert_private_key_file):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 42why, one step back
42 ssl_config = httpx.SSLConfig(cert=(cert_pem_file, cert_private_key_file))

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 43–44why, one step back
43 context = await ssl_config.load_ssl_context()
44 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 45why, one step back
45 assert context.check_hostname is True

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 46–48why, one step back
46
4748@pytest.mark.asyncio

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

lines 49–52why, one step back
49@pytest.mark.parametrize("password", [b"password", "password"])
50async def test_load_ssl_config_cert_and_encrypted_key(51 cert_pem_file, cert_encrypted_private_key_file, password52):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 53why, one step back
53 ssl_config = httpx.SSLConfig(

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

lines 54–64why, one step back
54 cert=(cert_pem_file, cert_encrypted_private_key_file, password)
55 )56 context = await ssl_config.load_ssl_context()57 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED58 assert context.check_hostname is True596061@pytest.mark.asyncio62async def test_load_ssl_config_cert_and_key_invalid_password(63 cert_pem_file, cert_encrypted_private_key_file64):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 65why, one step back
65 ssl_config = httpx.SSLConfig(

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

lines 66–68why, one step back
66 cert=(cert_pem_file, cert_encrypted_private_key_file, "password1")
67 )68

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 69–70why, one step back
69 with pytest.raises(ssl.SSLError):
70 await ssl_config.load_ssl_context()

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 71–73why, one step back
71
7273@pytest.mark.asyncio

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 74why, one step back
74async def test_load_ssl_config_cert_without_key_raises(cert_pem_file):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 75why, one step back
75 ssl_config = httpx.SSLConfig(cert=cert_pem_file)

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

lines 76–81why, one step back
76 with pytest.raises(ssl.SSLError):
77 await ssl_config.load_ssl_context()787980@pytest.mark.asyncio81async def test_load_ssl_config_no_verify():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 82why, one step back
82 ssl_config = httpx.SSLConfig(verify=False)

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 83–84why, one step back
83 context = await ssl_config.load_ssl_context()
84 assert context.verify_mode == ssl.VerifyMode.CERT_NONE

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 85why, one step back
85 assert context.check_hostname is False

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 86–88why, one step back
86
8788def test_ssl_repr():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 89why, one step back
89 ssl = httpx.SSLConfig(verify=False)

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 90–93why, one step back
90 assert repr(ssl) == "SSLConfig(cert=None, verify=False)"
919293def test_timeout_repr():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 94why, one step back
94 timeout = httpx.TimeoutConfig(timeout=5.0)

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 95–96why, one step back
95 assert repr(timeout) == "TimeoutConfig(timeout=5.0)"
96

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 97why, one step back
97 timeout = httpx.TimeoutConfig(read_timeout=5.0)

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 98–99why, one step back
98 assert (
99 repr(timeout)

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 100why, one step back
100 == "TimeoutConfig(connect_timeout=None, read_timeout=5.0, write_timeout=None)"

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 101–104why, one step back
101 )
102103104def test_limits_repr():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 105why, one step back
105 limits = httpx.PoolLimits(hard_limit=100)

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 106–108why, one step back
106 assert (
107 repr(limits) == "PoolLimits(soft_limit=None, hard_limit=100, pool_timeout=None)"108 )

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 109–111why, one step back
109
110111def test_ssl_eq():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 112–113why, one step back
112 ssl = httpx.SSLConfig(verify=False)
113 assert ssl == httpx.SSLConfig(verify=False)

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 114–116why, one step back
114
115116def test_timeout_eq():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 117–118why, one step back
117 timeout = httpx.TimeoutConfig(timeout=5.0)
118 assert timeout == httpx.TimeoutConfig(timeout=5.0)

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 119–121why, one step back
119
120121def test_limits_eq():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 122–123why, one step back
122 limits = httpx.PoolLimits(hard_limit=100)
123 assert limits == httpx.PoolLimits(hard_limit=100)

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 124–126why, one step back
124
125126def test_timeout_from_tuple():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 127–128why, one step back
127 timeout = httpx.TimeoutConfig(timeout=(5.0, 5.0, 5.0))
128 assert timeout == httpx.TimeoutConfig(timeout=5.0)

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 129–131why, one step back
129
130131def test_timeout_from_config_instance():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 132–133why, one step back
132 timeout = httpx.TimeoutConfig(timeout=5.0)
133 assert httpx.TimeoutConfig(timeout) == httpx.TimeoutConfig(timeout=5.0)