def test_load_body_not_reentrant(environment): ''' wsgi.input is consumed on read''' environ = environment("Only this", 9) body = wsgi.load_body(environ) different_body = wsgi.load_body(environ) assert body == "Only this" assert different_body == ""
def test_load_body_no_length_header(): ''' load_body raises when CONTENT_LENGTH is missing ''' environ = { "wsgi.input": io.BytesIO(b"None of this will be returned") } with pytest.raises(wsgi.RequestException): wsgi.load_body(environ)
def test_load_chunked_body_raises(environment): ''' chunked encoding isn't supported ''' environ = environment("Hello", 100) environ["HTTP_TRANSFER_ENCODING"] = "chunked" with pytest.raises(wsgi.RequestException): wsgi.load_body(environ)
def test_load_body_no_input(): ''' load_body returns an empty string when wsgi.input is missing ''' environ = {"CONTENT_LENGTH": "100"} assert wsgi.load_body(environ) == ''
def test_load_body_extra_buffer(environment): ''' don't read past the available buffer ''' environ = environment("Only this", wsgi.MEMFILE_MAX) body = wsgi.load_body(environ) assert body == "Only this"
def test_load_body_partial_buffer(environment): ''' don't load more than CONTENT_LENGTH bytes ''' environ = environment("Only this|None of this", 9) body = wsgi.load_body(environ) assert body == "Only this"
def test_load_body_no_length_header(): ''' load_body raises when CONTENT_LENGTH is missing ''' environ = {"wsgi.input": io.BytesIO(b"None of this will be returned")} with pytest.raises(wsgi.RequestException): wsgi.load_body(environ)
def test_load_body_max_size(environment): ''' load_body raises when CONTENT_LENGTH is too large ''' environ = environment("", wsgi.MEMFILE_MAX + 1) with pytest.raises(wsgi.RequestException): wsgi.load_body(environ)