Add test for BooleanField(null=True, choices)

This commit is contained in:
Kevin Brown 2020-01-07 19:46:51 -05:00
parent 1cc79a34e0
commit 5d380eca2e

View File

@ -235,6 +235,27 @@ class TestRegularFieldMappings(TestCase):
self.assertEqual(repr(NullableBooleanSerializer()), expected)
def test_nullable_boolean_field_choices(self):
class NullableBooleanChoicesModel(models.Model):
CHECKLIST_OPTIONS = (
(None, 'Unknown'),
(True, 'Yes'),
(False, 'No'),
)
field = models.BooleanField(null=True, choices=CHECKLIST_OPTIONS)
class NullableBooleanChoicesSerializer(serializers.ModelSerializer):
class Meta:
model = NullableBooleanChoicesModel
fields = ['field']
serializer = NullableBooleanChoicesSerializer(data=dict(
field=None,
))
self.assertTrue(serializer.is_valid())
self.assertEqual(serializer.errors, {})
def test_method_field(self):
"""
Properties and methods on the model should be allowed as `Meta.fields`