Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def app():
    """Create application for the tests."""
    _app = create_app("flaskapp.settings.testing")
    _app.logger.setLevel(logging.CRITICAL)
    ctx = _app.test_request_context()
    ctx.push()
    yield _app
    ctx.pop()
Ejemplo n.º 3
0
def app():
    """An application for the tests."""
    _app = create_app(TestConfig)
    ctx = _app.test_request_context()
    ctx.push()

    yield _app

    ctx.pop()
Ejemplo n.º 4
0
import logging
import os

from flaskapp.app import create_app

log = logging.getLogger(__name__)
app = create_app(config_data=os.environ)

if __name__ == '__main__':
    log.info('Serving requests')
    app.run(host='0.0.0.0', port=80)
Ejemplo n.º 5
0
from flaskapp.app import create_app

app = create_app()
app.run(debug=True)
Ejemplo n.º 6
0
from flaskapp.app import create_app
from werkzeug.debug import DebuggedApplication
from werkzeug.contrib.profiler import ProfilerMiddleware
import os

application = create_app()

DEBUG = os.environ.get('DEBUG', False)
if DEBUG:
    application.debug = True
    application.wsgi_app = DebuggedApplication(application.wsgi_app, True)

    application.config['PROFILE'] = True

    application.wsgi_app = ProfilerMiddleware(application.wsgi_app,
                                              restrictions=[30])
Ejemplo n.º 7
0
def test_dev_config():
    """Development config."""
    app = create_app(DevConfig)
    assert app.config['ENV'] == 'dev'
    assert app.config['DEBUG'] is True
    assert app.config['ASSETS_DEBUG'] is True
Ejemplo n.º 8
0
def app():
    app = create_app('flask_test.cfg')
    with app.app_context():
        yield app
Ejemplo n.º 9
0
def app():
    app = create_app(FORCE_ENV_FOR_DYNACONF="testing")
    with app.app_context():
        db.create_all(app=app)
        yield app
        db.drop_all(app=app)
Ejemplo n.º 10
0
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 flaskapp.app import create_app
from flaskapp.database import db
from flaskapp.settings import DevConfig, ProdConfig
from flaskapp.user.models import User

CONFIG = ProdConfig if os.environ.get('FLASKAPP_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
Ejemplo n.º 11
0
# -*- coding: utf-8 -*-
"""Create an application instance."""
from flask.helpers import get_debug_flag

from flaskapp.app import create_app
from flaskapp.settings import DevConfig, ProdConfig

import sys

reload(sys)

sys.setdefaultencoding("utf-8")

CONFIG = DevConfig if get_debug_flag() else ProdConfig

app = create_app(CONFIG)
Ejemplo n.º 12
0
from flaskapp.app import create_app


def production_warning(env, args):
    if len(args):
        env = 'PRODUCTION' if env == 'prod' else 'STAGING'
        cmd = ' '.join(args)
        # allow some time to cancel commands
        for i in [4, 3, 2, 1]:
            click.echo(f'!! {env} !!: Running "{cmd}" in {i} seconds')
            time.sleep(1)


@click.group(cls=FlaskGroup,
             add_default_commands=False,
             create_app=lambda _: create_app(),
             help="""\
A utility script for the 4DSurgery.Planner application.
""")
@click.option('--env',
              type=click.Choice(['dev', 'prod']),
              default='dev',
              help='Whether to use DevConfig or ProdConfig (dev by default).')
@click.option('--warn/--no-warn',
              default=True,
              help='Whether or not to warn if running in production.')
@click.pass_context
def cli(ctx, env, warn):
    ctx.obj.data['env'] = env
    if env != 'dev' and warn:
        production_warning(env, sys.argv[2:])