Beispiel #1
0
    def test_valid_value(self):
        api.BirthDayField().validate("")

        yesterday = (date.today() - relativedelta(days=1))
        api.BirthDayField().validate(yesterday.strftime("%d.%m.%Y"))

        near_69_years_ago = (date.today() - relativedelta(years=69, days=364))
        api.BirthDayField().validate(near_69_years_ago.strftime("%d.%m.%Y"))
Beispiel #2
0
    def test_not_valid_age(self):
        tomorrow = (date.today() + relativedelta(days=1))
        exc_msg = "Date mustn't be in the future"
        with pytest.raises(ValueError, message=exc_msg):
            api.BirthDayField().validate(tomorrow.strftime("%d.%m.%Y"))

        ago_70_years = (date.today() - relativedelta(years=70))
        exc_msg = "Age must be less than 70 years"
        with pytest.raises(ValueError, message=exc_msg):
            api.BirthDayField().validate(ago_70_years.strftime("%d.%m.%Y"))
Beispiel #3
0
 def test_not_valid_date(self, value, exc_type, exc_msg):
     with pytest.raises(exc_type, message=exc_msg):
         api.BirthDayField().validate(value)