我开始学习django框架,因为我已经创建了验证相互依赖字段的表单。现在我已经为它编写了一个测试用例,但是我的控制台显示有0个测试用例运行,我不明白它为什么不运行
下面是我的表单.py在
class SearchForm(forms.ModelForm):
fromDate=forms.DateField()
toDate=forms.DateField(required=False)
fromLocation=forms.CharField()
toLocation=forms.CharField()
def clean(self):
"""verify from and to date and location"""
cleanedData=super().clean()
fLocation=cleanedData.get('fromLocation')
tLocation=cleanedData.get('toLocation')
self.validateLocation(fLocation,tLocation)
self.validateDates(self.fromDate,self.toDate)
def validateLocation(self,fLocation,tLocation):
if fLocation==tLocation:
raise forms.ValidationError(_("from and to location can not be same"),code="invalid location")
def validateDates(self,fromDate,toDate):
if toDate is not None:
if toDate <= fromDate:
raise forms.ValidationError(_("from date should be less than to date"),code="invalid date")
还有我的测试.py在
^{pr2}$请告诉我我哪里出错了。仅供参考,我试图覆盖干净的表单方法,但没有运气
所有测试方法都必须以
test_
开头。(在任何情况下,方法的标准Python命名约定是lower_case_with_underscore
)调用您的方法
test_from_to_location_same
。在相关问题 更多 >
编程相关推荐