示例#1
0
def test_operational_error():
    app = ErrorMiddleware(myapp)
    req = Request.blank('/')
    resp = req.get_response(app, catch_exc_info=True)
    assert resp.status_code == 503
    assert 'Retry-After' in resp.headers
    assert 'accessing the database' in resp.body
示例#2
0
def test_500():
    app = ErrorMiddleware(error_instantiating_app)
    req = Request.blank('/')
    resp = req.get_response(app, catch_exc_info=True)

    assert resp.status_code == 500
    assert "There was an unhandleable problem with the application" \
        in resp.body
示例#3
0
def test_stream_error():
    app = ErrorMiddleware(streaming_app)
    req = Request.blank('/')
    resp = req.get_response(app, catch_exc_info=True)

    assert resp.status_code == 500
    for x in resp.app_iter:
        print x
示例#4
0
def initialize_backend(global_config, use_analytics=False):
    '''Backend DispatcherMiddleware with all data servers
    '''
    mounts = {app.url_base: app.mk_backend(global_config) for app in apps}

    static_app = static.Cling(resource_filename('pdp', 'static'))
    wsgi_app = DispatcherMiddleware(static_app, mounts)

    if use_analytics:
        wsgi_app = AnalyticsMiddleware(wsgi_app, global_config['analytics'])
    return ErrorMiddleware(wsgi_app)
示例#5
0
def initialize_frontend(global_config, use_analytics=False):
    '''Frontend server with all portal pages and required resources
    '''

    docs_app = static.Cling(resource_filename('pdp', 'docs/html'))
    static_app = static.Cling(resource_filename('pdp', 'static'))

    mounts = {app.url_base: app.mk_frontend(global_config) for app in apps}
    mounts.update({
        '/pcds_map': pcds.mk_frontend(global_config),  # legacy url support
        '/css/': static.Cling(resource_filename('pdp_util', 'data')),
        '/docs': docs_app
    })

    wsgi_app = DispatcherMiddleware(static_app, mounts)

    if use_analytics:
        wsgi_app = AnalyticsMiddleware(wsgi_app, global_config['analytics'])
    return ErrorMiddleware(wsgi_app)
示例#6
0
def test_io_error():
    app = ErrorMiddleware(missing_file_app)
    req = Request.blank('/')
    resp = req.get_response(app, catch_exc_info=True)
    assert 'Retry-After' in resp.headers
    assert resp.status_code == 503
示例#7
0
def test_stream_error():
    app = ErrorMiddleware(streaming_app)
    req = Request.blank('/')
    resp = req.get_response(app, catch_exc_info=True)

    assert resp.status_code == 500
    for x in resp.app_iter:
        print x


def test_500():
    app = ErrorMiddleware(error_instantiating_app)
    req = Request.blank('/')
    resp = req.get_response(app, catch_exc_info=True)

    assert resp.status_code == 500
    assert "There was an unhandleable problem with the application" \
        in resp.body


if __name__ == '__main__':
    app = Flask(__name__)
    app.wsgi_app = ErrorMiddleware(streaming_app)
    app.debug = True

    app.run('0.0.0.0',
            8006,
            use_reloader=True,
            debug=False,
            use_debugger=False)