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'
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
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
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'
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