本文整理汇总了Python中app.models.User.generate_fake方法的典型用法代码示例。如果您正苦于以下问题:Python User.generate_fake方法的具体用法?Python User.generate_fake怎么用?Python User.generate_fake使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.User
的用法示例。
在下文中一共展示了User.generate_fake方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUpClass
# 需要导入模块: from app.models import User [as 别名]
# 或者: from app.models.User import generate_fake [as 别名]
def setUpClass(cls):
# start Chrome
try:
cls.client = webdriver.Chrome(service_args=["--verbose", "--log-path=test-reports/chrome.log"])
except:
pass
# skip these tests if the browser could not be started
if cls.client:
# create the application
cls.app = create_app('testing')
cls.app_context = cls.app.app_context()
cls.app_context.push()
# suppress logging to keep unittest output clean
import logging
logger = logging.getLogger('werkzeug')
logger.setLevel("ERROR")
# create the database and populate with some fake data
db.create_all()
Role.insert_roles()
User.generate_fake(10)
Post.generate_fake(10)
# add an administrator user
admin_role = Role.query.filter_by(permissions=0xff).first()
admin = User(email='john@example.com',
username='john', password='cat',
role=admin_role, confirmed=True)
db.session.add(admin)
db.session.commit()
# start the Flask server in a thread
threading.Thread(target=cls.app.run).start()
# give the server a second to ensure it is up
time.sleep(1)
示例2: add_fake_data
# 需要导入模块: from app.models import User [as 别名]
# 或者: from app.models.User import generate_fake [as 别名]
def add_fake_data(number_users):
"""
Adds fake data to the database.
"""
User.generate_fake(count=number_users)
示例3: setUpClass
# 需要导入模块: from app.models import User [as 别名]
# 或者: from app.models.User import generate_fake [as 别名]
def setUpClass(cls):
# start Firefox
try:
cls.client = webdriver.Firefox()
except:
pass
# skip these tests if the browser could not be started
if cls.client:
# create the application
cls.app = create_app('testing')
cls.app_context = cls.app.app_context()
cls.app_context.push()
# suppress logging to keep unittest output clean
import logging
logger = logging.getLogger('werkzeug')
logger.setLevel("ERROR")
# create the database and populate with some fake data
db.create_all()
Role.insert_roles()
User.generate_fake(10)
Post.generate_fake(10)
# add an administrator user
admin_role = Role.query.filter_by(permissions=0xff).first()
admin = User(email='john@example.com',
username='john', password='cat',
role=admin_role, confirmed=True)
db.session.add(admin)
db.session.commit()
# start the Flask server in a thread
threading.Thread(target=cls.app.run).start()
# give the server a second to ensure it is up
time.sleep(1)