mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 08:59:54 +03:00
Add test for BooleanField(null=True, choices)
This commit is contained in:
parent
1cc79a34e0
commit
5d380eca2e
|
@ -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`
|
||||
|
|
Loading…
Reference in New Issue
Block a user