def app(): """ Setup our flask test app, this only gets executed once. :return: Flask app """ db_uri = f"{settings.SQLALCHEMY_DATABASE_URI}_test" params = { "DEBUG": False, "TESTING": True, "WTF_CSRF_ENABLED": False, "SQLALCHEMY_DATABASE_URI": db_uri } _app = create_app(settings_override=params) # Establish an application context before running the tests. ctx = _app.app_context() ctx.push() yield _app ctx.pop()
from logging.config import fileConfig from alembic import context from sqlalchemy import engine_from_config from sqlalchemy import pool from hello.app import create_app # There's no access to current_app here so we must create our own app. app = create_app() db_uri = app.config["SQLALCHEMY_DATABASE_URI"] db = app.extensions["sqlalchemy"].db # Provide access to the values within alembic.ini. config = context.config # Sets up Python logging. fileConfig(config.config_file_name) # Sets up metadata for autogenerate support, config.set_main_option("sqlalchemy.url", db_uri) target_metadata = db.metadata # Configure anything else you deem important, example: # my_important_option = config.get_main_option("my_important_option") def run_migrations_offline(): """ Run migrations in 'offline' mode.
def setUp(self): self.app = create_app() self.client = self.app.test_client() with self.app.app_context(): db.create_all()
from hello import app, config wsgi_app = app.create_app(config) if __name__ == '__main__': wsgi_app.run(host="0.0.0.0", port=8080, debug=config.DEBUG)