MCPcopy
hub / github.com/django/django / test_null_default

Method test_null_default

tests/model_fields/test_booleanfield.py:109–123  ·  view source on GitHub ↗

A BooleanField defaults to None, which isn't a valid value (#15124).

(self)

Source from the content-addressed store, hash-verified

107 self.assertIs(mc.nbf.nbfield, False)
108
109 def test_null_default(self):
110 """
111 A BooleanField defaults to None, which isn't a valid value (#15124).
112 """
113 boolean_field = BooleanModel._meta.get_field("bfield")
114 self.assertFalse(boolean_field.has_default())
115 b = BooleanModel()
116 self.assertIsNone(b.bfield)
117 with transaction.atomic():
118 with self.assertRaises(IntegrityError):
119 b.save()
120
121 nb = NullBooleanModel()
122 self.assertIsNone(nb.nbfield)
123 nb.save() # no error
124
125
126class ValidationTest(SimpleTestCase):

Callers

nothing calls this directly

Calls 5

BooleanModelClass · 0.85
NullBooleanModelClass · 0.85
has_defaultMethod · 0.80
get_fieldMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected