Exemplo n.º 1
0
def validate_lookup(field, value):
    valid, message = True, None
    try:
        to_lookup_raise(field, value, commit=False)
    except Exception as e:
        valid = False
        message = str(e)
    return valid, message
Exemplo n.º 2
0
 def test_not_strict_add(self):
     """
     Test that for not strict lookup a new value is added
     """
     # choose a non_strict_lookup
     f = self.not_strict_lookup_fields[0]
     original_values = util_model.get_field_lookup_values(f)
     original_size = len(original_values)
     new_value = "test38738"
     to_lookup_raise(f, new_value, commit=True)
     # the new value should have been added
     values = util_model.get_field_lookup_values(f)
     self.assertEqual(original_size + 1, len(values))
     self.assertTrue(new_value in values)
Exemplo n.º 3
0
 def test_not_strict_blank(self):
     """
     A blank value for a non strict lookup should not be added
     """
     # choose a non_strict_lookup
     f = self.not_strict_lookup_fields[0]
     original_values = util_model.get_field_lookup_values(f)
     original_size = len(original_values)
     blanks = ["", None, "   "]
     for blank in blanks:
         lookup = to_lookup_raise(f, blank, commit=True)
         values = util_model.get_field_lookup_values(f)
         self.assertEqual(original_size, len(values))
         self.assertTrue(blank not in values)