【发布时间】:2013-12-16 11:57:48
【问题描述】:
我有一个带有 clean 方法的模型,它检查两个字段是否为空,如果是则引发 ValidationError
我怎样才能对实例创建执行测试(通常我使用nose)而不会使测试因错误而失败。我想做一些断言来确保实例的创建失败。
这是干净的方法:
def clean(self):
if not self.message and not self.image:
raise ValidationError('You must provide either Message and/or '
'Image')
【问题讨论】: