def client(): """ Pytest fixture """ db_fd, app.config['DATABASE'] = tempfile.mkstemp(suffix=".db") app.config[ 'SQLALCHEMY_DATABASE_URI'] = f"sqlite:///{app.config.get('DATABASE')}" print(f"Database full path: {app.config.get('SQLALCHEMY_DATABASE_URI')}" ) # TODO: Remove print(f'Database: {app.config.get("DATABASE")}') # TODO: Remove print(f'Second field: {db_fd}') # TODO: Remove app.config['TESTING'] = config.TestingConfig() with app.test_client() as client: with app.app_context(): db.init_app(app) db.drop_all() db.create_all() db_file = os.path.join(_cwd, 'learners.sql') init_db_from_script(db_file, db) yield client os.close(db_fd) os.unlink(app.config['DATABASE'])
from flask import Flask, render_template, session, g, flash import os import config app = Flask(__name__) env = os.environ['ENV'].lower() if not env: app.config.from_object(config.Config()) if env == 'dev': app.config.from_object(config.DevelopmentConfig()) elif env == 'test': app.config.from_object(config.TestingConfig()) else: app.config.from_object(config.Config()) @app.errorhandler(403) def access_denied(e): flash(u'You can\'t go there.') return render_template('errors/403.html'), 403 @app.errorhandler(404) def page_not_found(e): flash(u'That page doesn\'t exist.') return render_template('errors/404.html'), 404 @app.errorhandler(500) def server_error(e): flash(u'The server has exploded. Great.') return render_template('errors/500.html'), 500
import config from hubstaff.services.client import HubStaff # create and configure the app app = flask.Flask(__name__, instance_relative_config=True) app.app_context().push() # set config object base on ENV env = os.environ.get('FLASK_ENV') if env == 'dev' or env == 'development': env_config = config.DevelopmentConfig() elif env == 'prod' or env == 'production': env_config = config.ProductionConfig() elif env == 'test' or env == 'testing': env_config = config.TestingConfig() else: env_config = config.DevelopmentConfig() app.config.from_object(env_config) # register SQLAlchemy db = flask_sqlalchemy.SQLAlchemy() db.init_app(app) # register Flask-Login's login manager login_manager = flask_login.LoginManager() login_manager.init_app(app) login_manager.login_view = 'login' # register flask bootstrap
from os import environ import config from server import create_app if 'FLASK_ENV' not in environ or environ['FLASK_ENV'] == 'development': config_obj = config.DevelopmentConfig() elif environ['FLASK_ENV'] == 'production': config_obj = config.ProductionConfig() elif environ['FLASK_ENV'] == 'testing': config_obj = config.TestingConfig() else: raise ValueError("Unknown FLASK_ENV") app = create_app(config_obj)
import os from app import app from layouts import layout1 import config import callbacks environment = os.environ.get('CONF_ENV', 'default') if environment == 'production': print("Production Configuration") appConfig = config.ProductionConfig() elif environment == 'development': print("Development Configuration") appConfig = config.DevelopmentConfig() elif environment == 'testing': print("Testing Configuration") appConfig = config.TestingConfig() elif environment == 'jenkinsDevelopment': print("Jenkins Development Configuration") appConfig = config.JenkinsDevelopmentConfig() elif environment == 'jenkinsTesting': print("Jenkins Testing Configuration") appConfig == config.JenkinsTestingConfig() else: appConfig = config.config() print("Default Configuration") app.layout = layout1 if __name__ == '__main__': app.run_server(host='0.0.0.0', port=appConfig.APP_PORT,