httpx/tests/test_api.py
2019-04-30 11:26:11 +01:00

44 lines
1.2 KiB
Python

import pytest
import httpcore
@pytest.mark.asyncio
async def test_get(server):
url = "http://127.0.0.1:8000/"
async with httpcore.Client() as client:
response = await client.get(url)
assert response.status_code == 200
assert response.body == b"Hello, world!"
@pytest.mark.asyncio
async def test_post(server):
url = "http://127.0.0.1:8000/"
async with httpcore.Client() as client:
response = await client.post(url, body=b"Hello, world!")
assert response.status_code == 200
@pytest.mark.asyncio
async def test_stream_response(server):
async with httpcore.Client() as client:
response = await client.request("GET", "http://127.0.0.1:8000/", stream=True)
assert response.status_code == 200
assert not hasattr(response, "body")
body = await response.read()
assert body == b"Hello, world!"
@pytest.mark.asyncio
async def test_stream_request(server):
async def hello_world():
yield b"Hello, "
yield b"world!"
async with httpcore.Client() as client:
response = await client.request(
"POST", "http://127.0.0.1:8000/", body=hello_world()
)
assert response.status_code == 200