Skip to content
Myr

Add test to https server

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add `https_server` test fixture

authored by Yeray Diaz Diaz · committed by Yeray Diaz Diaz · parent 21ac95a · Browse files · 3 files+35 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+35 added−1 removed

  • tests:+34 added−1 removed
  • other:+1 added−0 removed

3 files+35 added−1 removed

modified:tests/dispatch/test_connections.py+9 added-1 removed
1import pytest23from httpcore import HTTPConnection, Request3from httpcore import HTTPConnection, Request, SSLConfig456@pytest.mark.asyncio7async def test_get(server):
5 unmodified lines
13 assert response.content == b"Hello, world!"141516@pytest.mark.asyncio17async def test_https_get(https_server):18 http = HTTPConnection(origin="https://127.0.0.1:8001/", ssl=SSLConfig(verify=False))19 response = await http.request("GET", "https://127.0.0.1:8001/")20 assert response.status_code == 20021 assert response.content == b"Hello, world!"222324@pytest.mark.asyncio25async def test_post(server):26 conn = HTTPConnection(origin="http://127.0.0.1:8000/")27 request = Request("GET", "http://127.0.0.1:8000/", data=b"Hello, world!")28 request.prepare()
2 unmodified lines
modified:tests/conftest.py+25 added
1import asyncio2import os34import pytest5import trustme6from uvicorn.config import Config7from uvicorn.main import Server89
53 unmodified lines
63 yield server64 finally:65 server.should_exit = True66 await task676869@pytest.fixture70async def https_server():71 ca = trustme.CA()72 server_cert = ca.issue_cert("example.org")73 with ca.cert_pem.tempfile() as cert_temp_path, ca.private_key_pem.tempfile() as key_temp_path:74 config = Config(75 app=app,76 lifespan="off",77 ssl_certfile=cert_temp_path,78 ssl_keyfile=key_temp_path,79 port=8001,80 )81 server = Server(config=config)82 task = asyncio.ensure_future(server.serve())83 try:84 while not server.started:85 await asyncio.sleep(0.0001)86 yield server87 finally:88 server.should_exit = True89 await task
modified:requirements.txt+1 added
15 unmodified lines
16mypy17pytest18pytest-asyncio19pytest-cov20trustme21uvicorn