def migrate(): """ Invoke Alembic migrations. """ graph = create_app(debug=True, model_only=True) migrate_main(graph)
def test_production_config(): """Production config.""" app = create_app(Production) assert app.config['ENV'] == 'prd' assert app.config['DEBUG'] is False assert app.config['DEBUG_TB_ENABLED'] is False assert app.config['ASSETS_DEBUG'] is False
def runserver(): """ Invoke Flask development server. """ graph = create_app(debug=True) runserver_main(graph)
def run_migrations_offline(): """Run migrations in 'offline' mode. This configures the context with just a URL and not an Engine, though an Engine is acceptable here as well. By skipping the Engine creation we don't even need a DBAPI to be available. Calls to context.execute() here emit the given string to the script output. """ app = create_app() url = None with app.app_context(): url = db.get_engine() context.configure( url=url, target_metadata=target_metadata, literal_binds=True, dialect_opts={"paramstyle": "named"}, ) with context.begin_transaction(): context.run_migrations()
def setup(self) -> None: self.graph = create_app(extra_deps=["example_bundle"]) self.training_initializers = self.graph.training_initializers self.input_data = InputData(get_fixture_path("example_input_data")) self.input_artifact = InputArtifact(get_fixture_path("example_input_artifact")) self.gold_output_artifact_path = get_fixture_path("example_gold_output_artifact")
def app(): app = create_app({ 'TESTING': True, }) yield app
def setUp(self): self.app = create_app(TestingConfig) self.app_context = self.app.app_context() self.app_context.push() self.request_context = self.app.test_request_context() self.request_context.push() db.create_all()
def test_prod_config(self): """ Tests if the production config loads correctly """ app = create_app('{{cookiecutter.service_name}}.settings.ProdConfig') assert app.config['SQLALCHEMY_DATABASE_URI'] == 'sqlite:///../database.db' assert app.config['CACHE_TYPE'] == 'simple'
def test_prod_config(self): """ Tests if the production config loads correctly """ app = create_app('{{cookiecutter.repo_name}}.settings.ProdConfig', env='prod') assert app.config['SQLALCHEMY_DATABASE_URI'] == 'sqlite:///../database.db' assert app.config['CACHE_TYPE'] == 'simple'
def testapp(request): app = create_app('{{cookiecutter.app_name}}.settings.TestConfig') client = app.test_client() db.app = app db.create_all() if getattr(request.module, "create_user", True): admin = User(username="******", password="******") admin.insert() my_role = Role(name='admin') my_role.insert() admin.add_roles('admin') non_admin = User(username="******", password="******") non_admin.insert() safe_commit() def teardown(): db.session.remove() db.drop_all() request.addfinalizer(teardown) return client
def test_production_config(): """Production config.""" app = create_app(ProdConfig) assert app.config['ENV'] == 'prod' assert app.config['DEBUG'] is False assert app.config['DEBUG_TB_ENABLED'] is False assert app.config['ASSETS_DEBUG'] is False
def app(scope="function"): app = create_app() app.config['TESTING'] = True with app.app_context(): db.drop_all(app=app) db.create_all(app=app) yield app.test_client()
def createall(): """ Create (and possibly drop) database tables. """ graph = create_app(debug=True, model_only=True) createall_main(graph)
def app(): my_app = create_app( local_configs=p_config.ProsperConfig( path.join(ROOT, 'scripts', 'app.cfg') ) ) return my_app
def main(): """Entrypoint for main.""" app = create_app() manager = Manager(app) manager.add_command('db', MigrateCommand) manager.add_command('db_create', CreateDB(app)) manager.add_command('db_drop', DropDB(app)) manager.run()
def run_server(): """ Invoke Flask development server. """ os.environ["FLASK_ENV"] = "development" graph = create_app(debug=True) graph.connexion.run()
def app(): _app = create_app(TestConfig) ctx = _app.test_request_context() ctx.push() yield _app ctx.pop()
def test_test_config(self): """ Tests if the test config loads correctly """ app = create_app('{{cookiecutter.app_name}}.settings.TestConfig') assert app.config['DEBUG'] is True assert app.config['SQLALCHEMY_ECHO'] is True assert app.config['CACHE_TYPE'] == 'null'
def test_dev_config(self): """ Tests if the development config loads correctly """ app = create_app('{{cookiecutter.app_name}}.settings.DevConfig') assert app.config['DEBUG'] is True assert app.config['SQLALCHEMY_DATABASE_URI'] == 'sqlite:///../{{cookiecutter.app_name}}/{{cookiecutter.app_name}}.db' assert app.config['CACHE_TYPE'] == 'null'
def app(): _app = create_app(settings) ctx = _app.test_request_context() ctx.push() yield _app ctx.pop()
def app(database): """Create a Flask app context for tests.""" # override config for test app here app = create_app(test_config=dict(SQLALCHEMY_DATABASE_URI=DB_CONN, TESTING=True)) init_views() with app.app_context(): yield app
def app(): os.environ["FLASK_ENV"] = "testing" app = create_app() with app.app_context(): db.create_all(app=app) # flask_migrate.upgrade(revision="heads") yield app db.drop_all(app=app)
def diffsettings(): loop = asyncio.get_event_loop() app = create_app(loop, stage=0) for key in app.keys(): if key.isupper(): stdout.write(f'{key} = {app[key]}\n') stdout.flush()
def test_production_config(): """Production config.""" app = create_app(ProductionConfig) assert app.config['ENV'] == 'production' assert app.config['DEBUG'] is False assert app.config['TESTING'] is False assert app.config['LOG_LEVEL'] in [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG] assert app.config.get('URL_PREFIX', None)
def test_dev_config(): """Development config.""" app = create_app(DevelopmentConfig) assert app.config['ENV'] == 'development' assert app.config['DEBUG'] is True assert app.config['TESTING'] is False assert app.config['LOG_LEVEL'] in [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG] assert app.config.get('URL_PREFIX', None) is None
def test_create_app(): app_mock = Mock() app_mock.on_startup = [] with patch("{{cookiecutter.project_slug}}.server.factory.web.Application", return_value=app_mock): with patch("{{cookiecutter.project_slug}}.server.factory.register_routes") as register_routes_mock: assert create_app() == app_mock register_routes_mock.assert_called_once_with(app_mock) assert register_graphql_engine in app_mock.on_startup
def app(): """An application for the tests.""" _app = create_app('tests.settings') ctx = _app.test_request_context() ctx.push() yield _app ctx.pop()
def test_test_config(): """Testing configuration.""" app = create_app(TestingConfig) assert app.config['ENV'] == 'testing' assert app.config['DEBUG'] is True assert app.config['TESTING'] is True assert app.config['LOG_LEVEL'] in [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG] assert app.config.get('URL_PREFIX', None) is None
def app(): """An application for the tests.""" _app = create_app(TestConfig) ctx = _app.test_request_context() ctx.push() yield _app ctx.pop()
def setup(self): self.graph = create_app(testing=True) self.example_store = self.graph.example_store self.name = "NAME" self.context = SessionContext(self.graph) self.context.recreate_all() self.context.open()
def app(): os.environ['CONFIG'] = '{{cookiecutter.package}}.config.TestConfig' app = create_app() model.init_db_tables(app) model.init_db_data(app) ctx = app.test_request_context() ctx.push() yield app ctx.pop()
def app(): config = { 'TESTING': True, } app = create_app(config=config) with app.app_context(): # init_db(app) yield app
def app(): app = create_app(testing=True, cli=True) with app.app_context(): pass yield app # åˆ é™¤å»ºçš„ä¸´æ—¶åº“ from pymongo import MongoClient client = MongoClient('localhost', 27017) client.drop_database('{{cookiecutter.app_name}}_tmp')
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) self.name1 = "name1" self.example1 = Example( id=new_object_id(), name=self.name1, )
def app(request): app = create_app('Testing') # Establish an application context before running the tests. ctx = app.app_context() ctx.push() def teardown(): ctx.pop() request.addfinalizer(teardown) return app
def run_debug(): """ Run in local machine. :return: """ print("Running debug server") activate_this = "env/bin/activate_this.py" with open(activate_this) as f: code = compile(f.read(), activate_this, 'exec') exec(code, dict(__file__=activate_this)) print("virtualenv configured...") app = create_app() app.run(host='0.0.0.0')
def testapp(request): app = create_app('{{cookiecutter.repo_name}}.settings.TestConfig', env='dev') client = app.test_client() db.app = app db.create_all() if getattr(request.module, "create_user", True): admin = User('admin', 'supersafepassword') db.session.add(admin) db.session.commit() def teardown(): db.session.remove() db.drop_all() request.addfinalizer(teardown) return client
def setUp(self): self.app = create_app(self) self.client = self.app.test_client()
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all()
def test_dev_config(): app = create_app(DevConfig) assert app.config['ENV'] == 'dev' assert app.config['DEBUG'] is True assert app.config['ASSETS_DEBUG'] is True
from __future__ import with_statement import sys import os from alembic import context from sqlalchemy import engine_from_config, pool, create_engine from logging.config import fileConfig sys.path.append(os.getcwd()) from {{ name }} import create_app from {{ name }}.core import db app = create_app('config.local.py', purpose='alembic') # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config # Interpret the config file for Python logging. # This line sets up loggers basically. fileConfig(config.config_file_name) # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata target_metadata = db.metadata # other values from the config, defined by the needs of env.py,
#!/usr/bin/python # -*- coding: utf-8 -*- import urlparse import subprocess from flask.ext.script import Manager from flask.ext.migrate import Migrate, MigrateCommand from {{PROJECT_NAME}}.app import create_app from {{PROJECT_NAME}}.models import db app = create_app() migrate = Migrate(app, db) manager = Manager(app) manager.add_command('db', MigrateCommand) @manager.command def dbshell(): url = urlparse.urlparse(app.config['SQLALCHEMY_DATABASE_URI']) params = { 'db_name': url.path.strip('/'), 'user': url.username, 'host': url.hostname, } cmd = "psql {db_name} -U {user} -h {host}".format(**params) subprocess.call(cmd, shell=True)
far. We instantiate out application using our factory passing in the desired environement pulled from the alembic config section. This is specified on the command line using the -n NAME flag. This allows us to neatly tie all of out database configuration state into one object. As the pattern defined in this template is to pull all your models into your views the application factory will ensure all the modls are picked up by alembic Thus ensuring that autogenerate will find any changes you have made for you. """ from {{ PROJECT_NAME }} import create_app, db FLASK_ENV = config.get_section(config.config_ini_section).get('flask_env', 'DEVELOPMENT') app = create_app(default_env=FLASK_ENV) target_metadata = db.metadata def run_migrations_offline(): """Run migrations in 'offline' mode. This configures the context with just a URL and not an Engine, though an Engine is acceptable here as well. By skipping the Engine creation we don't even need a DBAPI to be available. Calls to context.execute() here emit the given string to the script output. """
# -*- coding: utf-8 -*- """ {{cookiecutter.app_name}}.deploy {{'~' * (cookiecutter.project_name|length + 7)}} {{cookiecutter.project_description}} :author: {{cookiecutter.full_name}} {{cookiecutter.email}} :copyright: (c) {{cookiecutter.year}} {{cookiecutter.full_name}} :license: {{cookiecutter.license}}, see LICENSE file. """ from {{cookiecutter.app_name}} import create_app from {{cookiecutter.app_name}}.config import ProductionConfig app = create_app(config=ProductionConfig())
from {{ cookiecutter.app_name }} import create_app app = create_app(config='../local.cfg') if __name__ == '__main__': app.run()
def app(): _app = create_app(**TEST_CONFIG) ctx = _app.app_context() ctx.push() yield _app ctx.pop()
# -*- coding: utf-8 -*- from flask.ext.script import Manager from %(project_name)s import create_app app = create_app(app_name="%(project_name)s") mgr = Manager(app) @mgr.command def run(): app.run() if __name__ == "__main__": mgr.run()
from glob import glob from subprocess import call from flask_migrate import Migrate, MigrateCommand from flask_script import Command, Manager, Option, Server, Shell from flask_script.commands import Clean, ShowUrls from {{cookiecutter.app_name}}.app import create_app from {{cookiecutter.app_name}}.database import db from {{cookiecutter.app_name}}.settings import DevConfig, ProdConfig from {{cookiecutter.app_name}}.user.models import User CONFIG = ProdConfig if os.environ.get('{{cookiecutter.app_name | upper}}_ENV') == 'prod' else DevConfig HERE = os.path.abspath(os.path.dirname(__file__)) TEST_PATH = os.path.join(HERE, 'tests') app = create_app(CONFIG) manager = Manager(app) migrate = Migrate(app, db) def _make_context(): """Return context dict for a shell session so you can access app, db, and the User model by default.""" return {'app': app, 'db': db, 'User': User} @manager.command def test(): """Run the tests.""" import pytest exit_code = pytest.main([TEST_PATH, '--verbose']) return exit_code
def create_app(self): app = create_app(TestConfig) with app.app_context(): db.create_all() return app