Skip to content
Myr

test_api.py

This file

Path

tests/test_api.py

38 lines · 1.2 KiB · Python

Last changed by

ConnectionsTom Christiebefore adoption86263fa

History of this file

Take it

1import pytest2import httpcore345@pytest.mark.asyncio6async def test_get(server):7    async with httpcore.ConnectionPool() as http:8        response = await http.request('GET', "http://127.0.0.1:8000/")9    assert response.status_code == 20010    assert response.body == b'Hello, world!'111213@pytest.mark.asyncio14async def test_post(server):15    async with httpcore.ConnectionPool() as http:16        response = await http.request('POST', "http://127.0.0.1:8000/", body=b"Hello, world!")17    assert response.status_code == 200181920@pytest.mark.asyncio21async def test_stream_response(server):22    async with httpcore.ConnectionPool() as http:23        response = await http.request('GET', "http://127.0.0.1:8000/", stream=True)24    assert response.status_code == 20025    assert not hasattr(response, 'body')26    body = await response.read()27    assert body == b'Hello, world!'282930@pytest.mark.asyncio31async def test_stream_request(server):32    async def hello_world():33        yield b"Hello, "34        yield b"world!"3536    async with httpcore.ConnectionPool() as http:37        response = await http.request('POST', "http://127.0.0.1:8000/", body=hello_world())38    assert response.status_code == 200