mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 03:20:12 +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
|
import uuid
|
||||||
from decimal import ROUND_DOWN, ROUND_UP, Decimal
|
from decimal import ROUND_DOWN, ROUND_UP, Decimal
|
||||||
|
|
||||||
|
import django
|
||||||
import pytest
|
import pytest
|
||||||
import pytz
|
import pytz
|
||||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||||
|
@ -657,7 +658,7 @@ class TestBooleanField(FieldValues):
|
||||||
|
|
||||||
class TestNullBooleanField(TestBooleanField):
|
class TestNullBooleanField(TestBooleanField):
|
||||||
"""
|
"""
|
||||||
Valid and invalid values for `BooleanField`.
|
Valid and invalid values for `NullBooleanField`.
|
||||||
"""
|
"""
|
||||||
valid_inputs = {
|
valid_inputs = {
|
||||||
'true': True,
|
'true': True,
|
||||||
|
@ -682,6 +683,17 @@ class TestNullBooleanField(TestBooleanField):
|
||||||
field = serializers.NullBooleanField()
|
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...
|
# String types...
|
||||||
|
|
||||||
class TestCharField(FieldValues):
|
class TestCharField(FieldValues):
|
||||||
|
|
|
@ -12,6 +12,7 @@ import decimal
|
||||||
import sys
|
import sys
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
import django
|
||||||
import pytest
|
import pytest
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.core.validators import (
|
from django.core.validators import (
|
||||||
|
@ -220,6 +221,25 @@ class TestRegularFieldMappings(TestCase):
|
||||||
)
|
)
|
||||||
self.assertEqual(unicode_repr(TestSerializer()), expected)
|
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):
|
def test_method_field(self):
|
||||||
"""
|
"""
|
||||||
Properties and methods on the model should be allowed as `Meta.fields`
|
Properties and methods on the model should be allowed as `Meta.fields`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user