Skip to content
Myr

test_config.py

This file

Path

tests/test_config.py

134 lines · 4.0 KiB · Python

Last changed by

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

History of this file

Take it

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

line 1why, one step back
1import os

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 2–5why, one step back
2import ssl
34import pytest5

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 6why, one step back
6import httpx

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 7–10why, one step back
7
89@pytest.mark.asyncio10async def test_load_ssl_config():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Finessing interfaceTom Christiebefore adoptiond7619a9

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

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

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

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

lines 15–18why, one step back
15
1617@pytest.mark.asyncio18async def test_load_ssl_config_verify_non_existing_path():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

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

lines 20–25why, one step back
20 with pytest.raises(IOError):
21 await ssl_config.load_ssl_context()222324@pytest.mark.asyncio25async def test_load_ssl_config_verify_existing_file():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

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

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

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

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

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

lines 30–33why, one step back
30
3132@pytest.mark.asyncio33async def test_load_ssl_config_verify_directory():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 34–35why, one step back
34 path = os.path.dirname(httpx.config.DEFAULT_CA_BUNDLE_PATH)
35 ssl_config = httpx.SSLConfig(verify=path)

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

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

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

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

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

lines 39–41why, one step back
39
4041@pytest.mark.asyncio

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

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

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

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

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

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

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

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

lines 47–49why, one step back
47
4849@pytest.mark.asyncio

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

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

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

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

lines 55–65why, one step back
55 cert=(cert_pem_file, cert_encrypted_private_key_file, password)
56 )57 context = await ssl_config.load_ssl_context()58 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED59 assert context.check_hostname is True606162@pytest.mark.asyncio63async def test_load_ssl_config_cert_and_key_invalid_password(64 cert_pem_file, cert_encrypted_private_key_file65):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

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

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

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

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

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 72–74why, one step back
72
7374@pytest.mark.asyncio

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

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

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

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

lines 77–82why, one step back
77 with pytest.raises(ssl.SSLError):
78 await ssl_config.load_ssl_context()798081@pytest.mark.asyncio82async def test_load_ssl_config_no_verify():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Finessing interfaceTom Christiebefore adoptiond7619a9

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

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

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

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 87–89why, one step back
87
8889def test_ssl_repr():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 91–94why, one step back
91 assert repr(ssl) == "SSLConfig(cert=None, verify=False)"
929394def test_timeout_repr():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

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

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

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

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 101why, one step back
101 == "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 102–105why, one step back
102 )
103104105def test_limits_repr():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

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

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 110–112why, one step back
110
111112def test_ssl_eq():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 115–117why, one step back
115
116117def test_timeout_eq():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 120–122why, one step back
120
121122def test_limits_eq():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

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

lines 125–127why, one step back
125
126127def test_timeout_from_tuple():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

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

lines 130–132why, one step back
130
131132def test_timeout_from_config_instance():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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