def setUp(self):
     """
     Set up app and other test objects
     """
     # use test configuration instead of dev/production config files
     self.svc = MyPlaceService()
     self.svc.app.config['DEBUG'] = True
     self.svc.app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:////tmp/integration-tests.db"
     # init the app context
     self.svc.app.test_request_context().push()
     db.init_app(self.svc.app)
     # create a sample DB
     db.create_all()
     # create a test client
     self.testapp = self.svc.app.test_client()
     self.testapp.manager = APIManager(self.testapp, flask_sqlalchemy_db=db)
     self.svc.manager.create_api(MyPlace, methods=['GET', 'POST', 'PUT', 'DELETE'])
示例#2
0
 def __init__(self):
     """
     Initialize the application, its context, and the API manager
     """
     self.app.config.from_object(config)
     # init the logging and context
     self.setup_logging();
     self.app.test_request_context().push()
     # grab the database from the model, init the service
     db.init_app(self.app)
     # Create the Flask-Restless API manager.
     self.manager = APIManager(self.app, flask_sqlalchemy_db=db)
     # define the blueprint
     self.myplaceServiceBlueprint = self.manager.create_api_blueprint(
                                                            MyPlace,
                                                            # if a custom URL prefix is desired: url_prefix='/api/',
                                                            methods=['GET', 'POST', 'PUT', 'DELETE'],
                                                            preprocessors=dict(GET_MANY=[self.preprocessor]))
     self.app.logger.info('MyService blueprint created')
示例#3
0
# Change appConfig to devConfig or whatever is being used
from org.awesome.tools.config_prod import WebappProductionConfiguration as appConfig
from org.awesome.model.myplace import db as db

# Expose API constructs through this module
frontend = flask.Flask("mypoiserviceWebapp")
frontend.config.from_object(appConfig)

# call flask_bootstrap for easy use twitter bootstrap provisioning
Bootstrap(frontend)

# our front-end app entrypoint
@frontend.route('/')
def index():
    return render_template('index.html', config=appConfig)

# initialize the service
db.init_app(frontend)

# register the blueprint to the app, so that both service and app are provided
backendSvc = MyPlaceService()
frontend.register_blueprint(backendSvc.get_blueprint())

if __name__ == '__main__':
    """
    Start the app in development / or other testing mode through the entrypoint
    """
    print "The current config is: {}".format(appConfig.DEBUG)
    run_simple('localhost', 5000, frontend,
               use_reloader=True, use_debugger=True, use_evalex=True)