def _set_sql_alchemy(self): """ Set SQLAlchemy specific configurations, init the db object and create the tables if necessary """ cfy_config = config.instance params = {} params.update(config.instance.postgresql_connection_options) if cfy_config.postgresql_ssl_enabled: params.update({ 'sslmode': 'verify-full', 'sslcert': config.instance.postgresql_ssl_cert_path, 'sslkey': config.instance.postgresql_ssl_key_path, 'sslrootcert': config.instance.ca_cert_path }) db_uri = '{0}://{1}:{2}@{3}/{4}'.format( SQL_DIALECT, cfy_config.postgresql_username, cfy_config.postgresql_password, cfy_config.postgresql_host, cfy_config.postgresql_db_name ) if any(params.values()): query = '&'.join('{0}={1}'.format(key, value) for key, value in params.items() if value) db_uri = '{0}?{1}'.format(db_uri, query) self.config['SQLALCHEMY_DATABASE_URI'] = db_uri self.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(self) # Prepare the app for use with flask-sqlalchemy
def _set_sql_alchemy(self): """ Set SQLAlchemy specific configurations, init the db object and create the tables if necessary """ self.config['SQLALCHEMY_DATABASE_URI'] = config.instance.db_url self.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(self) # Prepare the app for use with flask-sqlalchemy
def _set_sql_alchemy(self): """ Set SQLAlchemy specific configurations, init the db object and create the tables if necessary """ self.config['SQLALCHEMY_POOL_SIZE'] = 1 self.update_db_uri() self.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(self) # Prepare the app for use with flask-sqlalchemy
def setUp(self): """Initialize mock application with in memory sql database.""" app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:' context = app.app_context() context.push() self.addCleanup(context.pop) db.init_app(app) db.create_all() self._populate_db()
def setUp(self): """Initialize mock application with in memory sql database.""" app = Flask(__name__) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] =\ 'postgresql://*****:*****@localhost/cloudify_db' context = app.app_context() context.push() self.addCleanup(context.pop) db.init_app(app) db.create_all() self.addCleanup(self._clean_db) self._populate_db()
def _set_sql_alchemy(self): """Set SQLAlchemy specific configurations, init the db object and create the tables if necessary """ cfy_config = config.instance self.config['SQLALCHEMY_DATABASE_URI'] = \ '{0}://{1}:{2}@{3}/{4}'.format( SQL_DIALECT, cfy_config.postgresql_username, cfy_config.postgresql_password, cfy_config.postgresql_host, cfy_config.postgresql_db_name ) self.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(self) # Prepare the app for use with flask-sqlalchemy
def setup_app(): global app if not app: conf = utils.get_postgres_client_details() app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = \ 'postgresql+pg8000://{0}:{1}@{2}/{3}'.format( conf.username, conf.password, conf.host, conf.db_name ) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Setup the mock app with the DB db.init_app(app) app.app_context().push()
def setup_app(): global app default_tenant_id = 1 if not app: conf = utils.get_postgres_client_details() app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = \ 'postgresql+pg8000://{0}:{1}@{2}/{3}'.format( conf.username, conf.password, conf.host, conf.db_name ) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SECURITY_USER_IDENTITY_ATTRIBUTES'] = 'username, email' app.config['tenant_id'] = default_tenant_id # Setup the mock app with the DB db.init_app(app) app.app_context().push()
def _set_sql_alchemy(self): """ Set SQLAlchemy specific configurations, init the db object and create the tables if necessary """ cfy_config = config.instance self.config['SQLALCHEMY_DATABASE_URI'] = \ '{0}://{1}:{2}@{3}/{4}'.format( SQL_DIALECT, cfy_config.postgresql_username, cfy_config.postgresql_password, cfy_config.postgresql_host, cfy_config.postgresql_db_name ) if cfy_config.postgresql_ssl_enabled: # The ssl certificate and key should be found in the default # ~/.postgresql directory self.config['SQLALCHEMY_DATABASE_URI'] += '?sslmode=verify-full' self.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(self) # Prepare the app for use with flask-sqlalchemy
def setup_flask_app(manager_ip='localhost', driver='', hash_salt=None, secret_key=None): """Setup a functioning flask app, when working outside the rest-service :param manager_ip: The IP of the manager :param driver: SQLA driver for postgres (e.g. pg8000) :param hash_salt: The salt to be used when creating user passwords :param secret_key: Secret key used when hashing flask tokens :return: A Flask app """ app = Flask(__name__) db_uri = _get_postgres_db_uri(manager_ip, driver) app.config['SQLALCHEMY_DATABASE_URI'] = db_uri app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False set_flask_security_config(app, hash_salt, secret_key) Security(app=app, datastore=user_datastore) Migrate(app=app, db=db) db.init_app(app) app.app_context().push() return app
def setup_flask_app(manager_ip='localhost', driver='', hash_salt=None, secret_key=None): """Setup a functioning flask app, when working outside the rest-service :param manager_ip: The IP of the manager :param driver: SQLA driver for postgres (e.g. pg8000) :param hash_salt: The salt to be used when creating user passwords :param secret_key: Secret key used when hashing flask tokens :return: A Flask app """ app = Flask(__name__) db_uri = _get_postgres_db_uri(manager_ip, driver) app.config['SQLALCHEMY_DATABASE_URI'] = db_uri app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['ENV'] = 'production' set_flask_security_config(app, hash_salt, secret_key) Security(app=app, datastore=user_datastore) Migrate(app=app, db=db) db.init_app(app) app.app_context().push() return app