test_connections.py
This file
Path
tests/dispatch/test_connections.py
44 lines · 1.5 KiB · Python
Last changed by
SSLConfig refactor (#706)Tom Christiebefore adoptionb0bf2a7
History of this fileTake it
1import pytest23import httpx4from httpx.config import SSLConfig5from httpx.dispatch.connection import HTTPConnection678@pytest.mark.usefixtures("async_environment")9async def test_get(server):10 async with HTTPConnection(origin=server.url) as conn:11 response = await conn.request("GET", server.url)12 await response.aread()13 assert response.status_code == 20014 assert response.content == b"Hello, world!"151617@pytest.mark.usefixtures("async_environment")18async def test_post(server):19 async with HTTPConnection(origin=server.url) as conn:20 response = await conn.request("GET", server.url, data=b"Hello, world!")21 assert response.status_code == 200222324@pytest.mark.usefixtures("async_environment")25async def test_premature_close(server):26 with pytest.raises(httpx.ConnectionClosed):27 async with HTTPConnection(origin=server.url) as conn:28 response = await conn.request(29 "GET", server.url.copy_with(path="/premature_close")30 )31 await response.aread()323334@pytest.mark.usefixtures("async_environment")35async def test_https_get_with_ssl(https_server, ca_cert_pem_file):36 """37 An HTTPS request, with SSL configuration set on the client.38 """39 ssl = SSLConfig(verify=ca_cert_pem_file)40 async with HTTPConnection(origin=https_server.url, ssl=ssl) as conn:41 response = await conn.request("GET", https_server.url)42 await response.aread()43 assert response.status_code == 20044 assert response.content == b"Hello, world!"