def initdb(drop): '''Initialize the database.''' if drop: db.drop_all() click.echo('Droped the database.') db.create_all() click.echo('Initialized the database.')
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.')
def initdb(drop): """Initialize the database.""" if drop: db.drop_all() click.echo('Delete Table.') db.create_all() click.echo('Initialized database.')
def initdb(drop): """初始化数据库 命令行中执行命令 flask initdb 或 flask initdb --drop""" if drop: # 判断是否输入了选项 db.drop_all() db.create_all() click.echo('Initialized database.') # 输出提示信息
def initdb(drop): """Initialize the datebase.""" if drop: # 判断是否输入了选项 db.drop_all() click.echo('Dropped database.') # 输出提示信息 db.create_all() click.echo('Initialized database.') # 输出提示信息
def initdb(drop): #init the database if drop: click.echo("dropping..") db.drop_all() else: db.create_all() click.echo('Initialized database.')
def initdb(drop): """ 初始化数据库 """ if drop: db.drop_all() db.create_all() click.echo("Initialized database!")
def initdb(drop): """Initialize the database.""" if drop: db.drop_all() click.echo('Droped database.') else: db.create_all() click.echo('Initialized database.')
def initdb(drop): """Initialize the database.""" if drop: db.drop_all() db.create_all() # 操作完成后显示提示信息 click.echo('Initialized database.')
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'))
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.')
def initdb(drop): # 函数名即为命令的名字 """Initialize the database. 命令可选参数 --drop flask initdb 创建数据库表 flask initdb --drop 删除表后再创建数据库表 """ if drop: db.drop_all() db.create_all() click.echo('Initialized database.') # 输出
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"))
def initdb(drop): """ Initialize the database. :param drop: 输入drop命令,表示删掉数据库表重建 :return: """ if drop: # 判断是否输入了选项 db.drop_all() db.create_all() click.echo('Initialized database.') # 输出提示信息
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')
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'))
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!")
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.') # 输出提示信息
def initdb(drop): """初始化数据库""" if drop: db.drop_all() db.create_all() click.echo('初始化数据库完成!')
def initdb(drop): if drop: db.drop_all() db.create_all() click.echo('初始化数据库')
def drop(): """Drop all data.""" db.drop_all() click.echo('Database clean.')
def tearDown(self): db.session.remove() # 清除数据库会话 db.drop_all() # 删除数据库表
def initdb(drop): if drop: db.drop_all() db.create_all() click.echo("ALL WORKS OK!")
def tearDown(self): db.session.remove() db.drop_all()
def tearDown(self): # 删除 数据库会话 和 数据库表 db.session.remove() db.drop_all()
def initdb(drop): '''Initialize the database''' if drop: db.drop_all() db.create_all() click.echo('Initialized database.') # 输出提示信息
def tearDown(self): # 测试固件,在每一个测试方法执行后被调用,防止前面的测试对后面的测试造成影响 db.session.remove() # 清除数据库会话 db.drop_all() # 删除所有数据库表
def initdb(drop): """Initialize the database.""" if drop: # 判断是否输入了选项 db.drop_all() db.create_all() click.echo('初始化db成功.') # 输出提示信息
def initdb(drop): if drop: db.drop_all() db.create_all() click.echo('initialized database')
def initdb(drop): """初始化数据库。""" if drop: db.drop_all() db.create_all() click.echo('数据库初始化完毕。')