コード例 #1
0
def test_create_app():
    try:
        create_app()
    except SystemExit:
        # Clean git repository doesn't have `local_config.py`, so it is fine
        # if we get SystemExit error.
        pass
コード例 #2
0
def enter(context, install_dependencies=True, upgrade_db=True):
    """
    Enter into IPython notebook shell with an initialized app.
    """
    if install_dependencies:
        context.invoke_execute(context, 'app.deps.install')
    if upgrade_db:
        context.invoke_execute(context, 'app.db.upgrade')
        context.invoke_execute(context,
                               'app.db.init_dev_data',
                               upgrade_db=False,
                               skip_on_failure=True)

    import pprint
    from werkzeug import script
    import flask

    import catalog
    flask_app = catalog.create_app()

    def shell_context():
        context = dict(pprint=pprint.pprint)
        context.update(vars(flask))
        context.update(vars(catalog))
        return context

    with flask_app.app_context():
        script.make_shell(shell_context, use_ipython=True)()
コード例 #3
0
def flask_app():
    app = create_app(flask_config_name='testing')
    from catalog.extensions import db

    with app.app_context():
        db.create_all()
        yield app
        db.drop_all()
コード例 #4
0
ファイル: conftest.py プロジェクト: theanht1/nd-004
def app():
    os.environ['FLASK_ENV'] = 'test'
    test_app = create_app()
    # Init test db
    with test_app.app_context():
        init_db()
        seed_db()

    yield test_app
コード例 #5
0
def app():
    app = create_app()

    with app.app_context():
        db.engine.execute(_data_sql)

    yield app

    with app.app_context():
        db.drop_all()

    db.session.remove()
コード例 #6
0
ファイル: _utils.py プロジェクト: mt1976/catalog
        def wrapper(*args, **kwargs):
            """
            A wrapped which tries to get ``app`` from ``kwargs`` or creates a
            new ``app`` otherwise, and actives the application context, so the
            decorated function is run inside the application context.
            """
            app = kwargs.pop('app', None)
            if app is None:
                from catalog import create_app
                app = create_app()

            with app.app_context():
                return func(*args, **kwargs)
コード例 #7
0
def export(context, output_format='json', quiet=False):
    """
    Export swagger.json content
    """
    # set logging level to ERROR to avoid [INFO] messages in result
    logging.getLogger().setLevel(logging.ERROR)

    from catalog import create_app
    app = create_app()
    swagger_content = app.test_client().get('/api/v1/swagger.%s' %
                                            output_format).data
    if not quiet:
        print(swagger_content.decode('utf-8'))
    return swagger_content
コード例 #8
0
ファイル: run.py プロジェクト: mt1976/catalog
def run(
        context,
        host='0.0.0.0',
        port=4444,
        flask_config=None,
        install_dependencies=True,
        upgrade_db=True
):
    if flask_config is not None:
        os.environ['CATALOG_CONFIG'] = flask_config

    if install_dependencies:
        context.invoke_execute(context, 'app.deps.install')

    from catalog import create_app
    app = create_app()

    if upgrade_db:
        # After the installed dependencies the app.db.* tasks might need to be
        # reloaded to import all necessary dependencies.
        from . import db as db_tasks
        reload(db_tasks)

        context.invoke_execute(context, 'app.db.upgrade', app=app)
        if app.debug:
            context.invoke_execute(
                context,
                'app.db.init_dev_data',
                app=app,
                upgrade_db=False,
                skip_on_failure=True
            )

    use_reloader = app.debug
    if platform.system() == 'Windows':
        warnings.warn(
            "Auto-reloader feature doesn't work on Windows. "
            "Follow the issue for more details: "
            "https://github.com/frol/flask-restplus-server-example/issues/16"
        )
        use_reloader = False

    app.run(host=host, port=port, debug=True, use_reloader=use_reloader)
コード例 #9
0
def test_create_app_passing_flask_config_name(flask_config_name):
    create_app(flask_config_name=flask_config_name)
コード例 #10
0
ファイル: manage.py プロジェクト: kumaratinfy/fullstack
    1) python manage.py runserver to launch application
    2) python manage.py db migrate to detect changes in  schema
    3) python manage.py db upgrade to apply detected changes in  schema
    4) python manage.py test to run unit tests
    5) python manage.py shell to launch python shell with key modules imported
"""
from catalog import create_app
from flask.ext.script import Server, Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand
from catalog.model import User, Role, Item, Category
from catalog import model
from catalog import db

import os
# Configuration can be provided dynamically an environment variable
app = create_app(os.getenv('FLASK_CONFIG') or None)
manager = Manager(app)
server = Server(host='0.0.0.0', port=5000)
manager.add_command("runserver", server)

# Initializes Flask-Migrate extension to automatically handle
# modifications in schema
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)

# Default imports available after launching the shell
def _make_context():
    return dict(app=app, model=model, db=db, User=User, Role=Role,
                Item=Item, Category=Category)

コード例 #11
0
import os

from catalog import create_app, db

from flask.ext.script import Manager, Server
from flask.ext.migrate import Migrate, MigrateCommand

app = create_app(os.getenv('CATALOG_ENV') or 'dev')

manager = Manager(app)

migrate = Migrate(app, db)

manager.add_command("runserver", Server(port=5000, host='0.0.0.0'))
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manager.run()
コード例 #12
0
ファイル: run.py プロジェクト: klazich/catalog
import os

from catalog import create_app
from config import config_obj

# check for environment variable
config_env = os.getenv('FLASK_CONFIG', 'default')
config = config_obj[config_env]

# create flask app with the factory
app = create_app(config)

if app.debug:
    os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

# start the server
if __name__ == '__main__':
    app.run()
コード例 #13
0
ファイル: test.py プロジェクト: kumaratinfy/p5-linux-config
 def setUp(self):
     self.app = create_app('application.testing.cfg')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
コード例 #14
0
def test_create_app_passing_FLASK_CONFIG_env(monkeypatch, flask_config_name):
    monkeypatch.setenv('CATALOG_CONFIG', flask_config_name)
    create_app()
コード例 #15
0
 def setUp(self):
     self.app = create_app('application.testing.cfg')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     Role.insert_roles()
コード例 #16
0
ファイル: run.py プロジェクト: ducminh-phan/fullstack-nd004
from catalog import create_app

if __name__ == "__main__":
    app = create_app()
    app.run(debug=True)
コード例 #17
0
def test_create_app_with_conflicting_config(monkeypatch):
    monkeypatch.setenv('CATALOG_CONFIG', 'production')
    with pytest.raises(AssertionError):
        create_app('development')
コード例 #18
0
ファイル: manage.py プロジェクト: code-lgtm/p5-linux-config
    1) python manage.py runserver to launch application
    2) python manage.py db migrate to detect changes in  schema
    3) python manage.py db upgrade to apply detected changes in  schema
    4) python manage.py test to run unit tests
    5) python manage.py shell to launch python shell with key modules imported
"""
from catalog import create_app
from flask.ext.script import Server, Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand
from catalog.model import User, Role, Item, Category
from catalog import model
from catalog import db

import os
# Configuration can be provided dynamically an environment variable
app = create_app(os.getenv('FLASK_CONFIG') or None)
manager = Manager(app)
server = Server(host='0.0.0.0', port=5000)
manager.add_command("runserver", server)

# Initializes Flask-Migrate extension to automatically handle
# modifications in schema
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)

# Default imports available after launching the shell
def _make_context():
    return dict(app=app, model=model, db=db, User=User, Role=Role,
                Item=Item, Category=Category)

コード例 #19
0
def test_create_app_with_non_existing_config():
    with pytest.raises(KeyError):
        create_app('non-existing-config')