Skip to content
Myr

test_client.py

This file

Path

tests/test_client.py

52 lines · 1.5 KiB · Python

Last changed by

Merge branch 'master' into wait-for-connection-closeTom Christiebefore adoption20bc1f3

History of this file

Take it

1import pytest23import httpcore456@pytest.mark.asyncio7async def test_get(server):8    url = "http://127.0.0.1:8000/"9    async with httpcore.Client() as client:10        response = await client.get(url)11    assert response.status_code == 20012    assert response.text == "Hello, world!"131415@pytest.mark.asyncio16async def test_post(server):17    url = "http://127.0.0.1:8000/"18    async with httpcore.Client() as client:19        response = await client.post(url, content=b"Hello, world!")20    assert response.status_code == 200212223@pytest.mark.asyncio24async def test_stream_response(server):25    async with httpcore.Client() as client:26        response = await client.request("GET", "http://127.0.0.1:8000/", stream=True)27    assert response.status_code == 20028    body = await response.read()29    assert body == b"Hello, world!"30    assert response.content == b"Hello, world!"313233@pytest.mark.asyncio34async def test_access_content_stream_response(server):35    async with httpcore.Client() as client:36        response = await client.request("GET", "http://127.0.0.1:8000/", stream=True)37    assert response.status_code == 20038    with pytest.raises(httpcore.ResponseNotRead):39        response.content404142@pytest.mark.asyncio43async def test_stream_request(server):44    async def hello_world():45        yield b"Hello, "46        yield b"world!"4748    async with httpcore.Client() as client:49        response = await client.request(50            "POST", "http://127.0.0.1:8000/", content=hello_world()51        )52    assert response.status_code == 200