Beispiel #1
0
    def setUp(self):
        class RootController(object):
            @pecan.expose()
            def index(self):
                return 'Hello, World!'

        self.app = TestApp(pecan.Pecan(RootController()))
    def test_original_exception(self):
        class RootController(object):
            @pecan.expose()
            def index(self):
                if pecan.request.method != 'POST':
                    pecan.abort(405, 'You have to POST, dummy!')
                return 'Hello, World!'

            @pecan.expose('json')
            def error(self, status):
                return dict(status=int(status),
                            reason=pecan.request.
                            environ['pecan.original_exception'].detail)

        app = pecan.Pecan(RootController())
        app = RecursiveMiddleware(
            ErrorDocumentMiddleware(app, {405: '/error/405'}))
        app = TestApp(app)

        assert app.post('/').status_int == 200
        r = app.get('/', expect_errors=405)
        assert r.status_int == 405

        resp = json.loads(r.body.decode())
        assert resp['status'] == 405
        assert resp['reason'] == 'You have to POST, dummy!'
Beispiel #3
0
def setup_app(config):
    """Initialize Pecan application.

    This is a generic interface method of an application.

    :param config: An instance of :class:`pecan.Config`.
    :return: A normal WSGI application, an instance of
             :class:`pecan.Pecan`.
    """
    app = pecan.Pecan(config.app.root, debug=CONF.debug)
    return app
Beispiel #4
0
def build_wsgi_app(controller=None, transactional=False):
    """WSGI application creation helper

    :param controller: Overrides default application controller
    :param transactional: Adds transaction hook for all requests
    """
    request_hooks = [hooks.JSONErrorHook()]
    if transactional:
        request_hooks.append(hooks.BarbicanTransactionHook())
    if newrelic_loaded:
        request_hooks.insert(0, hooks.NewRelicHook())

    # Create WSGI app
    wsgi_app = pecan.Pecan(
        controller or versions.AVAILABLE_VERSIONS[versions.DEFAULT_VERSION](),
        hooks=request_hooks,
        force_canonical=False)
    return wsgi_app
Beispiel #5
0
def build_wsgi_app(controller=None, transactional=False):
    """WSGI application creation helper

    :param controller: Overrides default application controller
    :param transactional: Adds transaction hook for all requests
    """
    request_hooks = [hooks.JSONErrorHook()]
    if transactional:
        request_hooks.append(hooks.OSVmExpireTransactionHook())

    # Create WSGI app
    wsgi_app = pecan.Pecan(
        controller or versions.AVAILABLE_VERSIONS[versions.DEFAULT_VERSION](),
        hooks=request_hooks,
        force_canonical=False)

    # clear the session created in controller initialization     60
    repositories.clear()
    return wsgi_app