Example #1
0
async def test_async_cannot_read_after_response_closed():
    response = httpx.AsyncResponse(200, content=async_streaming_body())

    await response.close()

    with pytest.raises(httpx.ResponseClosed):
        await response.read()
Example #2
0
async def test_async_stream_interface():
    response = httpx.AsyncResponse(200, content=b"Hello, world!")

    content = b""
    async for part in response.stream():
        content += part
    assert content == b"Hello, world!"
Example #3
0
async def test_async_cannot_read_after_stream_consumed():
    response = httpx.AsyncResponse(200, content=async_streaming_body())

    content = b""
    async for part in response.stream():
        content += part

    with pytest.raises(httpx.StreamConsumed):
        await response.read()
Example #4
0
async def test_async_streaming_response():
    response = httpx.AsyncResponse(200, content=async_streaming_body())

    assert response.status_code == 200
    assert not response.is_closed

    content = await response.read()

    assert content == b"Hello, world!"
    assert response.content == b"Hello, world!"
    assert response.is_closed
Example #5
0
async def test_stream_text():
    async def iterator():
        yield b"Hello, world!"

    response = httpx.AsyncResponse(200, content=iterator().__aiter__())

    await response.read()

    content = ""
    async for part in response.stream_text():
        content += part
    assert content == "Hello, world!"