Ejemplo n.º 1
0
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 == ""
Ejemplo n.º 2
0
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 == ""
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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) == ''
Ejemplo n.º 6
0
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"
Ejemplo n.º 7
0
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"
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
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) == ''
Ejemplo n.º 12
0
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"
Ejemplo n.º 13
0
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"
Ejemplo n.º 14
0
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)