Пример #1
0
    def create_flask_app(self):
        app = flaskutils.make_json_app(flask.Flask("testing_app"))

        @app.route("/")
        def test():
            return "10"

        @app.route("/requirebody", methods=['GET', 'POST'])
        @flaskutils.require_body
        def body_required():
            return "10"

        @app.route("/withoutcors")
        def not_cross_domain():
            return "10"

        @app.route("/withcors")
        @flaskutils.crossdomain(origin="*")
        def cross_domain():
            return "10"

        @app.route("/testjsonify", methods=['POST'])
        def json_stuff():
            flaskutils.json_request_data(flask.request.data)

        return app
Пример #2
0
def app(testing=False, create_db=False, auth_strategy=None):
    if testing or app.instance is None:
        app.instance = flaskutils.make_json_app(MyFlask(__name__))
        config = 'apiconfig.DevelopmentConfig'
        if testing:
            config = 'apiconfig.TestConfig'
            app.instance.config['DATABASE_FILE'] = utils.\
                generate_temp_database()
            uri = 'sqlite:///' + app.instance.config['DATABASE_FILE']
            app.instance.config['DATABASE_URI'] = uri
        app.instance.config.from_object(config)
        session = db.create_db_environment(app.instance)
        if create_db:
            return True

        @app.instance.before_request
        def before_request():
            flask.g.session = session

        import faro_api.views.dataproviders as dp
        import faro_api.views.endpoint as endpoint
        import faro_api.views.events as events
        import faro_api.views.questions as questions
        import faro_api.views.users as users
        app.instance.register_blueprint(endpoint.mod)
        user_bp = users.UserApi()
        event_bp = events.EventApi()
        question_bp = questions.QuestionApi()
        dps_bp = dp.DataProviderApi()
        app.instance.register_blueprint(user_bp.blueprint)
        app.instance.register_blueprint(event_bp.blueprint)
        app.instance.register_blueprint(question_bp.blueprint)
        app.instance.register_blueprint(dps_bp.blueprint)
        auth_module = app.instance.config['AUTH_STRATEGY']
        if auth_strategy is not None:
            auth_module = auth_strategy
        auth_middleware = utils.load_constructor_from_string(auth_module)
        if auth_middleware is None:
            logger.fatal("Could not load middleware from %s" % auth_module)
            exit(1)

        try:
            app.instance.config.from_envvar('FARO_SETTINGS')
        except RuntimeError:
            pass
        app.instance.wsgi_app = auth_middleware(app.instance.wsgi_app)
    return app.instance