예제 #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!'
예제 #3
0
파일: app.py 프로젝트: sahanasj/rally
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
예제 #4
0
파일: app.py 프로젝트: tzatti/barbican
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
예제 #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