summaryrefslogtreecommitdiff
path: root/tests/model_fields/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/model_fields/tests.py')
-rw-r--r--tests/model_fields/tests.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py
index 378e6280cc..429337f31c 100644
--- a/tests/model_fields/tests.py
+++ b/tests/model_fields/tests.py
@@ -12,7 +12,7 @@ from django.db.models.fields import (
AutoField, BigIntegerField, BinaryField, BooleanField, CharField,
CommaSeparatedIntegerField, DateField, DateTimeField, DecimalField,
EmailField, FilePathField, FloatField, IntegerField, IPAddressField,
- GenericIPAddressField, NullBooleanField, PositiveIntegerField,
+ GenericIPAddressField, NOT_PROVIDED, NullBooleanField, PositiveIntegerField,
PositiveSmallIntegerField, SlugField, SmallIntegerField, TextField,
TimeField, URLField)
from django.db.models.fields.files import FileField, ImageField
@@ -275,10 +275,23 @@ class BooleanFieldTests(unittest.TestCase):
Check that a BooleanField defaults to None -- which isn't
a valid value (#15124).
"""
- b = BooleanModel()
- self.assertIsNone(b.bfield)
- with self.assertRaises(IntegrityError):
- b.save()
+ # Patch the boolean field's default value. We give it a default
+ # value when defining the model to satisfy the check tests
+ # #20895.
+ boolean_field = BooleanModel._meta.get_field('bfield')
+ self.assertTrue(boolean_field.has_default())
+ old_default = boolean_field.default
+ try:
+ boolean_field.default = NOT_PROVIDED
+ # check patch was succcessful
+ self.assertFalse(boolean_field.has_default())
+ b = BooleanModel()
+ self.assertIsNone(b.bfield)
+ with self.assertRaises(IntegrityError):
+ b.save()
+ finally:
+ boolean_field.default = old_default
+
nb = NullBooleanModel()
self.assertIsNone(nb.nbfield)
nb.save() # no error