def test_get_database_uri(self): # test with environmental variable os.environ[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:root@localhost:33600/fedlearner' self.assertTrue(get_database_uri().startswith( 'mysql+pymysql://root:root@localhost:33600/fedlearner')) # test with fallback options os.environ.pop('SQLALCHEMY_DATABASE_URI') self.assertTrue(get_database_uri().startswith('sqlite:///'))
class Config(object): SQLALCHEMY_DATABASE_URI = get_database_uri() SQLALCHEMY_TRACK_MODIFICATIONS = False JWT_SECRET_KEY = secrets.token_urlsafe(64) PROPAGATE_EXCEPTIONS = True LOGGING_LEVEL = logging.DEBUG TESTING = True ENV = 'development' GRPC_LISTEN_PORT = 1990 START_COMPOSER = False
def pre_start_hook(): before_hook_path = Envs.PRE_START_HOOK if before_hook_path: module_path, func_name = before_hook_path.split(':') module = importlib.import_module(module_path) # Dynamically run the function getattr(module, func_name)() # explicit rebind db engine to make hook work db.rebind(get_database_uri())
class Config(object): SQLALCHEMY_DATABASE_URI = get_database_uri() SQLALCHEMY_TRACK_MODIFICATIONS = False MYSQL_CHARSET = 'utf8mb4' # For unicode strings # Ref: https://stackoverflow.com/questions/14853694/python-jsonify-dictionary-in-utf-8 JSON_AS_ASCII = False JWT_SECRET_KEY = os.getenv('JWT_SECRET_KEY', secrets.token_urlsafe(64)) PROPAGATE_EXCEPTIONS = True GRPC_LISTEN_PORT = 1990 JWT_ACCESS_TOKEN_EXPIRES = 86400 STORAGE_ROOT = Envs.STORAGE_ROOT START_GRPC_SERVER = True START_SCHEDULER = True START_COMPOSER = os.getenv('START_COMPOSER', True)
class Config(object): SQLALCHEMY_DATABASE_URI = get_database_uri()