def initdb(drop): if drop: click.confirm( 'This operation will delete the database, do you want to continue?', abort=True) db.drop_all() db.create_all() click.echo('Initialized database.')
def make_faker(num_category, num_article, num_comment): from blog.fake_data import fake_admin, fake_articles, fake_categories, fake_comments db.drop_all() db.create_all() fake_admin() fake_categories(num_category) fake_articles(num_article) fake_comments(num_comment)
def client(): # 设置测试数据库路径和测试环境 app = create_app('test') # 初始化测试数据库 with app.test_client() as client: with app.app_context(): db.drop_all() db.create_all() db.session.add(User(username='******', password='******')) db.session.commit() db.session.close() yield client
def forge(category, post, comment): """Generate the fake categories, posts and commands.""" db.drop_all() db.create_all() click.echo('Generating the admin...') fake_admin() click.echo('Generating the categories...') fake_categories(category) click.echo('Generating the posts...') fake_posts(post) click.echo('Generating the comment...') fake_comments(comment) click.echo('Done')
def forge(category, post): """Generate fake data.""" from blog.fakes import fake_categories, fake_posts db.drop_all() db.create_all() click.echo('Generating %d categories...' % category) fake_categories(category) click.echo('Generating %d posts...' % post) fake_posts(post) click.echo('Done.')
def forge(category, post, comment): from blog.fakes import fake_admin, fake_categories, fake_posts, fake_comments db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d categories...' % category) fake_categories(category) click.echo('Generating %d posts...' % post) fake_posts(post) click.echo('Generating %d comments...' % comment) fake_comments(comment) click.echo('Done.')
def forge(user, post, category, comment): """Generate fake data.""" from blog.fakes import fake_admin, fake_user, fake_categories, fake_post, fake_comment db.drop_all() db.create_all() click.echo('Initializing the roles and permissions...') Role.init_role() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d users...' % user) fake_user(user) click.echo('Generating %d categories...' % category) fake_categories(category) click.echo('Generating %d posts...' % post) fake_post(post) # click.echo('Generating %d collects...' % collect) # fake_collect(collect) click.echo('Generating %d comments...' % comment) fake_comment(comment) click.echo('Done.')
def setUp(self): super(CLITestCase, self).setUp() 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.drop_all() self.context.pop()
def init_database(drop): if drop: db.drop_all() db.crete_all()