Beispiel #1
0
async def test_recv_event_anyio2_end_of_stream():
    class MockH11Connection:
        def __init__(self):
            self.data = None

        def next_event(self):
            if self.data == b"":
                return h11.PAUSED
            else:
                return h11.NEED_DATA

        def receive_data(self, data):
            self.data = data

    class MockSock:
        def receive(self):
            raise EndOfStream

    req = RequestProcessor(None, "get", "toot-toot", None)
    req.sock = MockSock()

    h11_connection = MockH11Connection()
    event = await req._recv_event(h11_connection)
    assert event is h11.PAUSED
    assert h11_connection.data == b""
Beispiel #2
0
def _catch_response(monkeypatch, headers, data):
    req = RequestProcessor(None, 'get', "toot-toot", None)
    events = [
        h11._events.Response(status_code=200, headers=headers),
        h11._events.Data(data=data),
        h11._events.EndOfMessage(),
    ]
    async def _recv_event(hconn):
        return events.pop(0)
    monkeypatch.setattr(req, '_recv_event', _recv_event)
    monkeypatch.setattr(req, 'host', 'lol')
    cr = req._catch_response(None)
    try:
        cr.send(None)
    except StopIteration as e:
        response = e.value
    return response
Beispiel #3
0
def _catch_response(monkeypatch, headers, data, http_version=b"1.1"):
    req = RequestProcessor(None, "get", "toot-toot", None)
    events = [
        h11._events.Response(status_code=200,
                             headers=headers,
                             http_version=http_version),
        h11._events.Data(data=data),
        h11._events.EndOfMessage(),
    ]

    async def _recv_event(hconn):
        return events.pop(0)

    monkeypatch.setattr(req, "_recv_event", _recv_event)
    monkeypatch.setattr(req, "host", "lol")
    cr = req._catch_response(None)
    try:
        cr.send(None)
    except StopIteration as e:
        response = e.value
    return response
Beispiel #4
0
def test_dict_to_query(data, query_str):
    assert RequestProcessor._dict_to_query(data) == query_str