mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-01 11:00:13 +03:00
Add tests for BooleanField when nullable
This commit is contained in:
parent
7f77340b33
commit
18d9dc3657
|
@ -5,6 +5,7 @@ import unittest
|
|||
import uuid
|
||||
from decimal import ROUND_DOWN, ROUND_UP, Decimal
|
||||
|
||||
import django
|
||||
import pytest
|
||||
import pytz
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
|
@ -657,7 +658,7 @@ class TestBooleanField(FieldValues):
|
|||
|
||||
class TestNullBooleanField(TestBooleanField):
|
||||
"""
|
||||
Valid and invalid values for `BooleanField`.
|
||||
Valid and invalid values for `NullBooleanField`.
|
||||
"""
|
||||
valid_inputs = {
|
||||
'true': True,
|
||||
|
@ -682,6 +683,17 @@ class TestNullBooleanField(TestBooleanField):
|
|||
field = serializers.NullBooleanField()
|
||||
|
||||
|
||||
@pytest.mark.skipif(django.VERSION < (2, 1), reason='Django version < 2.1')
|
||||
class TestNullableBooleanField(TestNullBooleanField):
|
||||
"""
|
||||
Valid and invalid values for `BooleanField` when `allow_null=True`.
|
||||
"""
|
||||
|
||||
@property
|
||||
def field(self):
|
||||
return serializers.BooleanField(allow_null=True)
|
||||
|
||||
|
||||
# String types...
|
||||
|
||||
class TestCharField(FieldValues):
|
||||
|
|
|
@ -12,6 +12,7 @@ import decimal
|
|||
import sys
|
||||
from collections import OrderedDict
|
||||
|
||||
import django
|
||||
import pytest
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.validators import (
|
||||
|
@ -220,6 +221,25 @@ class TestRegularFieldMappings(TestCase):
|
|||
)
|
||||
self.assertEqual(unicode_repr(TestSerializer()), expected)
|
||||
|
||||
# merge this into test_regular_fields / RegularFieldsModel when
|
||||
# Django 2.1 is the minimum supported version
|
||||
@pytest.mark.skipif(django.VERSION < (2, 1), reason='Django version < 2.1')
|
||||
def test_nullable_boolean_field(self):
|
||||
class NullableBooleanModel(models.Model):
|
||||
field = models.BooleanField(null=True, default=False)
|
||||
|
||||
class NullableBooleanSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = NullableBooleanModel
|
||||
fields = ['field']
|
||||
|
||||
expected = dedent("""
|
||||
NullableBooleanSerializer():
|
||||
field = BooleanField(allow_null=True, required=False)
|
||||
""")
|
||||
|
||||
self.assertEqual(unicode_repr(NullableBooleanSerializer()), expected)
|
||||
|
||||
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