Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ mypy
pytest
pytest-asyncio
pytest-cov
trustme
uvicorn
25 changes: 25 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import asyncio
import os

import pytest
import trustme
from uvicorn.config import Config
from uvicorn.main import Server

Expand Down Expand Up @@ -62,3 +64,26 @@ async def server():
finally:
server.should_exit = True
await task


@pytest.fixture
async def https_server():
ca = trustme.CA()
server_cert = ca.issue_cert("example.org")
with ca.cert_pem.tempfile() as cert_temp_path, ca.private_key_pem.tempfile() as key_temp_path:
config = Config(
app=app,
lifespan="off",
ssl_certfile=cert_temp_path,
ssl_keyfile=key_temp_path,
port=8001,
)
server = Server(config=config)
task = asyncio.ensure_future(server.serve())
try:
while not server.started:
await asyncio.sleep(0.0001)
yield server
finally:
server.should_exit = True
await task
10 changes: 9 additions & 1 deletion tests/dispatch/test_connections.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from httpcore import HTTPConnection, Request
from httpcore import HTTPConnection, Request, SSLConfig


@pytest.mark.asyncio
Expand All @@ -13,6 +13,14 @@ async def test_get(server):
assert response.content == b"Hello, world!"


@pytest.mark.asyncio
async def test_https_get(https_server):
http = HTTPConnection(origin="https://127.0.0.1:8001/", ssl=SSLConfig(verify=False))
response = await http.request("GET", "https://127.0.0.1:8001/")
assert response.status_code == 200
assert response.content == b"Hello, world!"


@pytest.mark.asyncio
async def test_post(server):
conn = HTTPConnection(origin="http://127.0.0.1:8000/")
Expand Down