Example #1
0
async def _protocol(monkeypatch: MonkeyPatch) -> H11Protocol:
    MockHTTPStream = AsyncMock()  # noqa: N806
    MockHTTPStream.return_value = AsyncMock(spec=HTTPStream)
    monkeypatch.setattr(hypercorn.protocol.h11, "HTTPStream", MockHTTPStream)
    MockEvent = AsyncMock()  # noqa: N806
    MockEvent.return_value = AsyncMock(spec=IOEvent)
    return H11Protocol(Config(), False, None, None, CoroutineMock(), CoroutineMock(), MockEvent)
Example #2
0
async def _stream() -> WSStream:
    stream = WSStream(Config(), False, None, None, CoroutineMock(),
                      CoroutineMock(), 1)
    stream.spawn_app.return_value = CoroutineMock()
    stream.app_put = CoroutineMock()
    stream.config._log = AsyncMock(spec=Logger)
    return stream
Example #3
0
async def test_protocol_handle_max_incomplete(monkeypatch: MonkeyPatch) -> None:
    config = Config()
    config.h11_max_incomplete_size = 5
    MockHTTPStream = AsyncMock()  # noqa: N806
    MockHTTPStream.return_value = AsyncMock(spec=HTTPStream)
    monkeypatch.setattr(hypercorn.protocol.h11, "HTTPStream", MockHTTPStream)
    MockEvent = AsyncMock()  # noqa: N806
    MockEvent.return_value = AsyncMock(spec=IOEvent)
    protocol = H11Protocol(config, False, None, None, CoroutineMock(), CoroutineMock(), MockEvent)
    await protocol.handle(RawData(data=b"GET / HTTP/1.1\r\nHost: hypercorn\r\n"))
    protocol.send.assert_called()
    assert protocol.send.call_args_list == [
        call(
            RawData(
                data=b"HTTP/1.1 400 \r\ncontent-length: 0\r\nconnection: close\r\n"
                b"date: Thu, 01 Jan 1970 01:23:20 GMT\r\nserver: hypercorn-h11\r\n\r\n"
            )
        ),
        call(RawData(data=b"")),
        call(Closed()),
    ]
Example #4
0
async def test_protocol_send_end_data(protocol: H11Protocol) -> None:
    protocol.stream = AsyncMock()
    await protocol.stream_send(EndData(stream_id=1))
    assert protocol.stream is not None
Example #5
0
async def _stream() -> HTTPStream:
    stream = HTTPStream(Config(), False, None, None, CoroutineMock(),
                        CoroutineMock(), 1)
    stream.app_put = CoroutineMock()
    stream.config._log = AsyncMock(spec=Logger)
    return stream