Пример #1
0
def app():
    app = create_app()
    db.init_app(app)
    with app.app_context():
        db.drop_all()
        db.create_all()
        initialize_test_data()
        yield app
Пример #2
0
def plain_client():
    load_dotenv()

    app = create_app('testing')

    with app.test_client() as client:
        with app.app_context():
            db.init_app(app)

            db.drop_all()
            db.create_all()

        yield client
Пример #3
0
def login_client():
    """
    This fixture create the database consisting one user
    :return:
    """
    load_dotenv()

    app = create_app('testing')

    with app.test_client() as client:
        with app.app_context():
            db.init_app(app)

            db.drop_all()
            db.create_all()

            create_user(email='*****@*****.**', password='******')

        yield client
Пример #4
0
def auth_client():
    """
    This fixture provide a authorized client, with some initial database
    :return:
    """
    load_dotenv()

    app = create_app('testing')

    with app.test_client() as client:
        with app.app_context():
            db.init_app(app)

            db.drop_all()
            db.create_all()

            user_id = create_test_db()
            access_token = create_access_token(identity=user_id)
            client.environ_base[
                'HTTP_AUTHORIZATION'] = 'Bearer ' + access_token

        yield client
Пример #5
0
def create_app(config_name: str):
    """Return initialized and configured Flask app"""
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    db.init_app(app)
    jwt.init_app(app)

    # logging
    init_logger(app)

    # error handling
    app.register_error_handler(Exception, handle_exceptions)
    app.register_error_handler(HTTPException, handle_http_errors)
    app.register_error_handler(BadRequestError, handle_bad_request)
    app.register_error_handler(UnauthorizedError, handle_unauthorized)
    app.register_error_handler(NotFoundError, handle_not_found)

    # routes
    prefix = "/api"
    app.register_blueprint(user_router, url_prefix=prefix)
    app.register_blueprint(habit_router, url_prefix=prefix)
    app.register_blueprint(log_router, url_prefix=prefix)

    return app
Пример #6
0
import os

from main import create_app
from main.db import db

app = create_app()


@app.before_first_request
def create_table():
    db.create_all()


if __name__ == '__main__':
    db.init_app(app)
    app.run(port=8000, debug=True)