Ejemplo n.º 1
0
def app():
    app = create_app(TestConfig())
    with app.app_context():
        db.drop_all()
        db.create_all()

    yield app
Ejemplo n.º 2
0
def main():
    app = create_app()

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

    write_to_db(app)
Ejemplo n.º 3
0
    def _app(config_class, init_scheduler=False) -> Flask:
        __app: Flask = create_app(config_class, init_scheduler)

        if config_class is TestingConfig:
            db.drop_all()
            db.create_all()

        return __app
def main():
    app = create_app()

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

        read_from_file_and_write_to_db()

        geocode_cities()
Ejemplo n.º 5
0
 def initdb(drop):
     """Initialize the database."""
     if drop:
         click.confirm(
             'This operation will delete the database, do you want to continue?',
             abort=True)
         db.drop_all()
         click.echo('Drop tables.')
     db.create_all()
     click.echo('Initialized database.')
Ejemplo n.º 6
0
def db(app):
    _db.app = app

    with app.app_context():
        _db.create_all()

    yield _db

    _db.session.close()
    _db.drop_all()
def db(app):
    """
    Setup our database, this only gets executed once per session.

    :param app: Pytest fixture
    :return: SQLAlchemy database session
    """
    _db.drop_all()
    _db.create_all()

    return _db
Ejemplo n.º 8
0
def create_app(config=Config):
    app = Flask(__name__, template_folder='../build', static_folder='../build')

    CORS(app)
    app.config.from_object(config)

    register_extensions(app)

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

    return app
Ejemplo n.º 9
0
def extensions(app):
    """
    Register 0 or more extenstions (mutates the app thats passed in)

    :param app: Flask application instance
    :return: None
    """

    db.init_app(app)
    with app.app_context():
        db.create_all()

    return None
Ejemplo n.º 10
0
def _db():
    """Create and configure a new db instance for pytest-flask-sqlalchemy."""
    db_fd, db_path = tempfile.mkstemp()
    app = create_app()
    app.config["TESTING"] = True
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    app.config["DATABASE"] = db_path
    app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://"

    with app.app_context():
        db.init_app(app)
        db.create_all()

        yield db

    os.close(db_fd)
    os.unlink(db_path)
Ejemplo n.º 11
0
def app():
    """Create and configure a new app instance for tests."""
    # create a temp file to isolate the db for each test
    db_fd, db_path = tempfile.mkstemp()
    app = create_app()
    app.config["TESTING"] = True
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    app.config["DATABASE"] = db_path
    app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://"

    # create the db and load test data
    with app.app_context():
        db.init_app(app)
        db.create_all()

    yield app

    # close and remove the temporary db
    os.close(db_fd)
    os.unlink(db_path)
Ejemplo n.º 12
0
if __name__ == "__main__":

    test = False

    app = create_app()

    if test:
        from flask import jsonify
        from datetime import datetime, time
        from backend.player.schemas import player_schema, level_schema, players_schema
        from backend.game.schemas import game_schema, game_details_schema
        from backend.draw_group.schemas import draw_group_schema

        with app.app_context():

            db.create_all()

            all_players = Player.query.all()
            result = players_schema.dump(all_players)
            jsonify(result)

            players = db.session.query(Player).all()
            player_1 = players[0]
            level_1 = player_1.levels[0]
            draw_group_1 = player_1.draw_groups[0]
            game_1 = draw_group_1.game

            result = player_schema.dump(player_1)
            print(result)

            result = level_schema.dump(level_1)
Ejemplo n.º 13
0
def db():
    db_ext.create_all()
    yield db_ext
    db_ext.drop_all()