def forge(user, tag, photo, collect, comment, follow, notification): """Generate fake data.""" 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 follows...' % follow) fake_follow(follow) click.echo('Generating %d tags...' % tag) fake_tag(tag) click.echo('Generating %d photos...' % photo) fake_photo(photo) click.echo('Generating %d collects...' % collect) fake_collect(collect) click.echo('Generating %d comments...' % comment) fake_comment(comment) click.echo('Generating %d notifications...' % notification) fake_notification(notification) click.echo('Done.')
def setUp(self): app = create_app('testing') self.context = app.test_request_context() self.context.push() self.client = app.test_client() self.runner = app.test_cli_runner() db.create_all() Role.init_role() admin_user = User(email='*****@*****.**', name='Admin', username='******', confirmed=True) admin_user.set_password('123') normal_user = User(email='*****@*****.**', name='Normal User', username='******', confirmed=True) normal_user.set_password('123') unconfirmed_user = User(email='*****@*****.**', name='unconfirmed', username='******', confirmed=False) unconfirmed_user.set_password('123') locked_user = User(email='*****@*****.**', name='Locked User', username='******', confirmed=True, locked=True) locked_user.set_password('123') locked_user.lock() blocked_user = User(email='*****@*****.**', name='Blocked User', username='******', confirmed=True, active=False) blocked_user.set_password('123') photo = Photo(filename='test.jpg', filename_s='test_s.jpg', filename_m='test_m.jpg', description='Photo 1', author=admin_user) photo2 = Photo(filename='test2.jpg', filename_s='test_s2.jpg', filename_m='test_m2.jpg', description='Photo 2', author=normal_user) comment = Comment(body='test comment body', photo=photo, author=normal_user) tag = Tag(name='test tag') photo.tags.append(tag) db.session.add_all([ admin_user, normal_user, unconfirmed_user, locked_user, blocked_user ]) db.session.commit()
def forge(user, follow, photo, tag, collect, comment): """Generate fake data.""" from albumy.fakes import fake_admin, fake_comment, fake_follow, fake_photo, fake_tag, fake_user, fake_collect 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 follows...' % follow) fake_follow(follow) click.echo('Generating %d tags...' % tag) fake_tag(tag) click.echo('Generating %d photos...' % photo) fake_photo(photo) click.echo('Generating %d collects...' % photo) fake_collect(collect) click.echo('Generating %d comments...' % comment) fake_comment(comment) click.echo('Done.')
def initdb(drop): if drop: click.confirm('该选项将会删除数据库,是否继续执行?', abort=True) db.drop_all() click.echo('删除数据库') db.create_all() click.echo('初始化数据库')
def fake(user, follow, photo, tag, collect, comment): """ 使用flask fake创建虚拟数据 """ from albumy.fakes import fake_admin, fake_comment, fake_follow, fake_photo, fake_tag, fake_user, fake_collect 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 follows...' % follow) # 虚拟关注数据 fake_follow(follow) click.echo('Generating %d tags...' % tag) # 虚拟标签 fake_tag(tag) click.echo('Generating %d photos...' % photo) # 虚拟图片 fake_photo(photo) click.echo('Generating %d collects...' % photo) # 随机收藏数据 fake_collect(collect) click.echo('Generating %d comments...' % comment) # 虚拟评论 fake_comment(comment) click.echo('Done.')
def forge(user, follow, photo, tag, collect, comment): from albumy.fakes import fake_admin, fake_user, fake_photo, fake_tag, fake_comment, fake_collect, fake_follow db.drop_all() db.create_all() click.echo('Initializing the role and permissions...') Role.init_role() click.echo('Generating the administrator') fake_admin() click.echo(f'Generating {user} users...') fake_user(user) click.echo(f'Gnerrating {follow} follows...') fake_follow(follow) click.echo(f'Generating {tag} tags...') fake_tag(tag) click.echo(f'Generating {photo} photos...') fake_photo(photo) click.echo(f'Generating {collect} collects..') fake_collect(collect) click.echo(f'Generating {comment} comments...') fake_comment(comment) click.echo('Done.')
def initdb(drop): if drop: click.confirm('Confirm to delete database') db.drop_all() click.echo('Database deleted') db.create_all() click.echo('Initialized database')
def init(): click.echo('Initializing the database....') db.create_all() click.echo('Initializing the roles and permissions...') Role.init_role() click.echo('Done.')
def initdb(drop): """Initialize the database.""" if drop: click.confirm('This operation will delete the database, do you want to continue?', abort=True) db.drop_all() click.echo('Drop tables.') db.create_all() click.echo('Initialized database.')
def init(): """Initialize Albumy.""" click.echo("Initializing the database...") db.create_all() click.echo("Initializing the roles and permissions...") Role.init_role() click.echo("Done.")
def init(): click.echo("creating database and tables...") db.drop_all() db.create_all() click.echo("Initializing the roles and permission...") Role.init_role() click.echo("Done...")
def initdb(drop): '''Initialize the database''' if drop: click.confirm('The operation will delete the database, ' 'will you like to continue?', abort=True) db.drop_all() click.echo('Drop tables.') db.create_all() click.echo('Initialized the database.')
def init(): """Initialize Albumy.""" click.echo('初始化数据库') db.create_all() click.echo('初始化角色与权限') Role.init_role() click.echo('结束')
def initdb(drop): """ 使用flask initdb清空数据库然后再初始化数据库 """ if drop: click.confirm('该操作将会清空数据表数据,是否继续?', abort=True) db.drop_all() click.echo('Drop tables.') db.create_all() click.echo('Initialized database.')
def init(): """Initialize Albumy.""" click.echo('Droping the database...') db.drop_all() click.echo('Initializing the database...') db.create_all() click.echo('Initializing the roles and permissions...') Role.init_role() click.echo('Done.')
def init(): """ 初始化数据库 """ click.echo('Initializing the database...') db.create_all() click.echo('Initializing the roles and permissions...') # 在Role类中,调用init_role函数将会初始化Role数据和Permission数据 Role.init_role() click.echo('Done.')
def forge(user): """Generate fake data.""" from albumy.fakes import fake_admin, fake_user db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d users...' % user) fake_user(user) click.echo('Done.')
def init(drop): """Initialize Albumy.""" if drop: click.confirm( 'This operation will delete the database, do you want to continue?', abort=True) db.drop_all() click.echo('Drop tables.') click.echo('Initializing the database...') db.create_all() click.echo('Initializing the roles and permissions...') Role.init_role() click.echo('Done.')
def forge(user): from albumy.fakes import fake_admin, fake_users db.drop_all() db.create_all() Role.init_role() fake_admin() fake_users(user) fake_tag() fake_photo() fake_comment() fake_collect() fake_follow() click.echo('Done')
def forge(user, photo, tag, comment, collect, follow): """Generate fake data.""" from albumy.fakes import fake_user, fake_admin, fake_tag, fake_photo, fake_comment, fake_collect, fake_follow from flask import current_app uploads_path = current_app.config['ALBUMY_UPLOAD_PATH'] avatars_path = current_app.config['AVATARS_SAVE_PATH'] for f in os.listdir(uploads_path): filepath = os.path.join(uploads_path, f) if os.path.isfile(filepath): os.remove(filepath) print('delete uploads file {}'.format(f)) for f in os.listdir(avatars_path): filepath = os.path.join(avatars_path, f) if os.path.isfile(filepath): os.remove(filepath) print('delete uploads file {}'.format(f)) click.echo('drop tables and then create...') 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 tags...' % tag) fake_tag() click.echo('Generating %d photos...' % photo) fake_photo(photo) click.echo('Generating %d comments...' % comment) fake_comment(comment) click.echo('Generating %d collects...' % collect) fake_collect(collect) click.echo('Generating %d follows...' % follow) fake_follow(follow) click.echo('Done.')
def init_db(): db.drop_all() db.create_all()
def init(): """Initialize Albumy.""" click.echo('Initializing the database...') db.create_all() click.echo('Done.')
def setUp(self) -> None: app = create_app('testing') self.context = app.test_request_context() self.context.push() self.client = app.test_client() self.runner = app.test_cli_runner() db.create_all() Role.init_role() admin_user = User(email='*****@*****.**', name='Admin', username='******', confirmed=True) admin_user.password = '******' normal_user = User(email='*****@*****.**', name='Normal', username='******', confirmed=True) normal_user.password = '******' unconfirm_user = User(email='*****@*****.**', name='Unconfirm', username='******', confirmed=False) unconfirm_user.password = '******' locked_user = User(email='*****@*****.**', name='Locked', username='******', confirmed=True, locked=True) locked_role = Role.query.filter_by(name='Locked').first() locked_user.role = locked_role locked_user.password = '******' block_user = User(email='*****@*****.**', name='Block', username='******', confirmed=True, active=False) block_user.password = '******' photo = Photo(filename='test.jpg', filename_s='test_s.jpg', filename_m='test_m.jpg', author=admin_user, description='Photo 1') photo2 = Photo(filename='test2.jpg', filename_s='test2_s.jpg', filename_m='test2_m.jpg', author=normal_user, description='Photo 2') comment = Comment(body='test comment body', photo=photo, author=normal_user) tag = Tag(name='test tag') photo.tags.append(tag) db.session.add_all([ admin_user, normal_user, unconfirm_user, locked_user, block_user, photo, photo2, comment, tag ]) db.session.commit()