You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_nullcharfield.py 939B

123456789101112131415161718192021222324252627
  1. from django.core.exceptions import ImproperlyConfigured
  2. from django.test import TestCase
  3. from oscar.models.fields import NullCharField
  4. class NullCharFieldTest(TestCase):
  5. def test_from_db_value_converts_null_to_string(self):
  6. field = NullCharField()
  7. self.assertEqual(
  8. "",
  9. field.from_db_value(None, expression=None, connection=None, context=None),
  10. )
  11. def test_get_prep_value_converts_empty_string_to_null(self):
  12. field = NullCharField()
  13. self.assertEqual(None, field.get_prep_value(""))
  14. def test_raises_exception_for_invalid_null_blank_combo(self):
  15. with self.assertRaises(ImproperlyConfigured):
  16. NullCharField(null=True, blank=False)
  17. with self.assertRaises(ImproperlyConfigured):
  18. NullCharField(null=False, blank=True)
  19. with self.assertRaises(ImproperlyConfigured):
  20. NullCharField(null=False, blank=False)