8000 Merged two DecimalValidator tests together · jaydev/django-rest-framework@a772326 · GitHub
[go: up one dir, main page]

Skip to content

Commit a772326

Browse files
committed
Merged two DecimalValidator tests together
These two tests were previously added in encode@7d79cf3 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.
1 parent d797389 commit a772326

File tree

2 files changed

+3
-19
lines changed

2 files changed

+3
-19
lines changed

rest_framework/utils/field_mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def get_field_kwargs(field_name, model_field):
133133
if isinstance(model_field, models.DecimalField) and DecimalValidator:
134134
validator_kwarg = [
135135
validator for validator in validator_kwarg
136-
if DecimalValidator and not isinstance(validator, DecimalValidator)
136+
if not isinstance(validator, DecimalValidator)
137137
]
138138

139139
# Ensure that max_length is passed explicitly as a keyword arg,

tests/test_model_serializer.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from rest_framework import serializers
2424
from rest_framework.compat import DurationField as ModelDurationField
25-
from rest_framework.compat import DecimalValidator, unicode_repr
25+
from rest_framework.compat import unicode_repr
2626

2727

2828
def dedent(blocktext):
@@ -872,25 +872,9 @@ class DecimalFieldModel(models.Model):
872872

873873

874874
class TestDecimalFieldMappings(TestCase):
875-
@pytest.mark.skipif(DecimalValidator is not None,
876-
reason='DecimalValidator is available in Django 1.9+')
877-
def test_decimal_field_has_no_decimal_validator(self):
878-
"""
879-
Test that a DecimalField has no validators before Django 1.9.
880-
"""
881-
class TestSerializer(serializers.ModelSerializer):
882-
class Meta:
883-
model = DecimalFieldModel
884-
885-
serializer = TestSerializer()
886-
887-
assert len(serializer.fields['decimal_field'].validators) == 2
888-
889-
@pytest.mark.skipif(DecimalValidator is None,
890-
reason='DecimalValidator is available in Django 1.9+')
891875
def test_decimal_field_has_decimal_validator(self):
892876
"""
893-
Test that a DecimalField has DecimalValidator in Django 1.9+.
877+
Test that a `DecimalField` has no `DecimalValidator`.
894878
"""
895879
class TestSerializer(serializers.ModelSerializer):
896880
class Meta:

0 commit comments

Comments
 (0)
0