Exemplo n.º 1
0
def test_read_all():
    b = BodyBuffer(
        preallocated=b'live',
        socket=MockSocket(b' long and prosper'),
        content_length=9,
    )

    assert b.read() == b'live long'
Exemplo n.º 2
0
def test_parse_get_request():
    sock = MockSocket(b'\r\n'.join([
        b'GET /resource HTTP/1.1',
        b'Accept: */*',
        b'Accept-Encoding: gzip, deflate, compress',
        b'Host: www.lol-example.com',
        b'User-Agent: troll-agent',
        b'\r\n',
    ]))

    req = parse_http_socket(sock)

    assert req.verb == 'GET'
    assert req.resource == '/resource'
    assert req.headers['accept'] == '*/*'
    assert req.headers['accept-encoding'] == 'gzip, deflate, compress'
    assert req.headers['host'] == 'www.lol-example.com'
    assert req.headers['user-agent'] == 'troll-agent'
    assert req.body.read() == b''
Exemplo n.º 3
0
def test_basic():
    b = BodyBuffer(socket=MockSocket(b'hello there\r\namigo'))

    assert b.read(5) == b'hello'
    assert b.read(1) == b' '
    assert b.read(5) == b'there'
Exemplo n.º 4
0
def test_preallocated():
    b = BodyBuffer(preallocated=b'live',
                   socket=MockSocket(b' long and prosper'))
    assert b.read(500) == b'live long and prosper'
Exemplo n.º 5
0
def test_lines():
    b = BodyBuffer(socket=MockSocket(b'hello there\r\namigo'))
    assert b.readlines() == [b'hello there\r\n', b'amigo']