Exemple #1
0
 def create_app(self):
     app = create_app(config_path=os.path.join(
         os.path.dirname(os.path.realpath(__file__)),
         '..', 'test_config.py'
     ))
     app.config['TESTING'] = True
     return app
    def test_flask_debugtoolbar(self):
        """ Test if flask debugtoolbar is loaded correctly

        Creating an app with default config so that debug is True
        and SECRET_KEY is defined.
        """
        app = create_app(debug=True)
        client = app.test_client()
        resp = client.get('/')
        self.assert200(resp)
        self.assertIn('flDebug', str(resp.data))
def init_db(force):
    """Initializes database.

    This process involves several steps:
    1. Table structure is created.
    2. Primary keys and foreign keys are created.
    3. Indexes are created.
    """
    db.init_db_engine(config.POSTGRES_ADMIN_URI)
    if force:
        res = db.run_sql_script_without_transaction(
            os.path.join(ADMIN_SQL_DIR, 'drop_db.sql'))
        if not res:
            raise Exception(
                'Failed to drop existing database and user! Exit code: %i' %
                exit_code)

    print('Creating user and a database...')
    res = db.run_sql_script_without_transaction(
        os.path.join(ADMIN_SQL_DIR, 'create_db.sql'))
    if not res:
        raise Exception(
            'Failed to create new database and user! Exit code: %i' %
            exit_code)

    print('Creating database extensions...')
    exit_code = db.run_sql_script_without_transaction(
        os.path.join(ADMIN_SQL_DIR, 'create_extensions.sql'))

    app = create_app()
    with app.app_context():
        print('Creating tables...')
        db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_tables.sql'))

        print('Creating primary and foreign keys...')
        db.run_sql_script(
            os.path.join(ADMIN_SQL_DIR, 'create_primary_keys.sql'))
        db.run_sql_script(
            os.path.join(ADMIN_SQL_DIR, 'create_foreign_keys.sql'))

        print('Creating indexes...')
        db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_indexes.sql'))

    print("Done!")
def runserver(host, port, debug=False):
    create_app(debug=debug).run(host=host, port=port)