test_config.py
This file
Path
tests/test_config.py
242 lines · 7.1 KiB · Python
Last changed by
Version 0.14.0 (#1083)Tom Christiebefore adoption8c7729e
History of this fileTake it
The walk stopped after 200 commits: lines older than c2eb0bd point at it.
Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 1–12why, one step back1import os2import ssl3import sys4from pathlib import Path56import certifi7import pytest89import httpx101112def test_load_ssl_config():Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 13why, one step back13 context = httpx.create_ssl_context()Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 14–19why, one step back14 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED15 assert context.check_hostname is True161718def test_load_ssl_config_verify_non_existing_path():19 with pytest.raises(IOError):Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 20why, one step back20 httpx.create_ssl_context(verify="/path/to/nowhere")Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 21–23why, one step back212223def test_load_ssl_config_verify_existing_file():Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 24why, one step back24 context = httpx.create_ssl_context(verify=certifi.where())Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 25–29why, one step back25 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED26 assert context.check_hostname is True272829@pytest.mark.parametrize("config", ("SSL_CERT_FILE", "SSL_CERT_DIR"))Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
lines 30–32why, one step back30def test_load_ssl_config_verify_env_file(31 https_server, ca_cert_pem_file, config, cert_authority32):Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 33–37why, one step back33 os.environ[config] = (34 ca_cert_pem_file35 if config.endswith("_FILE")36 else str(Path(ca_cert_pem_file).parent)37 )Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
lines 38–40why, one step back38 context = httpx.create_ssl_context(trust_env=True)39 cert_authority.configure_trust(context)40Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 41–42why, one step back41 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED42 assert context.check_hostname is TrueIncluded create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 43why, one step back43 assert len(context.get_ca_certs()) == 1Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 44–47why, one step back444546def test_load_ssl_config_verify_directory():47 path = Path(certifi.where()).parentIncluded create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 48why, one step back48 context = httpx.create_ssl_context(verify=str(path))Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 49–53why, one step back49 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED50 assert context.check_hostname is True515253def test_load_ssl_config_cert_and_key(cert_pem_file, cert_private_key_file):Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 54why, one step back54 context = httpx.create_ssl_context(cert=(cert_pem_file, cert_private_key_file))Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 55–62why, one step back55 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED56 assert context.check_hostname is True575859@pytest.mark.parametrize("password", [b"password", "password"])60def test_load_ssl_config_cert_and_encrypted_key(61 cert_pem_file, cert_encrypted_private_key_file, password62):Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 63why, one step back63 context = httpx.create_ssl_context(Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 64–73why, one step back64 cert=(cert_pem_file, cert_encrypted_private_key_file, password)65 )66 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED67 assert context.check_hostname is True686970def test_load_ssl_config_cert_and_key_invalid_password(71 cert_pem_file, cert_encrypted_private_key_file72):73 with pytest.raises(ssl.SSLError):Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
lines 74–76why, one step back74 httpx.create_ssl_context(75 cert=(cert_pem_file, cert_encrypted_private_key_file, "password1")76 )Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 77–80why, one step back777879def test_load_ssl_config_cert_without_key_raises(cert_pem_file):80 with pytest.raises(ssl.SSLError):Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 81why, one step back81 httpx.create_ssl_context(cert=cert_pem_file)Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 82–84why, one step back828384def test_load_ssl_config_no_verify():Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 85why, one step back85 context = httpx.create_ssl_context(verify=False)Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 86–91why, one step back86 assert context.verify_mode == ssl.VerifyMode.CERT_NONE87 assert context.check_hostname is False888990def test_load_ssl_context():91 ssl_context = ssl.create_default_context()Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 92why, one step back92 context = httpx.create_ssl_context(verify=ssl_context)Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
line 93why, one step back93Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 94why, one step back94 assert context is ssl_contextFix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 95–96why, one step back9596Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
lines 97–100why, one step back97def test_create_ssl_context_with_get_request(server, cert_pem_file):98 context = httpx.create_ssl_context(verify=cert_pem_file)99 response = httpx.get(server.url, verify=context)100 assert response.status_code == 200Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 101–103why, one step back101102103def test_limits_repr():Rename PoolLimits to Limits (#1113)Florimond Mancabefore adoptionf67e925
line 104why, one step back104 limits = httpx.Limits(max_connections=100)Update to httpcore 0.10 (#1126)Tom Christiebefore adoption876e722
line 105why, one step back105 assert repr(limits) == "Limits(max_connections=100, max_keepalive_connections=None)"Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 106–108why, one step back106107108def test_limits_eq():Rename PoolLimits to Limits (#1113)Florimond Mancabefore adoptionf67e925
lines 109–115why, one step back109 limits = httpx.Limits(max_connections=100)110 assert limits == httpx.Limits(max_connections=100)111112113def test_pool_limits_deprecated():114 with pytest.warns(DeprecationWarning):115 httpx.PoolLimits()Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 116–117why, one step back116117Version 0.14.0 (#1083)Tom Christiebefore adoption8c7729e
lines 118–122why, one step back118def test_max_keepalive_deprecated():119 with pytest.warns(DeprecationWarning):120 httpx.Limits(max_keepalive=50)121122Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 123–127why, one step back123def test_timeout_eq():124 timeout = httpx.Timeout(timeout=5.0)125 assert timeout == httpx.Timeout(timeout=5.0)126127httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4
line 128why, one step back128def test_timeout_all_parameters_set():Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5
line 129why, one step back129 timeout = httpx.Timeout(connect=5.0, read=5.0, write=5.0, pool=5.0)httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4
lines 130–132why, one step back130 assert timeout == httpx.Timeout(timeout=5.0)131132Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
line 133why, one step back133def test_timeout_from_nothing():httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4
line 134why, one step back134 timeout = httpx.Timeout(None)Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5
lines 135–138why, one step back135 assert timeout.connect is None136 assert timeout.read is None137 assert timeout.write is None138 assert timeout.pool is NoneFix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 139–142why, one step back139140141def test_timeout_from_none():142 timeout = httpx.Timeout(timeout=None)httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4
line 143why, one step back143 assert timeout == httpx.Timeout(None)Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 144–146why, one step back144145146def test_timeout_from_one_none_value():Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5
line 147why, one step back147 timeout = httpx.Timeout(None, read=None)httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4
line 148why, one step back148 assert timeout == httpx.Timeout(None)Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 149–151why, one step back149150151def test_timeout_from_one_value():Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5
line 152why, one step back152 timeout = httpx.Timeout(None, read=5.0)Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 153–156why, one step back153 assert timeout == httpx.Timeout(timeout=(None, 5.0, None, None))154155156def test_timeout_from_one_value_and_default():Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5
line 157why, one step back157 timeout = httpx.Timeout(5.0, pool=60.0)Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 158–160why, one step back158 assert timeout == httpx.Timeout(timeout=(5.0, 5.0, 5.0, 60.0))159160httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4
lines 161–162why, one step back161def test_timeout_missing_default():162 with pytest.warns(DeprecationWarning):Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5
line 163why, one step back163 timeout = httpx.Timeout(pool=60.0)httpx.Timeout must include a default (#1085)Tom Christiebefore adoptiondba83d4
lines 164–166why, one step back164 assert timeout == httpx.Timeout(timeout=(None, None, None, 60.0))165166Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 167–180why, one step back167def test_timeout_from_tuple():168 timeout = httpx.Timeout(timeout=(5.0, 5.0, 5.0, 5.0))169 assert timeout == httpx.Timeout(timeout=5.0)170171172def test_timeout_from_config_instance():173 timeout = httpx.Timeout(timeout=5.0)174 assert httpx.Timeout(timeout) == httpx.Timeout(timeout=5.0)175176177def test_timeout_repr():178 timeout = httpx.Timeout(timeout=5.0)179 assert repr(timeout) == "Timeout(timeout=5.0)"180Switch to more concise Timeout parameters (#1111)Florimond Mancabefore adoption26cd4f5
lines 181–182why, one step back181 timeout = httpx.Timeout(None, read=5.0)182 assert repr(timeout) == "Timeout(connect=None, read=5.0, write=None, pool=None)"Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 183–193why, one step back183184185@pytest.mark.skipif(186 not hasattr(ssl.SSLContext, "keylog_filename"),187 reason="requires OpenSSL 1.1.1 or higher",188)189@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")190def test_ssl_config_support_for_keylog_file(tmpdir, monkeypatch): # pragma: nocover191 with monkeypatch.context() as m:192 m.delenv("SSLKEYLOGFILE", raising=False)193Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 194why, one step back194 context = httpx.create_ssl_context(trust_env=True)Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
line 195why, one step back195Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 196why, one step back196 assert context.keylog_filename is None # type: ignoreFix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 197–202why, one step back197198 filename = str(tmpdir.join("test.log"))199200 with monkeypatch.context() as m:201 m.setenv("SSLKEYLOGFILE", filename)202Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 203why, one step back203 context = httpx.create_ssl_context(trust_env=True)Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
line 204why, one step back204Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 205why, one step back205 assert context.keylog_filename == filename # type: ignoreFix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
line 206why, one step back206Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 207why, one step back207 context = httpx.create_ssl_context(trust_env=False)Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
line 208why, one step back208Included create_ssl_context function to create the same context with SSLConfig and serve as API (#996)Can Sarıgölbefore adoption926a55a
line 209why, one step back209 assert context.keylog_filename is None # type: ignoreFix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 210–217why, one step back210211212@pytest.mark.parametrize(213 "url,expected_url,expected_headers,expected_mode",214 [215 ("https://example.com", "https://example.com", {}, "DEFAULT"),216 (217 "https://user:pass@example.com",URL.port becomes Optional[int] (#1080)Tom Christiebefore adoptionc089480
line 218why, one step back218 "https://example.com",Fix simple typo: conncurrent -> concurrent (#793)Tim Gatesbefore adoptionc2eb0bd
lines 219–242why, one step back219 {"proxy-authorization": "Basic dXNlcjpwYXNz"},220 "DEFAULT",221 ),222 ],223)224def test_proxy_from_url(url, expected_url, expected_headers, expected_mode):225 proxy = httpx.Proxy(url)226227 assert str(proxy.url) == expected_url228 assert dict(proxy.headers) == expected_headers229 assert proxy.mode == expected_mode230 assert repr(proxy) == "Proxy(url='{}', headers={}, mode='{}')".format(231 expected_url, str(expected_headers), expected_mode232 )233234235def test_invalid_proxy_scheme():236 with pytest.raises(ValueError):237 httpx.Proxy("invalid://example.com")238239240def test_invalid_proxy_mode():241 with pytest.raises(ValueError):242 httpx.Proxy("https://example.com", mode="INVALID")