Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run ASGI tests on trio too #1020

Merged
merged 1 commit into from
Jun 13, 2020
Merged
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
13 changes: 7 additions & 6 deletions tests/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,45 @@ async def raise_exc_after_response(scope, receive, send):
raise ValueError()


@pytest.mark.asyncio
@pytest.mark.usefixtures("async_environment")
async def test_asgi():
client = httpx.AsyncClient(app=hello_world)
response = await client.get("http://www.example.org/")
assert response.status_code == 200
assert response.text == "Hello, World!"


@pytest.mark.asyncio
@pytest.mark.usefixtures("async_environment")
async def test_asgi_upload():
client = httpx.AsyncClient(app=echo_body)
response = await client.post("http://www.example.org/", data=b"example")
assert response.status_code == 200
assert response.text == "example"


@pytest.mark.asyncio
@pytest.mark.usefixtures("async_environment")
async def test_asgi_exc():
client = httpx.AsyncClient(app=raise_exc)
with pytest.raises(ValueError):
await client.get("http://www.example.org/")


@pytest.mark.asyncio
@pytest.mark.usefixtures("async_environment")
async def test_asgi_http_error():
client = httpx.AsyncClient(app=partial(raise_exc, exc=httpx.HTTPError))
with pytest.raises(httpx.HTTPError):
await client.get("http://www.example.org/")


@pytest.mark.asyncio
@pytest.mark.usefixtures("async_environment")
async def test_asgi_exc_after_response():
client = httpx.AsyncClient(app=raise_exc_after_response)
with pytest.raises(ValueError):
await client.get("http://www.example.org/")


async def test_asgi_disconnect_after_response_complete(async_environment):
@pytest.mark.usefixtures("async_environment")
async def test_asgi_disconnect_after_response_complete():
disconnect = False

async def read_body(scope, receive, send):
Expand Down