From a7723261124c2fff7033f20680dd0bc3bc78fa8e Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Mon, 28 Dec 2015 10:38:53 -0500 Subject: [PATCH] Merged two DecimalValidator tests together These two tests were previously added in https://github.com/tomchristie/django-rest-framework/commit/7d79cf35b7be01b175d8c25276a4414e8144a16b 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. --- rest_framework/utils/field_mapping.py | 2 +- tests/test_model_serializer.py | 20 ++------------------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/rest_framework/utils/field_mapping.py b/rest_framework/utils/field_mapping.py index 22a38050d..af7ab0231 100644 --- a/rest_framework/utils/field_mapping.py +++ b/rest_framework/utils/field_mapping.py @@ -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, diff --git a/tests/test_model_serializer.py b/tests/test_model_serializer.py index 2976b1984..af8ce66dd 100644 --- a/tests/test_model_serializer.py +++ b/tests/test_model_serializer.py @@ -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: