def test_scriptinfo(test_apps, monkeypatch): """Test of ScriptInfo.""" obj = ScriptInfo(app_import_path="cliapp.app:testapp") assert obj.load_app().name == "testapp" assert obj.load_app().name == "testapp" def create_app(info): return Flask("createapp") obj = ScriptInfo(create_app=create_app) app = obj.load_app() assert app.name == "createapp" assert obj.load_app() == app obj = ScriptInfo() pytest.raises(NoAppException, obj.load_app) # import app from wsgi.py in current directory monkeypatch.chdir(os.path.abspath(os.path.join( os.path.dirname(__file__), 'test_apps', 'helloworld' ))) obj = ScriptInfo() app = obj.load_app() assert app.name == 'hello' # import app from app.py in current directory monkeypatch.chdir(os.path.abspath(os.path.join( os.path.dirname(__file__), 'test_apps', 'cliapp' ))) obj = ScriptInfo() app = obj.load_app() assert app.name == 'testapp'
def test_scriptinfo(test_apps, monkeypatch): """Test of ScriptInfo.""" obj = ScriptInfo(app_import_path="cliapp.app:testapp") assert obj.load_app().name == "testapp" assert obj.load_app().name == "testapp" def create_app(info): return Flask("createapp") obj = ScriptInfo(create_app=create_app) app = obj.load_app() assert app.name == "createapp" assert obj.load_app() == app obj = ScriptInfo() pytest.raises(NoAppException, obj.load_app) # import app from wsgi.py in current directory monkeypatch.chdir( os.path.abspath( os.path.join(os.path.dirname(__file__), 'test_apps', 'helloworld'))) obj = ScriptInfo() app = obj.load_app() assert app.name == 'hello' # import app from app.py in current directory monkeypatch.chdir( os.path.abspath( os.path.join(os.path.dirname(__file__), 'test_apps', 'cliapp'))) obj = ScriptInfo() app = obj.load_app() assert app.name == 'testapp'
def test_scriptinfo(test_apps): """Test of ScriptInfo.""" obj = ScriptInfo(app_import_path="cliapp.app:testapp") assert obj.load_app().name == "testapp" assert obj.load_app().name == "testapp" def create_app(info): return Flask("createapp") obj = ScriptInfo(create_app=create_app) app = obj.load_app() assert app.name == "createapp" assert obj.load_app() == app
def test_scriptinfo(test_apps): """Test of ScriptInfo.""" obj = ScriptInfo(app_import_path="cliapp.app:testapp") assert obj.load_app().name == "testapp" assert obj.load_app().name == "testapp" def create_app(info): return Flask("createapp") obj = ScriptInfo(create_app=create_app) app = obj.load_app() assert app.name == "createapp" assert obj.load_app() == app
def run(): from flask.helpers import get_load_dotenv from flask.cli import ScriptInfo, load_dotenv from mini_fiction.management import manager manager.populate_commands() # Необходимо создать приложение заранее для загрузки команд из плагинов if get_load_dotenv(manager.cli.load_dotenv): load_dotenv() obj = ScriptInfo(create_app=manager.cli.create_app) obj.load_app() return manager.cli(obj=obj)
def test_scriptinfo(test_apps, monkeypatch): """Test of ScriptInfo.""" obj = ScriptInfo(app_import_path="cliapp.app:testapp") app = obj.load_app() assert app.name == "testapp" assert obj.load_app() is app # import app with module's absolute path cli_app_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "test_apps", "cliapp", "app.py")) obj = ScriptInfo(app_import_path=cli_app_path) app = obj.load_app() assert app.name == "testapp" assert obj.load_app() is app obj = ScriptInfo(app_import_path=cli_app_path + ":testapp") app = obj.load_app() assert app.name == "testapp" assert obj.load_app() is app def create_app(info): return Flask("createapp") obj = ScriptInfo(create_app=create_app) app = obj.load_app() assert app.name == "createapp" assert obj.load_app() is app obj = ScriptInfo() pytest.raises(NoAppException, obj.load_app) # import app from wsgi.py in current directory monkeypatch.chdir( os.path.abspath( os.path.join(os.path.dirname(__file__), "test_apps", "helloworld"))) obj = ScriptInfo() app = obj.load_app() assert app.name == "hello" # import app from app.py in current directory monkeypatch.chdir( os.path.abspath( os.path.join(os.path.dirname(__file__), "test_apps", "cliapp"))) obj = ScriptInfo() app = obj.load_app() assert app.name == "testapp"
def run_socketio(script_info: ScriptInfo, host: str, port: int) -> None: app = script_info.load_app() if 'socketio' not in app.extensions: # flask-socketio is installed, but it isn't in this application # so we invoke Flask's original run command run_index = sys.argv.index('run_socketio') sys.argv = sys.argv[run_index:] return run_command() socketio = app.extensions['socketio'] socketio.run(app, host=host, port=port)
def test_scriptinfo(test_apps, monkeypatch): obj = ScriptInfo(app_import_path="cliapp.app:testapp") app = obj.load_app() assert app.name == "testapp" assert obj.load_app() is app # import app with module's absolute path cli_app_path = str(test_path / "cliapp" / "app.py") obj = ScriptInfo(app_import_path=cli_app_path) app = obj.load_app() assert app.name == "testapp" assert obj.load_app() is app obj = ScriptInfo(app_import_path=f"{cli_app_path}:testapp") app = obj.load_app() assert app.name == "testapp" assert obj.load_app() is app def create_app(): return Flask("createapp") obj = ScriptInfo(create_app=create_app) app = obj.load_app() assert app.name == "createapp" assert obj.load_app() is app obj = ScriptInfo() pytest.raises(NoAppException, obj.load_app) # import app from wsgi.py in current directory monkeypatch.chdir(test_path / "helloworld") obj = ScriptInfo() app = obj.load_app() assert app.name == "hello" # import app from app.py in current directory monkeypatch.chdir(test_path / "cliapp") obj = ScriptInfo() app = obj.load_app() assert app.name == "testapp"
class FlaskJob(Job): """ The RQ Job class that is capable to running with a Flask app context. This requires setting the ``FLASK_APP`` environment variable. """ def __init__(self, *args, **kwargs): super(FlaskJob, self).__init__(*args, **kwargs) self.script_info = ScriptInfo() def perform(self): app = self.script_info.load_app() with app.app_context(): return super(FlaskJob, self).perform()
class FlaskJob(Job): """ The RQ Job class that is capable to running with a Flask app context. This requires setting the ``FLASK_APP`` environment variable. """ def __init__(self, *args, **kwargs): super(FlaskJob, self).__init__(*args, **kwargs) self.script_info = ScriptInfo() def load_app(self): if current_app: app = current_app else: app = self.script_info.load_app() return app def perform(self): app = self.load_app() with app.app_context(): return super(FlaskJob, self).perform()
def create_app(self): script_info = ScriptInfo(create_app=create_app) script_info.data['APP_SETTINGS'] = 'config.TestingConfig' return script_info.load_app()