Skip to content
Myr

test_config.py

This file

Path

tests/test_config.py

106 lines · 3.1 KiB · Python

Last changed by

http3 (#86)Tom Christiebefore adoptionc9747aa

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

http3 (#86)Tom Christiebefore adoptionc9747aa

line 6why, one step back
6import http3

Finessing interfaceTom Christiebefore adoptiond7619a9

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

http3 (#86)Tom Christiebefore adoptionc9747aa

line 11why, one step back
11 ssl_config = http3.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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

line 18why, one step back
18 ssl_config = http3.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():

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

lines 26–31why, one step back
26 context = await ssl_config.load_ssl_context()
27 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED282930@pytest.mark.asyncio31async def test_load_ssl_config_verify_directory():

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 32–33why, one step back
32 path = os.path.dirname(http3.config.DEFAULT_CA_BUNDLE_PATH)
33 ssl_config = http3.SSLConfig(verify=path)

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

lines 34–40why, one step back
34 context = await ssl_config.load_ssl_context()
35 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED363738@pytest.mark.asyncio39async def test_load_ssl_config_cert_and_key(cert_and_key_paths):40 cert_path, key_path = cert_and_key_paths

http3 (#86)Tom Christiebefore adoptionc9747aa

line 41why, one step back
41 ssl_config = http3.SSLConfig(cert=(cert_path, key_path))

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

lines 42–48why, one step back
42 context = await ssl_config.load_ssl_context()
43 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED444546@pytest.mark.asyncio47async def test_load_ssl_config_cert_without_key_raises(cert_and_key_paths):48 cert_path, _ = cert_and_key_paths

http3 (#86)Tom Christiebefore adoptionc9747aa

line 49why, one step back
49 ssl_config = http3.SSLConfig(cert=cert_path)

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

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

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 52–55why, one step back
52
5354@pytest.mark.asyncio55async def test_load_ssl_config_no_verify(verify=False):

http3 (#86)Tom Christiebefore adoptionc9747aa

line 56why, one step back
56 ssl_config = http3.SSLConfig(verify=False)

Finessing interfaceTom Christiebefore adoptiond7619a9

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

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 59–61why, one step back
59
6061def test_ssl_repr():

http3 (#86)Tom Christiebefore adoptionc9747aa

line 62why, one step back
62 ssl = http3.SSLConfig(verify=False)

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 63–66why, one step back
63 assert repr(ssl) == "SSLConfig(cert=None, verify=False)"
646566def test_timeout_repr():

http3 (#86)Tom Christiebefore adoptionc9747aa

line 67why, one step back
67 timeout = http3.TimeoutConfig(timeout=5.0)

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

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

http3 (#86)Tom Christiebefore adoptionc9747aa

line 70why, one step back
70 timeout = http3.TimeoutConfig(read_timeout=5.0)

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 71–72why, one step back
71 assert (
72 repr(timeout)

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 73why, one step back
73 == "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 74–77why, one step back
74 )
757677def test_limits_repr():

http3 (#86)Tom Christiebefore adoptionc9747aa

line 78why, one step back
78 limits = http3.PoolLimits(hard_limit=100)

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 79–81why, one step back
79 assert (
80 repr(limits) == "PoolLimits(soft_limit=None, hard_limit=100, pool_timeout=None)"81 )

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 85–86why, one step back
85 ssl = http3.SSLConfig(verify=False)
86 assert ssl == http3.SSLConfig(verify=False)

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 90–91why, one step back
90 timeout = http3.TimeoutConfig(timeout=5.0)
91 assert timeout == http3.TimeoutConfig(timeout=5.0)

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 92–94why, one step back
92
9394def test_limits_eq():

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 95–96why, one step back
95 limits = http3.PoolLimits(hard_limit=100)
96 assert limits == http3.PoolLimits(hard_limit=100)

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

lines 97–99why, one step back
97
9899def test_timeout_from_tuple():

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 100–101why, one step back
100 timeout = http3.TimeoutConfig(timeout=(5.0, 5.0, 5.0))
101 assert timeout == http3.TimeoutConfig(timeout=5.0)

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

lines 102–104why, one step back
102
103104def test_timeout_from_config_instance():

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 105–106why, one step back
105 timeout = http3.TimeoutConfig(timeout=(5.0))
106 assert http3.TimeoutConfig(timeout) == http3.TimeoutConfig(timeout=5.0)