Skip to content
Myr

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 file

Take it

1import os2import ssl34import pytest56import httpcore789@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_REQUIRED141516@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()525354@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_NONE596061def 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)73        == "TimeoutConfig(connect_timeout=None, read_timeout=5.0, write_timeout=None)"74    )757677def test_limits_repr():78    limits = httpcore.PoolLimits(hard_limit=100)79    assert (80        repr(limits) == "PoolLimits(soft_limit=None, hard_limit=100, pool_timeout=None)"81    )828384def 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)