mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-03-31 15:24:31 +03:00
Merged two DecimalValidator tests together
These two tests were previously added in
7d79cf35b7
but we have now discovered that there are not actually two separate
cases, there was just a bug in the code that made it look that way.
This also removes a redundant check to see if `DecimalValidator` was
defined.
This commit is contained in:
parent
d797389cf7
commit
a772326112
|
@ -133,7 +133,7 @@ def get_field_kwargs(field_name, model_field):
|
|||
if isinstance(model_field, models.DecimalField) and DecimalValidator:
|
||||
validator_kwarg = [
|
||||
validator for validator in validator_kwarg
|
||||
if DecimalValidator and not isinstance(validator, DecimalValidator)
|
||||
if not isinstance(validator, DecimalValidator)
|
||||
]
|
||||
|
||||
# Ensure that max_length is passed explicitly as a keyword arg,
|
||||
|
|
|
@ -22,7 +22,7 @@ from django.utils import six
|
|||
|
||||
from rest_framework import serializers
|
||||
from rest_framework.compat import DurationField as ModelDurationField
|
||||
from rest_framework.compat import DecimalValidator, unicode_repr
|
||||
from rest_framework.compat import unicode_repr
|
||||
|
||||
|
||||
def dedent(blocktext):
|
||||
|
@ -872,25 +872,9 @@ class DecimalFieldModel(models.Model):
|
|||
|
||||
|
||||
class TestDecimalFieldMappings(TestCase):
|
||||
@pytest.mark.skipif(DecimalValidator is not None,
|
||||
reason='DecimalValidator is available in Django 1.9+')
|
||||
def test_decimal_field_has_no_decimal_validator(self):
|
||||
"""
|
||||
Test that a DecimalField has no validators before Django 1.9.
|
||||
"""
|
||||
class TestSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = DecimalFieldModel
|
||||
|
||||
serializer = TestSerializer()
|
||||
|
||||
assert len(serializer.fields['decimal_field'].validators) == 2
|
||||
|
||||
@pytest.mark.skipif(DecimalValidator is None,
|
||||
reason='DecimalValidator is available in Django 1.9+')
|
||||
def test_decimal_field_has_decimal_validator(self):
|
||||
"""
|
||||
Test that a DecimalField has DecimalValidator in Django 1.9+.
|
||||
Test that a `DecimalField` has no `DecimalValidator`.
|
||||
"""
|
||||
class TestSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
|
|
Loading…
Reference in New Issue
Block a user