test_connections.py
This file
Path
tests/dispatch/test_connections.py
51 lines · 1.9 KiB · Python
Last changed by
Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
History of this fileTake it
1import pytest23import httpx4from httpx.dispatch.connection import HTTPConnection567async def test_get(server, backend):8 async with HTTPConnection(origin=server.url, backend=backend) as conn:9 response = await conn.request("GET", server.url)10 await response.read()11 assert response.status_code == 20012 assert response.content == b"Hello, world!"131415async def test_post(server, backend):16 async with HTTPConnection(origin=server.url, backend=backend) as conn:17 response = await conn.request("GET", server.url, data=b"Hello, world!")18 assert response.status_code == 200192021async def test_premature_close(server, backend):22 with pytest.raises(httpx.ConnectionClosed):23 async with HTTPConnection(origin=server.url, backend=backend) as conn:24 response = await conn.request(25 "GET", server.url.copy_with(path="/premature_close")26 )27 await response.read()282930async def test_https_get_with_ssl_defaults(https_server, ca_cert_pem_file, backend):31 """32 An HTTPS request, with default SSL configuration set on the client.33 """34 async with HTTPConnection(35 origin=https_server.url, verify=ca_cert_pem_file, backend=backend36 ) as conn:37 response = await conn.request("GET", https_server.url)38 await response.read()39 assert response.status_code == 20040 assert response.content == b"Hello, world!"414243async def test_https_get_with_sll_overrides(https_server, ca_cert_pem_file, backend):44 """45 An HTTPS request, with SSL configuration set on the request.46 """47 async with HTTPConnection(origin=https_server.url, backend=backend) as conn:48 response = await conn.request("GET", https_server.url, verify=ca_cert_pem_file)49 await response.read()50 assert response.status_code == 20051 assert response.content == b"Hello, world!"