Example #1
0
def database(app):

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

        yield db
Example #2
0
def create_test_users():
    with app.app_context():
        print('Committing to database ...')
        db.create_all()
        user_datastore.find_or_create_role(name='superadmin',
                                           description='Superadministrator')
        user_datastore.find_or_create_role(name='master', description='Master')
        user_datastore.find_or_create_role(name='leed', description='Leed')
        encrypted_password = utils.encrypt_password('iddqd3133122')
        db.session.commit()
        user_datastore.create_user(email='*****@*****.**',
                                   password=encrypted_password,
                                   confirmed_at=datetime.datetime.now())
        db.session.commit()
        user_datastore.create_user(email='*****@*****.**',
                                   password=encrypted_password,
                                   confirmed_at=datetime.datetime.now())
        db.session.commit()
        user_datastore.create_user(email='*****@*****.**',
                                   password=encrypted_password,
                                   confirmed_at=datetime.datetime.now())
        db.session.commit()
        user_datastore.add_role_to_user('*****@*****.**',
                                        'superadmin')
        user_datastore.add_role_to_user('*****@*****.**', 'master')
        user_datastore.add_role_to_user('*****@*****.**', 'leed')
        db.session.commit()
    print('SuperUser was created!')
Example #3
0
def upgrade_db():
    os.system('python manage.py db upgrade')
    a = create_test_users()
    with app.app_context():
        print('Creating all ...')
        db.create_all()
    print('All is created!!')
Example #4
0
    def setup(self):
        app = create_test_app()
        self.app = app
        self.client = app.test_client()

        with app.app_context():
            db.drop_all()
            db.create_all()
Example #5
0
def init_empty_database(app):
    with app.app_context():
        # Create the database
        db.create_all()

        yield  # tests run here

        # Destroy the database
        db.drop_all()
Example #6
0
def create_db():
    app = Flask(__name__)
    app.config.from_object(os.environ['APP_SETTINGS'])
    db.init_app(app)

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

    return None
Example #7
0
    def setup(self):
        os.environ['MODE'] = 'TESTING'

        app = create_app()
        self.app = app
        self.client = app.test_client()

        with app.app_context():
            db.drop_all()
            db.create_all()
Example #8
0
def create_db(app):
    """
    A test fixture for creating a database table, with the schema defined in model, 
    once per test class and deleted after exiting the scope of a test class.
    """
    db.app = app
    with app.app_context():
        db.create_all()
        yield db
        db.session.close()
        db.drop_all()
Example #9
0
def app_old():
    """
    Fixture app returning an instance of Flask app
    with created models in the database
    """

    app = create_app("testing")
    with app.app_context():
        db.create_all()

        yield app
        db.drop_all()
Example #10
0
def init_database(app, colors_list):
    with app.app_context():
        # Create the database
        db.create_all()

        # Insert color data
        for color in colors_list:
            db.session.add(Color(color=color['color'], value=color['value']))

        # Commit the changes
        db.session.commit()

        yield  # tests run here

        # Destroy the database
        db.drop_all()
Example #11
0
def client():
    client = app.test_client()

    with app.app_context():
        for table in reversed(db.metadata.sorted_tables):
            try:
                db.engine.execute(table.delete())
            except:
                pass

        db.create_all()
        load_model_fixtures(db, Company, 'company.csv')
        load_model_fixtures(db, Tags, 'tags.csv')
        load_model_fixtures(db, Company_Tags_Map, 'company_tags_map.csv')

        yield client
Example #12
0
def clear():
    """Clear DB"""

    db.drop_all()
    db.create_all()

    # add admin user
    admin_user = User(username='******',
                      email='*****@*****.**',
                      password='******',
                      admin=True)
    db.session.add(admin_user)
    db.session.commit()

    flash("Database refreshed")
    return redirect(url_for('main_bp.chat'))
Example #13
0
def run():
    with app.app_context():
        db.drop_all()
        db.create_all()

        # Administrator
        admin = User(email="*****@*****.**")
        db.session.add(admin)

        # First user
        user1 = User(email="*****@*****.**")
        db.session.add(user1)

        # Second user
        user2 = User(email="*****@*****.**")
        db.session.add(user2)

        db.session.commit()
Example #14
0
def run():
    with app.app_context():
        
        print(f"ran users script. DB: {db}")

        db.drop_all()
        db.create_all()

        # Admin user
        admin = User(email="*****@*****.**")
        db.session.add(admin)

        # First base user
        user1 = User(email="*****@*****.**")
        db.session.add(user1)

        # Second base user
        user2 = User(email="*****@*****.**")
        db.session.add(user2)

        print(f"user.first(): {User.query.first()}")

        db.session.commit()
Example #15
0
from datetime import datetime
from flask import Flask, jsonify, request

app = Flask(__name__)
config = app.config.from_envvar('APP_SETTINGS')

from application.models import db, Task

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


def get_task(task_id):
    return db.session.query(Task).filter_by(id=task_id).first_or_404()


@app.route("/tasks")
def tasks_list():
    tasks = db.session.query(Task).all()
    return jsonify(tasks=[i.serialize for i in tasks])


@app.route("/tasks/<int:task_id>")
def task_by_id(task_id):
    task = get_task(task_id)
    return jsonify(task=task.serialize)


@app.route("/tasks/post", methods=['POST'])
def task_post():
Example #16
0
def create_all():
    with app.app_context():
        print('Creating all ...')
        db.create_all()
    print('All is created!!')
Example #17
0
def create_db():
    """Create database."""
    print 'creating db...'
    print db.engine.url
    db.create_all()
def db_rebuild():
    db.drop_all()
    db.create_all()
    return "Database rebuilt!"
Example #19
0
def syncdb():
    with app.app_context():
        db.create_all()
Example #20
0
def syncdb():
    with app.app_context():
        db.create_all()
Example #21
0
def app():
    """Flask application fixture """
    _app = build_app(env='test')
    db.create_all()
    yield _app
    db.drop_all()
Example #22
0
def createdb():
    """Create database."""
    db.create_all()
Example #23
0
def syncdb():
    """根据model创建数据库tables"""
    db.create_all()
Example #24
0
from application.models import db, UserAdmin
db.drop_all()
db.create_all()

# create admin first user
adm_user = UserAdmin(email='*****@*****.**', password='******')
db.session.add(adm_user)
db.session.commit()
Example #25
0
def syncdb():
    """根据model创建数据库tables"""
    db.create_all()
Example #26
0
def createdb():
    """Create database."""
    db.create_all()
Example #27
0
def initdb():
    """create database tables"""
    db.create_all()