Skip to content
Myr

test_api.py

This file

Path

tests/test_api.py

43 lines · 1.2 KiB · Python

Last changed by

Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7

History of this file

Take it

1import pytest23import httpcore456@pytest.mark.asyncio7async def test_get(server):8    async with httpcore.ConnectionPool() as http:9        response = await http.request("GET", "http://127.0.0.1:8000/")10    assert response.status_code == 20011    assert response.body == b"Hello, world!"121314@pytest.mark.asyncio15async def test_post(server):16    async with httpcore.ConnectionPool() as http:17        response = await http.request(18            "POST", "http://127.0.0.1:8000/", body=b"Hello, world!"19        )20    assert response.status_code == 200212223@pytest.mark.asyncio24async def test_stream_response(server):25    async with httpcore.ConnectionPool() as http:26        response = await http.request("GET", "http://127.0.0.1:8000/", stream=True)27    assert response.status_code == 20028    assert not hasattr(response, "body")29    body = await response.read()30    assert body == b"Hello, world!"313233@pytest.mark.asyncio34async def test_stream_request(server):35    async def hello_world():36        yield b"Hello, "37        yield b"world!"3839    async with httpcore.ConnectionPool() as http:40        response = await http.request(41            "POST", "http://127.0.0.1:8000/", body=hello_world()42        )43    assert response.status_code == 200