def test_error_handler():
    assert not has_error_handler(404)
    handler = MagicMock()
    error_handler(404)(handler)
    assert has_error_handler(404)

    handler.return_value = 123
    assert get_error_handler(404)(1, 2, key='value') == 123
    handler.assert_called_once_with(1, 2, key='value')
Exemplo n.º 2
0
def test_error_handler():
    assert not has_error_handler(404)
    handler = MagicMock()
    error_handler(404)(handler)
    assert has_error_handler(404)

    handler.return_value = 123
    assert get_error_handler(404)(1, 2, key='value') == 123
    handler.assert_called_once_with(1, 2, key='value')
def handle_http_exception(request, e):
    response = HTTPResponse()
    response.status = status = e.status
    response.code = e.message
    response.content_type = 'text/html'
    
    if has_error_handler(status):
        return handle_action(get_error_handler(status), request, response)
    
    response.content = '<html><body>%d %s</body></html>'%(e.status, e.message,)
    return response