def test_space_invalid(self): validator = NumberCheck() mock_form = Mock() mock_field = Mock() mock_field.raw_data = [" "] with self.assertRaises(StopValidation) as ite: validator(mock_form, mock_field) self.assertEqual(error_messages["INVALID_NUMBER"], str(ite.exception))
def test_zero_valid(self): validator = NumberCheck() mock_form = Mock() mock_field = Mock() mock_field.raw_data = ["0"] try: validator(mock_form, mock_field) except StopValidation: self.fail("Valid number raised StopValidation")
def _get_number_field_validators(self): answer_errors = self.error_messages.copy() for error_key in self.validation_messages.keys(): answer_errors[error_key] = self.get_validation_message(error_key) return [ NumberCheck(answer_errors["INVALID_NUMBER"]), NumberRange( minimum=self.references["minimum"], minimum_exclusive=self.references["min_exclusive"], maximum=self.references["maximum"], maximum_exclusive=self.references["max_exclusive"], messages=answer_errors, currency=self.answer_schema.get("currency"), ), DecimalPlaces(max_decimals=self.max_decimals, messages=answer_errors), ]
def number_check(): return NumberCheck()