Пример #1
0
def initdb(drop):
    '''Initialize the database.'''
    if drop:
        db.drop_all()
        click.echo('Droped the database.')
    db.create_all()
    click.echo('Initialized the database.')
Пример #2
0
def forge():
    db.drop_all()
    db.create_all()

    name = "Wang Dingbo"
    movies = [
        {'title': 'My Neighbor Totoro', 'year': '1988'},
        {'title': 'Dead Poets Society', 'year': '1989'},
        {'title': 'A Perfect World', 'year': '1993'},
        {'title': 'Leon', 'year': '1994'},
        {'title': 'Mahjong', 'year': '1996'},
        {'title': 'Swallowtail Butterfly', 'year': '1996'},
        {'title': 'King of Comedy', 'year': '1999'},
        {'title': 'Devils on the Doorstep', 'year': '1999'},
        {'title': 'WALL-E', 'year': '2008'},
        {'title': 'The Pork of Music', 'year': '2012'}
    ]

    user = User(name=name)
    db.session.add(user)
    for m in movies:
        movie = Movie(title=m['title'], year=m['year'])
        db.session.add(movie)
    db.session.commit()
    click.echo('Generate fake data Done.')
Пример #3
0
def initdb(drop):
    """Initialize the database."""
    if drop:
        db.drop_all()
        click.echo('Delete Table.')
    db.create_all()
    click.echo('Initialized database.')
Пример #4
0
def initdb(drop):
    """初始化数据库
    命令行中执行命令 flask initdb 或 flask initdb --drop"""
    if drop:  # 判断是否输入了选项
        db.drop_all()
    db.create_all()
    click.echo('Initialized database.')  # 输出提示信息
Пример #5
0
def initdb(drop):
    """Initialize the datebase."""
    if drop:  # 判断是否输入了选项
        db.drop_all()
        click.echo('Dropped database.')  # 输出提示信息
    db.create_all()
    click.echo('Initialized database.')  # 输出提示信息
Пример #6
0
def initdb(drop):
    #init the database
    if drop:
        click.echo("dropping..")
        db.drop_all()
    else:
        db.create_all()
        click.echo('Initialized database.')
Пример #7
0
def initdb(drop):
    """
    初始化数据库
    """
    if drop:
        db.drop_all()
    db.create_all()
    click.echo("Initialized database!")
Пример #8
0
def initdb(drop):
    """Initialize the database."""
    if drop:
        db.drop_all()
        click.echo('Droped database.')
    else:
        db.create_all()
        click.echo('Initialized database.')
Пример #9
0
def initdb(drop):
    """Initialize the database."""

    if drop:
        db.drop_all()
    db.create_all()

    # 操作完成后显示提示信息
    click.echo('Initialized database.')
Пример #10
0
 def test_admin_command(self):
     db.drop_all()
     db.create_all()
     result = self.runner.invoke(args=['admin', '--username', 'grey', '--password', '123'])
     self.assertIn('Creating user...', result.output)
     self.assertIn('Done.', result.output)
     self.assertEqual(User.query.count(), 1)
     self.assertEqual(User.query.first().username, 'grey')
     self.assertTrue(User.query.first().validate_password('123'))
Пример #11
0
def forge(count):
    """Generate fake data."""
    from faker import Faker

    db.drop_all()
    db.create_all()

    # 全局的两个变量移动到这个函数内
    name = "Five Hao"
    movies = [{
        'title': 'My Neighbor Totoro',
        'year': '1988'
    }, {
        'title': 'Dead Poets Society',
        'year': '1989'
    }, {
        'title': 'A Perfect World',
        'year': '1993'
    }, {
        'title': 'Leon',
        'year': '1994'
    }, {
        'title': 'Mahjong',
        'year': '1996'
    }, {
        'title': 'Swallowtail Butterfly',
        'year': '1996'
    }, {
        'title': 'King of Comedy',
        'year': '1999'
    }, {
        'title': 'Devils on the Doorstep',
        'year': '1999'
    }, {
        'title': 'WALL-E',
        'year': '2008'
    }, {
        'title': 'The Pork of Music',
        'year': '2012'
    }]

    user = User(name=name)
    db.session.add(user)
    for m in movies:
        movie = Movie(title=m['title'], year=m['year'])
        db.session.add(movie)

    fake = Faker()

    for i in range(count):
        message = Message(name=fake.name(),
                          body=fake.sentence(),
                          timestamp=fake.date_time_this_year())
        db.session.add(message)

    db.session.commit()
    click.echo('Done.')
Пример #12
0
def initdb(drop):  # 函数名即为命令的名字
    """Initialize the database.
    命令可选参数 --drop
    flask initdb 创建数据库表
    flask initdb --drop 删除表后再创建数据库表
    """
    if drop:
        db.drop_all()
    db.create_all()
    click.echo('Initialized database.')  # 输出
Пример #13
0
 def test_admin_command(self):
     db.drop_all()
     db.create_all()
     result = self.runner.invoke(
         args=["admin", "--username", "grey", "--password", "123"])
     self.assertIn("Creating user...", result.output)
     self.assertIn("Done.", result.output)
     self.assertEqual(User.query.count(), 1)
     self.assertEqual(User.query.first().username, "grey")
     self.assertTrue(User.query.first().validate_password("123"))
Пример #14
0
def initdb(drop):
    """
    Initialize the database.
    :param drop: 输入drop命令,表示删掉数据库表重建
    :return:
    """
    if drop:  # 判断是否输入了选项
        db.drop_all()
    db.create_all()
    click.echo('Initialized database.')  # 输出提示信息
Пример #15
0
 def test_admin_command(self, runner):
     db.drop_all()
     db.create_all()
     result = runner.invoke(
         args=['admin', '--username', 'XAY', '--password', '123'])
     assert 'Creating user...' in result.output
     assert 'Done' in result.output
     assert User.query.count() == 1
     assert User.query.first().username == 'XAY'
     assert User.query.first().validate_password('123')
Пример #16
0
 def test_admin_command(self):
     """测试admin命令"""
     db.drop_all()
     db.create_all()
     result = self.ruuner.invoke(
         args=['admin', '--username', 'laoyang', '--password', '123'])
     self.assertIn('create user', result.output)
     self.assertIn('Done.', result.output)
     self.assertEqual(User.query.count(), 1)
     self.assertEqual(User.query.first().name, 'laoyang')
     self.assertTrue(User.query.first().check_password('123'))
Пример #17
0
def gen_db_data():
    db.drop_all()
    db.create_all()
    users = []
    movies = []
    for i in range(10):
        item = {}
        item["title"] = fake.name()
        item["year"] = fake.year()
        movies.append(item)
    for i in range(1):
        item = {}
        item["name"] = fake.name()
        users.append(item)
    db.session.bulk_insert_mappings(User, users)  # 批量插入数据
    db.session.bulk_insert_mappings(Movie, movies)
    db.session.commit()
    click.echo("data generated!")
Пример #18
0
def initdb(drop):
    """Initialize the database."""
    if drop:  # 判断是否输入了选项
        db.drop_all()
    db.create_all()

    user = User(email=os.environ.get('EMAIL1'))
    user.set_password(os.environ.get('PASSWORD'))
    db.session.add(user)

    user = User(email=os.environ.get('EMAIL2'))
    user.set_password(os.environ.get('PASSWORD'))
    db.session.add(user)

    user = User(email=os.environ.get('EMAIL3'))
    user.set_password(os.environ.get('PASSWORD'))
    db.session.add(user)

    db.session.commit()
    click.echo('Initialized database.')  # 输出提示信息
Пример #19
0
def initdb(drop):
    """初始化数据库"""
    if drop:
        db.drop_all()
    db.create_all()
    click.echo('初始化数据库完成!')
Пример #20
0
def initdb(drop):
    if drop:
        db.drop_all()
    db.create_all()
    click.echo('初始化数据库')
Пример #21
0
def drop():
    """Drop all data."""
    db.drop_all()
    click.echo('Database clean.')
Пример #22
0
 def tearDown(self):
     db.session.remove()  # 清除数据库会话
     db.drop_all()  # 删除数据库表
Пример #23
0
def initdb(drop):
    if drop:
        db.drop_all()
    db.create_all()
    click.echo("ALL WORKS OK!")
Пример #24
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
Пример #25
0
 def tearDown(self):
     # 删除 数据库会话 和 数据库表
     db.session.remove()
     db.drop_all()
Пример #26
0
def initdb(drop):
    '''Initialize the database'''
    if drop:
        db.drop_all()
    db.create_all()
    click.echo('Initialized database.')  # 输出提示信息
Пример #27
0
 def tearDown(self):  # 测试固件,在每一个测试方法执行后被调用,防止前面的测试对后面的测试造成影响
     db.session.remove()  # 清除数据库会话
     db.drop_all()  # 删除所有数据库表
Пример #28
0
def initdb(drop):
    """Initialize the database."""
    if drop:  # 判断是否输入了选项
        db.drop_all()
    db.create_all()
    click.echo('初始化db成功.')  # 输出提示信息
Пример #29
0
def initdb(drop):
    if drop:
        db.drop_all()
    db.create_all()
    click.echo('initialized database')
Пример #30
0
def initdb(drop):
    """初始化数据库。"""
    if drop:
        db.drop_all()
    db.create_all()
    click.echo('数据库初始化完毕。')