def test_valid__year(self): validator = DateRequired() mock_form = Mock() mock_form.year.data = "2017" mock_field = Mock() try: validator(mock_form, mock_field) except StopValidation: self.fail("Valid date raised StopValidation")
def test_date_required_empty(self): validator = DateRequired() mock_form = Mock() mock_form.day.data = "" mock_form.month.data = "" mock_form.year.data = "" mock_field = Mock() with self.assertRaises(StopValidation) as ite: validator(mock_form, mock_field) self.assertEqual(error_messages["MANDATORY_DATE"], str(ite.exception))
def test_date_year_required_empty(self): validator = DateRequired() class TestYearSpec: year = None mock_form = Mock(spec=TestYearSpec) mock_form.year.data = "" mock_field = Mock() with self.assertRaises(StopValidation) as ite: validator(mock_form, mock_field) self.assertEqual(error_messages["MANDATORY_DATE"], str(ite.exception))
def validators(self): validate_with = [OptionalForm()] if self.answer_schema["mandatory"] is True: validate_with = [ DateRequired(message=self.get_validation_message( self.MANDATORY_MESSAGE_KEY)) ] error_message = self.get_validation_message("INVALID_DATE") validate_with.append(DateCheck(error_message)) minimum_date = self.get_date_value("minimum") maximum_date = self.get_date_value("maximum") if minimum_date or maximum_date: min_max_validator = self.get_min_max_validator( minimum_date, maximum_date) validate_with.append(min_max_validator) return validate_with
def date_required(): return DateRequired()