Reputation: 608
I started learning django framework in that I have created form which verifies interdependent fields. now I have written a testCase for it but my console is showing 0 test cases ran.I am not getting why it is not running
below is my 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")
and my 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())
please let me know where I went wrong. FYI I tried by overriding clean method of forms but no luck
Upvotes: 0
Views: 207
Reputation: 599470
All test methods need to begin with test_
. (And in any case, standard Python naming convention for methods is lower_case_with_underscore
.)
Call your method test_from_to_location_same
.
Upvotes: 3