mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-01 19:10:12 +03:00
Add test for NullBooleanField
with choices
Author: @preston-wagner in PR #6116
This commit is contained in:
parent
bf9533ae37
commit
9dfee6cd7b
|
@ -363,6 +363,27 @@ class TestRegularFieldMappings(TestCase):
|
||||||
|
|
||||||
ExampleSerializer()
|
ExampleSerializer()
|
||||||
|
|
||||||
|
def test_null_boolean_field_choices(self):
|
||||||
|
|
||||||
|
class Trivial(models.Model):
|
||||||
|
CHECKLIST_OPTIONS = (
|
||||||
|
(None, 'none'),
|
||||||
|
(True, 'checked'),
|
||||||
|
(False, 'N/A'),
|
||||||
|
)
|
||||||
|
|
||||||
|
name = models.CharField(max_length=255)
|
||||||
|
theoretically_nullable_field = models.NullBooleanField(choices=CHECKLIST_OPTIONS)
|
||||||
|
|
||||||
|
class TrivialSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Trivial
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
trivial_serialized = TrivialSerializer(data=dict(name='test', theoretically_nullable_field=None))
|
||||||
|
self.assertTrue(trivial_serialized.is_valid())
|
||||||
|
self.assertEqual(trivial_serialized.errors, {})
|
||||||
|
|
||||||
|
|
||||||
class TestDurationFieldMapping(TestCase):
|
class TestDurationFieldMapping(TestCase):
|
||||||
def test_duration_field(self):
|
def test_duration_field(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user