本文整理汇总了Python中models.Task.create_from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Task.create_from_dict方法的具体用法?Python Task.create_from_dict怎么用?Python Task.create_from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Task
的用法示例。
在下文中一共展示了Task.create_from_dict方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_task_from_dict_invalid_data
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import create_from_dict [as 别名]
def test_create_task_from_dict_invalid_data(self):
count_before_insert = Task.query.count()
task_dict = dict()
with self.assertRaises(ValidationError):
task = Task.create_from_dict(task_dict)
db_session.add(task)
db_session.commit()
count_after_insert = Task.query.count()
示例2: create_task
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import create_from_dict [as 别名]
def create_task():
data = request.get_json()
task = Task.create_from_dict(data)
try:
db_session.add(task)
db_session.commit()
except IntegrityError as e:
db_session.rollback()
return jsonify(dict(message=str(e))), 409
return jsonify(task.to_dict()), 201
示例3: test_create_task_from_dict_invalid_type
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import create_from_dict [as 别名]
def test_create_task_from_dict_invalid_type(self):
count_before_insert = Task.query.count()
task_list = [
'Usuń'
]
with self.assertRaises(TypeError):
task = Task.create_from_dict(task_list)
db_session.add(task)
db_session.commit()
count_after_insert = Task.query.count()
self.assertEqual(count_before_insert, count_after_insert)
示例4: test_create_task_from_dict_invalid_indices
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import create_from_dict [as 别名]
def test_create_task_from_dict_invalid_indices(self):
count_before_insert = Task.query.count()
task_dict = dict(name='tmp', type_id=10, status_id=10, creator_id=10)
with self.assertRaises(IntegrityError):
task = Task.create_from_dict(task_dict)
db_session.add(task)
db_session.commit()
db_session.rollback()
count_after_insert = Task.query.count()
self.assertEqual(count_before_insert, count_after_insert)
示例5: test_create_task_from_dict
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import create_from_dict [as 别名]
def test_create_task_from_dict(self):
count_before_insert = Task.query.count()
task_dict = dict(name='tmp', type_id=1, status_id=1, creator_id=1)
task = Task.create_from_dict(task_dict)
db_session.add(task)
db_session.commit()
count_after_insert = Task.query.count()
self.assertEqual(count_before_insert + 1, count_after_insert)
task = Task.query.filter_by(
name='tmp', type_id=1, status_id=1, creator_id=1).first()
self.assertIsNotNone(task)
self.assertEqual(task_dict['name'], task.name)