0
我開始學習django框架,因爲我創建了驗證相互依賴字段的表單。現在我已經寫了測試用例的,但我的控制檯顯示0測試用例ran.I我沒有得到爲什麼它沒有運行未在django中運行的表單驗證測試用例
下面是我forms.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")
和我tests.py
from django.test import TestCase
from booking.forms import SearchForm
# Create your tests here.
class SearchTestCase(TestCase):
def fromToLocationSameTestCase(self):
form_data={'fromLocation':'bangalore','toLocation':'bangalore','fromDate':'2017-06-07'}
form=SearchForm(data=form_data)
self.assertFlase(form.is_valid())
請讓我知道我出錯的地方。僅供參考我試圖通過推翻形式的乾淨方法,但沒有運氣