表单验证的测试用例没有在django中运行

时间:2017-07-06 08:51:54

标签: python django unit-testing

我开始学习django框架,因为我创建了一个验证相互依赖的字段的表单。现在我已经为它编写了一个testCase,但是我的控制台显示0个测试用例已经运行。我不明白为什么它没有运行

下面的

是我的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())

请让我知道我哪里出错了。仅供参考我试过重写干净的表格方法,但没有运气

1 个答案:

答案 0 :(得分:3)

所有测试方法都需要以$ gradle :appB:deploy deploying Application B to ~/web/appB 开头。 (无论如何,方法的标准Python命名约定是$ gradle :utilityC:deploy [no output] 。)

调用您的方法test_