Beispiel #1
0
def run(main, *args):
    """Runs the script in an application context and manages the session cycle.

    :param main: A function to run.
    :param *args: Positional arguments to the `main` function.

    """
    app = create_app(__name__)
    with app.app_context():
        # Create a new session for this script and commit/rollback accordingly.
        session = db.session
        try:
            args += (session,)
            main(*args)
            session.commit()
        except:
            if session.is_active:
                session.rollback()
            raise
        finally:
            session.remove()
Beispiel #2
0
def run(main, *args):
    """Runs the script in an application context and manages the session cycle.

    :param main: A function to run.
    :param *args: Positional arguments to the `main` function.

    """
    app = create_app(__name__)
    with app.app_context():
        # Create a new session for this script and commit/rollback accordingly.
        session = db.session
        try:
            args += (session, )
            main(*args)
            session.commit()
        except:
            if session.is_active:
                session.rollback()
            raise
        finally:
            session.remove()
Beispiel #3
0
def app(request):
    """Session-wide test `Flask` application."""
    settings_override = {
        'TESTING': True,
        'SQLALCHEMY_DATABASE_URI': TEST_DATABASE_URI,
        'SEARCH_INDEX_NAME': TEST_SEARCH_INDEX_NAME
    }

    app = create_app(__name__, settings_override)

    # By default, all tests are run without signals for performance. If a
    # test requires signalling support then it has to require the `signals`
    # fixture.
    deregister_signals()

    # Establish an application context before running the tests.
    ctx = app.app_context()
    ctx.push()

    def teardown():
        ctx.pop()

    request.addfinalizer(teardown)
    return app
Beispiel #4
0
def app(request):
    """Session-wide test `Flask` application."""
    settings_override = {
        'TESTING': True,
        'SQLALCHEMY_DATABASE_URI': TEST_DATABASE_URI,
        'SEARCH_INDEX_NAME': TEST_SEARCH_INDEX_NAME
    }

    app = create_app(__name__, settings_override)

    # By default, all tests are run without signals for performance. If a
    # test requires signalling support then it has to require the `signals`
    # fixture.
    deregister_signals()

    # Establish an application context before running the tests.
    ctx = app.app_context()
    ctx.push()

    def teardown():
        ctx.pop()

    request.addfinalizer(teardown)
    return app
Beispiel #5
0
"""
jobber.app
~~~~~~~~~~

Exposes the `Flask` application.

"""
from jobber import factory
app = factory.create_app(__name__)