From 9bab640b0a9908cf9777da6efae8dcd1e158a980 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Thu, 24 Dec 2015 14:00:49 -0500 Subject: [PATCH] Added tests for min_value and max_value on a DecimalField This adds tests for a regression where the `min_value` and `max_value` arguments are not being set for a DRF `DecimalField` even though the corresponding `MinValueValidator` and `MaxValueValidator` is being set on the model fields. Note that this only appears to be a regression for Django < 1.9, as these regression tests pass on newer versions of Django. --- tests/test_model_serializer.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_model_serializer.py b/tests/test_model_serializer.py index 57e540e7a..e2c3a7a47 100644 --- a/tests/test_model_serializer.py +++ b/tests/test_model_serializer.py @@ -899,3 +899,29 @@ class TestDecimalFieldMappings(TestCase): serializer = TestSerializer() assert len(serializer.fields['decimal_field'].validators) == 2 + + def test_min_value_is_passed(self): + """ + Test that the `MinValueValidator` is converted to the `min_value` + argument for the field. + """ + class TestSerializer(serializers.ModelSerializer): + class Meta: + model = DecimalFieldModel + + serializer = TestSerializer() + + assert serializer.fields['decimal_field'].min_value == 1 + + def test_max_value_is_passed(self): + """ + Test that the `MaxValueValidator` is converted to the `max_value` + argument for the field. + """ + class TestSerializer(serializers.ModelSerializer): + class Meta: + model = DecimalFieldModel + + serializer = TestSerializer() + + assert serializer.fields['decimal_field'].max_value == 3