test_config.py
This file
Path
tests/test_config.py
96 lines · 2.8 KiB · Python
Last changed by
Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
History of this fileTake it
Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
line 1why, one step back1import osFinessing interfaceTom Christiebefore adoptiond7619a9
lines 2–5why, one step back2import ssl34import pytest5Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde
line 6why, one step back6import httpcoreFinessing interfaceTom Christiebefore adoptiond7619a9
lines 7–13why, one step back789@pytest.mark.asyncio10async def test_load_ssl_config():11 ssl_config = httpcore.SSLConfig()12 context = await ssl_config.load_ssl_context()13 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIREDMerge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
lines 14–51why, one step back141516@pytest.mark.asyncio17async def test_load_ssl_config_verify_non_existing_path():18 ssl_config = httpcore.SSLConfig(verify="/path/to/nowhere")19 with pytest.raises(IOError):20 await ssl_config.load_ssl_context()212223@pytest.mark.asyncio24async def test_load_ssl_config_verify_existing_file():25 ssl_config = httpcore.SSLConfig(verify=httpcore.config.DEFAULT_CA_BUNDLE_PATH)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():32 path = os.path.dirname(httpcore.config.DEFAULT_CA_BUNDLE_PATH)33 ssl_config = httpcore.SSLConfig(verify=path)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_paths41 ssl_config = httpcore.SSLConfig(cert=(cert_path, key_path))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_paths49 ssl_config = httpcore.SSLConfig(cert=cert_path)50 with pytest.raises(ssl.SSLError):51 await ssl_config.load_ssl_context()Finessing interfaceTom Christiebefore adoptiond7619a9
lines 52–58why, one step back525354@pytest.mark.asyncio55async def test_load_ssl_config_no_verify(verify=False):56 ssl_config = httpcore.SSLConfig(verify=False)57 context = await ssl_config.load_ssl_context()58 assert context.verify_mode == ssl.VerifyMode.CERT_NONEMerge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde
lines 59–72why, one step back596061def test_ssl_repr():62 ssl = httpcore.SSLConfig(verify=False)63 assert repr(ssl) == "SSLConfig(cert=None, verify=False)"646566def test_timeout_repr():67 timeout = httpcore.TimeoutConfig(timeout=5.0)68 assert repr(timeout) == "TimeoutConfig(timeout=5.0)"6970 timeout = httpcore.TimeoutConfig(read_timeout=5.0)71 assert (72 repr(timeout)Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 73why, one step back73 == "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–78why, one step back74 )757677def test_limits_repr():78 limits = httpcore.PoolLimits(hard_limit=100)Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 79–81why, one step back79 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–96why, one step back828384def test_ssl_eq():85 ssl = httpcore.SSLConfig(verify=False)86 assert ssl == httpcore.SSLConfig(verify=False)878889def test_timeout_eq():90 timeout = httpcore.TimeoutConfig(timeout=5.0)91 assert timeout == httpcore.TimeoutConfig(timeout=5.0)929394def test_limits_eq():95 limits = httpcore.PoolLimits(hard_limit=100)96 assert limits == httpcore.PoolLimits(hard_limit=100)