Exemple #1
0
 def test_non_mandatory_blank_date(self):
     """
     Test that a non mandatory date with a blank value returns None and not throw an exception
     """
     non_mandatory_date_fields = [f for f in self.non_mandatory_fields if util_model.is_date_field(f)]
     blanks = [None, '', "  "]
     for f in non_mandatory_date_fields:
         for v in blanks:
             try:
                 self.assertEqual(None, to_field_value_raise(f, v))
             except Exception as e:
                 self.assertTrue(False,
                                 msg="A blank value for non mandatory date should return None and not throw an exception")
Exemple #2
0
def to_field_value_raise(field, value, commit=True, site_visit=None, row_data=None):
    if is_blank(value):
        if util_model.is_mandatory(field):
            message = "Mandatory field with no data {field}.".format(field=field.verbose_name)
            raise ValidationException(message)
    # Every next conversion functions should handle a blank/None value
    if util_model.is_lookup_field(field):
        return to_lookup_raise(field, value, commit=commit)
    if util_model.has_choices(field):
        return to_choice_raise(field, value)
    if util_model.is_boolean_field(field):
        return to_boolean_raise(value)
    if util_model.is_integer_field(field):
        return to_integer_raise(value)
    if util_model.is_float_field(field):
        return to_float_raise(value)
    if util_model.is_date_field(field):
        return to_date_raise(value)
    if util_model.is_string_field(field):
        return to_string(value)
    if util_model.is_species_observation_field(field):
        return to_species_observation_raise(value, site_visit, commit=commit, row_data=row_data)
    return value