Beispiel #1
0
async def test_body_streaming_no_data() -> None:
    body = Body(None)
    semaphore = asyncio.Semaphore(0)
    asyncio.ensure_future(_fill_body(body, semaphore, 0))
    async for _ in body:  # type: ignore # noqa: F841
        assert False  # Should not reach this
    assert b'' == await body  # type: ignore
Beispiel #2
0
async def test_body_streaming() -> None:
    body = Body(None)
    limit = 3
    semaphore = asyncio.Semaphore(0)
    asyncio.ensure_future(_fill_body(body, semaphore, limit))
    index = 0
    async for data in body:  # type: ignore
        semaphore.release()
        assert data == b"%d" % index
        index += 1
    assert b'' == await body  # type: ignore
Beispiel #3
0
async def test_body_stream_single_chunk() -> None:
    body = Body(None, None)
    body.append(b"data")
    body.set_complete()

    async def _check_data() -> None:
        async for data in body:
            assert data == b"data"

    await asyncio.wait_for(_check_data(), 1)
Beispiel #4
0
def test_body_exceeds_max_content_length() -> None:
    max_content_length = 5
    body = Body(max_content_length)
    with pytest.raises(RequestEntityTooLarge):
        body.append(b' ' * (max_content_length + 1))
Beispiel #5
0
async def test_full_body() -> None:
    body = Body(None)
    limit = 3
    semaphore = asyncio.Semaphore(limit)
    asyncio.ensure_future(_fill_body(body, semaphore, limit))
    assert b'012' == await body  # type: ignore
Beispiel #6
0
async def _fill_body(body: Body, semaphore: asyncio.Semaphore,
                     limit: int) -> None:
    for number in range(limit):
        body.append(b"%d" % number)
        await semaphore.acquire()
    body.set_complete()
Beispiel #7
0
async def test_body_exceeds_max_content_length() -> None:
    max_content_length = 5
    body = Body(None, max_content_length)
    body.append(b" " * (max_content_length + 1))
    with pytest.raises(RequestEntityTooLarge):
        await body