def test_read_all(): b = BodyBuffer( preallocated=b'live', socket=MockSocket(b' long and prosper'), content_length=9, ) assert b.read() == b'live long'
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''
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'
def test_preallocated(): b = BodyBuffer(preallocated=b'live', socket=MockSocket(b' long and prosper')) assert b.read(500) == b'live long and prosper'
def test_lines(): b = BodyBuffer(socket=MockSocket(b'hello there\r\namigo')) assert b.readlines() == [b'hello there\r\n', b'amigo']