Skip to content

Commit c9d29f1

Browse files
committed
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.
1 parent 2d27d9a commit c9d29f1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_model_serializer.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,3 +899,29 @@ class Meta:
899899
serializer = TestSerializer()
900900

901901
assert len(serializer.fields['decimal_field'].validators) == 2
902+
903+
def test_min_value_is_passed(self):
904+
"""
905+
Test that the `MinValueValidator` is converted to the `min_value`
906+
argument for the field.
907+
"""
908+
class TestSerializer(serializers.ModelSerializer):
909+
class Meta:
910+
model = DecimalFieldModel
911+
912+
serializer = TestSerializer()
913+
914+
assert serializer.fields['decimal_field'].min_value == 1
915+
916+
def test_max_value_is_passed(self):
917+
"""
918+
Test that the `MaxValueValidator` is converted to the `max_value`
919+
argument for the field.
920+
"""
921+
class TestSerializer(serializers.ModelSerializer):
922+
class Meta:
923+
model = DecimalFieldModel
924+
925+
serializer = TestSerializer()
926+
927+
assert serializer.fields['decimal_field'].max_value == 1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy