def test_max_chunk_size(self): rfile = BytesIO(b"123456") assert list(read_body(rfile, -1, max_chunk_size=None)) == [b"123456"] rfile = BytesIO(b"123456") assert list(read_body(rfile, -1, max_chunk_size=1)) == [ b"1", b"2", b"3", b"4", b"5", b"6" ]
def test_chunked(self): rfile = BytesIO(b"3\r\nfoo\r\n0\r\n\r\nbar") body = b"".join(read_body(rfile, None)) assert body == b"foo" assert rfile.read() == b"bar"
def test_max_chunk_size(self): rfile = BytesIO(b"123456") assert list(read_body(rfile, -1, max_chunk_size=None)) == [b"123456"] rfile = BytesIO(b"123456") assert list(read_body(rfile, -1, max_chunk_size=1)) == [b"1", b"2", b"3", b"4", b"5", b"6"]
def test_unknown_size_limit(self): rfile = BytesIO(b"foobar") with raises(HttpException): b"".join(read_body(rfile, -1, 3))
def test_unknown_size(self): rfile = BytesIO(b"foobar") body = b"".join(read_body(rfile, -1)) assert body == b"foobar"
def test_known_size_too_short(self): rfile = BytesIO(b"foo") with raises(HttpException): b"".join(read_body(rfile, 6))
def test_known_size(self): rfile = BytesIO(b"foobar") body = b"".join(read_body(rfile, 3)) assert body == b"foo" assert rfile.read() == b"bar"
def test_known_size_limit(self): rfile = BytesIO(b"foobar") with raises(HttpException): b"".join(read_body(rfile, 3, 2))