httpx/tests/test_api.py
Tom Christie ba1953cdd0 Linting
2019-04-06 13:20:47 +01:00

44 lines
1.2 KiB
Python

import pytest
import httpcore
@pytest.mark.asyncio
async def test_get(server):
async with httpcore.ConnectionPool() as http:
response = await http.request("GET", "http://127.0.0.1:8000/")
assert response.status_code == 200
assert response.body == b"Hello, world!"
@pytest.mark.asyncio
async def test_post(server):
async with httpcore.ConnectionPool() as http:
response = await http.request(
"POST", "http://127.0.0.1:8000/", body=b"Hello, world!"
)
assert response.status_code == 200
@pytest.mark.asyncio
async def test_stream_response(server):
async with httpcore.ConnectionPool() as http:
response = await http.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.ConnectionPool() as http:
response = await http.request(
"POST", "http://127.0.0.1:8000/", body=hello_world()
)
assert response.status_code == 200