本文整理汇总了Python中app.models.Comment.generate_fake方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.generate_fake方法的具体用法?Python Comment.generate_fake怎么用?Python Comment.generate_fake使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Comment
的用法示例。
在下文中一共展示了Comment.generate_fake方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rebuild
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import generate_fake [as 别名]
def rebuild():
if config == 'development':
with app.app_context():
db.drop_all()
db.create_all()
Role.insert_roles()
admin_me = User(email=app.config['FLASKR_ADMIN'],
username=app.config['MY_USERNAME'],
password=app.config['MY_PASSWORD'],
confirmed=True,
name=forgery_py.name.full_name(),
location=forgery_py.address.city(),
about_me=forgery_py.lorem_ipsum.sentences(10),
member_since=forgery_py.date.date(True,
min_delta=10))
db.session.add(admin_me)
ordinary_me = User(email=forgery_py.internet.email_address(),
username='exm',
password='exm',
confirmed=True,
name=forgery_py.name.full_name(),
location=forgery_py.address.city(),
about_me=forgery_py.lorem_ipsum.sentences(10),
member_since=forgery_py.date.date(True,
min_delta=10))
db.session.add(ordinary_me)
db.session.commit()
User.generate_fake(30)
Post.generate_fake(500)
Follow.generate_fake(500)
Comment.generate_fake(500)
else:
print('Permission denied.')
示例2: generate_fake
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import generate_fake [as 别名]
def generate_fake():
"""Generate fake data"""
Role.insert_roles()
admin = User(email='[email protected]', password='secret', confirmed=True, username='Admin')
db.session.add(admin)
db.session.commit()
print('Inserting admin user: [email protected]')
User.generate_fake()
Post.generate_fake()
Comment.generate_fake()
Follow.generate_fake()
示例3: genfake
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import generate_fake [as 别名]
def genfake():
config = os.getenv('FLASK_CONFIG') or 'default'
if config == 'default' or config == 'development':
print("delete all files ...")
db.drop_all()
db.create_all()
print("creating roles ...")
Role.insert_roles()
print("creating cities ...")
City.insert_cities()
print("creating topics ...")
Topic.insert_topics()
print("creating users ...")
User.generate_fake()
print("creating conferences ...")
Conference.generate_fake()
print("creating comments ...")
Comment.generate_fake()
示例4: deploy
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import generate_fake [as 别名]
def deploy():
"""Run deployment tasks."""
from flask.ext.migrate import upgrade
upgrade()
# create user roles
Role.insert_roles()
Category.insert_categories()
User.generate_fake(6)
v=User(email='[email protected]',username="AAA",password='admin123',confirmed=True)
u=User(email='[email protected]',username="ABC",password='123456',confirmed=True,role_id=3)
v.role_id=2
db.session.add(v)
db.session.commit()
db.session.add(u) ####插入管理员用户
db.session.commit()
User.add_self_follows()
Post.generate_fake(15)
Comment.generate_fake(15)
示例5: deploy
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import generate_fake [as 别名]
def deploy(deploy_type):
from flask.ext.migrate import upgrade
from app.models import BlogInfo, User, ArticleTypeSetting, Source, \
ArticleType, Plugin, BlogView, Comment
# upgrade database to the latest version
upgrade()
if deploy_type == 'product':
# step_1:insert basic blog info
BlogInfo.insert_blog_info()
# step_2:insert admin account
User.insert_admin(email='[email protected]', username='blog_mini', password='blog_mini', userlevel='admin')
# step_3:insert system default setting
ArticleTypeSetting.insert_system_setting()
# step_4:insert default article sources
Source.insert_sources()
# step_5:insert default articleType
ArticleType.insert_system_articleType()
# step_6:insert system plugin
Plugin.insert_system_plugin()
# step_7:insert blog view
BlogView.insert_view()
# You must run `python manage.py deploy(product)` before run `python manage.py deploy(test_data)`
if deploy_type == 'test_data':
# step_1:insert navs
Menu.insert_menus()
# step_2:insert articleTypes
ArticleType.insert_articleTypes()
# step_3:generate random articles
Article.generate_fake(100)
# step_4:generate random comments
Comment.generate_fake(300)
# step_5:generate random replies
Comment.generate_fake_replies(100)
# step_4:generate random comments
Comment.generate_fake(300)
示例6: test_comments
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import generate_fake [as 别名]
def test_comments(self):
u = User(
email='[email protected]',
password='cat',
username='john')
db.session.add(u)
db.session.commit()
# user is not confirmed
# generate posts first, then comments
Post.generate_fake(testing=True)
Comment.generate_fake(testing=True)
all_posts = Post.query.all()
response = self.client.get(
url_for('api.get_comments'),
headers=self.get_api_headers(
'[email protected]', 'cat'))
self.assertTrue(response.status_code==403)
json_response = json.loads(response.data.decode('utf-8'))
self.assertTrue(json_response['error']=='forbidden')
self.assertTrue(json_response['message']=='Unconfirmed account')
u.confirmed = True
db.session.add(u)
db.session.commit()
# user is now confirmed
response = self.client.get(
url_for('api.get_comments'),
headers=self.get_api_headers(
'[email protected]', 'cat'))
self.assertTrue(response.status_code==200)
json_response = json.loads(response.data.decode('utf-8'))
self.assertTrue(json_response['next']==
url_for('api.get_comments', page=2, _external=True))
# go to page two
response = self.client.get(
url_for('api.get_comments', page=2),
headers=self.get_api_headers(
'[email protected]', 'cat'))
self.assertTrue(response.status_code==200)
json_response = json.loads(response.data.decode('utf-8'))
self.assertTrue(json_response['prev']==
url_for('api.get_comments', page=1, _external=True))
# get comments of post 1 (page=1)
response = self.client.get(
url_for('api.get_post_comments', id=1),
headers=self.get_api_headers(
'[email protected]',
'cat'))
self.assertTrue(response.status_code==200)
json_response = json.loads(response.data.decode('utf-8'))
self.assertTrue(json_response['next'] ==
url_for(
'api.get_post_comments',
id=1,
page=2,
_external=True))
# get comments of post 1 (page=2)
response = self.client.get(
url_for('api.get_post_comments', id=1, page=2),
headers=self.get_api_headers(
'[email protected]',
'cat'))
self.assertTrue(response.status_code==200)
json_response = json.loads(response.data.decode('utf-8'))
self.assertTrue(json_response['prev'] ==
url_for(
'api.get_post_comments',
id=1,
page=1,
_external=True))