test_connections.py
This file
Path
tests/dispatch/test_connections.py
49 lines · 1.8 KiB · Python
Last changed by
Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
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) 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) 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) 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(origin=https_server.url, verify=ca_cert_pem_file) as conn:35 response = await conn.request("GET", https_server.url)36 await response.read()37 assert response.status_code == 20038 assert response.content == b"Hello, world!"394041async def test_https_get_with_sll_overrides(https_server, ca_cert_pem_file, backend):42 """43 An HTTPS request, with SSL configuration set on the request.44 """45 async with HTTPConnection(origin=https_server.url) as conn:46 response = await conn.request("GET", https_server.url, verify=ca_cert_pem_file)47 await response.read()48 assert response.status_code == 20049 assert response.content == b"Hello, world!"