Skip to content
Myr

test_api.py

This file

Path

tests/test_api.py

45 lines · 1.4 KiB · Python

Last changed by

Refactor to request = Client.send(request)Tom Christiebefore adoptionbe77498

History of this file

Take it

1import pytest23import httpcore456@pytest.mark.asyncio7async def test_get(server):8    async with httpcore.ConnectionPool() as client:9        request = httpcore.Request("GET", "http://127.0.0.1:8000/")10        response = await client.send(request)11    assert response.status_code == 20012    assert response.body == b"Hello, world!"131415@pytest.mark.asyncio16async def test_post(server):17    async with httpcore.ConnectionPool() as client:18        request = httpcore.Request(19            "POST", "http://127.0.0.1:8000/", body=b"Hello, world!"20        )21        response = await client.send(request)22    assert response.status_code == 200232425@pytest.mark.asyncio26async def test_stream_response(server):27    async with httpcore.ConnectionPool() as client:28        request = httpcore.Request("GET", "http://127.0.0.1:8000/")29        response = await client.send(request, stream=True)30    assert response.status_code == 20031    assert not hasattr(response, "body")32    body = await response.read()33    assert body == b"Hello, world!"343536@pytest.mark.asyncio37async def test_stream_request(server):38    async def hello_world():39        yield b"Hello, "40        yield b"world!"4142    async with httpcore.ConnectionPool() as client:43        request = httpcore.Request("POST", "http://127.0.0.1:8000/", body=hello_world())44        response = await client.send(request)45    assert response.status_code == 200