Beispiel #1
0
def db(app):
    """Create database for the tests."""
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    # Explicitly close DB connection
    _db.session.close()
    _db.drop_all()
def session():
    # Create app context
    app.app_context().push()

    # Create the database and the database table
    db.create_all()

    # Import mock data
    create_mock_data()

    yield app

    # In the next call drop all data in the databases
    drop_tables()
Beispiel #3
0
def create_app(test_config=None):
    # Create and configure the application
    app = Flask(__name__, instance_relative_config=False)
    app.config.from_pyfile(os.path.join(".", "config.py"))

    # Declare everything we need in this application:
    with app.app_context():

        from main.database import db, Order, Product, User
        # Initialise Plugins
        db.init_app(app)
        db.create_all()
        login_manager.init_app(app)
        Session(app)

        from main.auth import auth_bp
        from main.transact import transact_bp

        # Register Blueprints - These help to compartmentalise routes.
        app.register_blueprint(auth_bp)
        # app.register_blueprint(content.content_bp)
        app.register_blueprint(transact_bp)

        # Ensure responses aren't cached
        @app.after_request
        def after_request(response):
            response.headers[
                "Cache-Control"] = "no-cache, no-store, must-revalidate"
            response.headers["Expires"] = 0
            response.headers["Pragma"] = "no-cache"
            return response

        # Listen for errors
        # for code in default_exceptions:
        #     app.errorhandler(code)(errorhandler)

        import main.auth, main.transact, main.routes
        # print("auth is in {}".format(main.auth.__file__))
        # print("transact is in {}".format(main.transact.__file__))
        # print("routes is in {}".format(main.routes.__file__))
    return app
from main.controllers import init_routes

# Create app instance associated with the module that runs it
app = Flask(__name__)

# Load configurations corresponding to environment
app.config.from_object(config)

# Define bcrypt encryption
bcrypt = Bcrypt(app)

# Init DB
db.init_app(app)

# Initialize database using Flask-SQLAlchemy
db.create_all(app=app)

# Init routes
init_routes()


# Errors handlers
def _response_error(exception=None):
    """To manipulate structure of response payload.

    :param exception: Exception instance for errors
    :return: flask.Response instance
    """

    prepared_data = {
        'error_code': exception.error_code,
Beispiel #5
0
def create_db():
    """Creates the database."""
    db.create_all()
Beispiel #6
0
def recreate_db():
    """Удалить а потом создать все таблицы"""
    if click.confirm('Ты уверен?', abort=True):
        db.drop_all()
        db.create_all()
Beispiel #7
0
def create_db():
    """Создать все таблицы"""
    db.create_all()