コード例 #1
0
ファイル: run.py プロジェクト: ez4u/ijust_backend
def drop_database():
    from project import app
    from project.extensions import db
    import project.models
    with app.app_context():
        db.drop_all()
        db.session.commit()
コード例 #2
0
def recreate_test_db():
    """Recreates testing database."""
    app.config.from_object('project.config.TestingConfig')
    db.reflect()
    db.drop_all()
    db.create_all()
    db.session.commit()
コード例 #3
0
ファイル: utils.py プロジェクト: uaprom-summer-2015/Meowth
    def tearDown(self):
        """
        Drop it all!

        DO NOT FORGET TO CALL THIS METHOD WHEN OVERRIDING
        """
        with self.app.app_context():
            db.drop_all()
コード例 #4
0
    def tearDown(self):
        """
        Drop it all!

        DO NOT FORGET TO CALL THIS METHOD WHEN OVERRIDING
        """
        with self.app.app_context():
            db.drop_all()
コード例 #5
0
def app():
    """Create and configure a new app instance for each test."""
    # create the app with common test config
    app = create_app()
    # create the database and load test data
    with app.app_context():
        db.drop_all()
        db.create_all()
        db.session.commit()
    yield app
コード例 #6
0
ファイル: cmd_add.py プロジェクト: Jayden-Liang/mypractice
def users():
    """
    generate users and data
    """
    user_emails = []
    data =[]
    for i in range(300):
        user_emails.append(fake.email())
    while True:
        email = user_emails.pop()
        user_set = {
              'username': fake.name(),
              'email': email,
              'password': User.encryptpassword('password'),
              'ct': fake.iso8601(tzinfo=None, end_datetime=None),
              'last_login_ip': fake.ipv4_private(),
              'current_login_ip': fake.ipv4_private()
              ''
        }
        data.append(user_set)
        if len(user_emails) <=0:
            break
    fisrt_admin = {
         'username': fake.name(),
         'email': app.config['SEED_ADMIN_EMAIL'],
         'password': User.encryptpassword(app.config['SEED_ADMIN_PASSWORD']),
         'ct': fake.iso8601(tzinfo=None, end_datetime=None),
         'last_login_ip': fake.ipv4_private(),
         'current_login_ip': fake.ipv4_private()
    }
    data.append(fisrt_admin)
    with app.app_context():
        db.drop_all()
        db.create_all()
        # User.query.delete()   #批量删除
        # db.session.commit()
        print('删除了')
        db.engine.execute(User.__table__.insert(), data)
        all = User.query.all()
        add_role_account()
        admin = Role.query.filter_by(name='Admin').first()
        user = Role.query.filter_by(name='Normal_Users').first()
        for u in all:
            i = random.random()
            if i <= 0.05:
                admin.users.append(u)
            else:
                user.users.append(u)
        db.session.commit()
        print('insert success')
コード例 #7
0
    def setUp(self):
        with app.app_context():
            app.config['TESTING'] = True
            app.config['WTF_CSRF_ENABLED'] = False
            app.config['DEBUG'] = False
            app.config['SECRET_KEY'] = 'testing'
            #app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(app.config['BASEDIR'], TEST_DB)
            app.config[
                'SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(
                    BASEDIR, TEST_DB)
            self.app = app.test_client()
            db.drop_all()
            db.create_all()

        self.assertEquals(app.debug, False)
コード例 #8
0
ファイル: cmd_db.py プロジェクト: Jayden-Liang/mypractice
def init(with_testdb):
    """
    初始化,如果传入参数则创建测试数据库

    :param with_testdb: Create a test database
    :return: None
    """
    db.drop_all()
    db.create_all()

    if with_testdb:
        db_uri = '{0}_test'.format(app.config['SQLALCHEMY_DATABASE_URI'])
        if not database_exists(db_uri):
            create_database(db_uri)
            print('创建了测试数据库')

    return None
コード例 #9
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
コード例 #10
0
def syncdb():
    """Init/reset database."""
    db.drop_all()
    db.create_all()
コード例 #11
0
ファイル: database.py プロジェクト: iustce/cesa-web
def drop():
    """Drops database tables"""
    if prompt_bool("Are you sure you want to lose all your data"):
        db.drop_all()
コード例 #12
0
def init_db():
    db.drop_all()
    db.create_all()
コード例 #13
0
def syncdb():
    """Init/reset database."""
    db.drop_all()
    db.create_all()
コード例 #14
0
def recreate_db():
    db.drop_all()
    db.create_all()
    db.session.commit()
    print('Database dropped and recreated.')
コード例 #15
0
def drop_db():
    """Drop a database."""
    db.reflect()
    db.drop_all()
    db.session.commit()
コード例 #16
0
def drop_db():
    """Drop testing database."""
    app.config.from_object('project.config.TestingConfig')
    db.reflect()
    db.drop_all()
    db.session.commit()
コード例 #17
0
ファイル: models.py プロジェクト: Cybran111/Meowth
def init_db():
    db.drop_all()
    db.create_all()
コード例 #18
0
"""Create an admin user in the database."""

from project.extensions import db
from project.app import create_app

app = create_app()

# Keep database tables but delete all information
with app.app_context():
    db.drop_all()
    db.create_all()
    db.session.commit()
コード例 #19
0
def recreate_db():
    db.drop_all()
    db.create_all()
    db.session.commit()
コード例 #20
0
def recreate_db():
    """Recreates a database."""
    db.reflect()
    db.drop_all()
    db.create_all()
    db.session.commit()