示例#1
0
def test_set_response_unicode(start_response):
    ''' ಠ_ಠ '''
    response = wsgi.Response(start_response)
    response.body = "ಠ_ಠ"

    response_body = response.send()[0]
    assert response_body == b'\xe0\xb2\xa0_\xe0\xb2\xa0'
示例#2
0
def test_default_response(start_response):
    ''' By default responses should be 500s with no body '''
    response = wsgi.Response(start_response)

    response_body = response.send()[0]
    assert start_response.status == '500 Internal Server Error'
    assert start_response.headers == [('Content-Length', '0')]
    assert not response_body
示例#3
0
def test_set_response_ok(start_response):
    ''' 200 OK without a body is fine '''
    response = wsgi.Response(start_response)
    response.status = 200

    response_body = response.send()[0]
    assert start_response.status == '200 OK'
    assert start_response.headers == [('Content-Length', '0')]
    assert not response_body
示例#4
0
def test_set_response_body(start_response):
    ''' Body is correctly returned, and appropriate header values are set '''
    response = wsgi.Response(start_response)
    response.status = 400  # Setting a body will clear this
    response.body = "This is the body"

    response_body = response.send()[0]
    assert start_response.status == '200 OK'
    assert start_response.headers == [('Content-Length', '16')]
    assert response_body == b'This is the body'
示例#5
0
def test_set_response_exception(start_response):
    ''' Setting an exception should clear the body '''
    response = wsgi.Response(start_response)
    response.body = "This will be cleared"
    exception = wsgi.RequestException(404)
    response.exception(exception)

    response_body = response.send()[0]
    assert start_response.status == '404 Not Found'
    assert start_response.headers == [('Content-Length', '0')]
    assert not response_body