mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
add testcase and PEP8 multilines fix
This commit is contained in:
parent
831f688cc5
commit
1cd86fbf40
|
@ -1031,8 +1031,8 @@ class DecimalField(Field):
|
||||||
|
|
||||||
if rounding is not None:
|
if rounding is not None:
|
||||||
valid_roundings = [v for k, v in vars(decimal).items() if k.startswith('ROUND_')]
|
valid_roundings = [v for k, v in vars(decimal).items() if k.startswith('ROUND_')]
|
||||||
assert rounding in valid_roundings, \
|
assert rounding in valid_roundings, (
|
||||||
'Invalid rounding option %s. Valid values for rounding are: %s' % (rounding, valid_roundings)
|
'Invalid rounding option %s. Valid values for rounding are: %s' % (rounding, valid_roundings))
|
||||||
self.rounding = rounding
|
self.rounding = rounding
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
def to_internal_value(self, data):
|
||||||
|
|
|
@ -1092,6 +1092,22 @@ class TestNoDecimalPlaces(FieldValues):
|
||||||
field = serializers.DecimalField(max_digits=6, decimal_places=None)
|
field = serializers.DecimalField(max_digits=6, decimal_places=None)
|
||||||
|
|
||||||
|
|
||||||
|
class TestRoundingDecimalField(TestCase):
|
||||||
|
def test_valid_rounding(self):
|
||||||
|
field = serializers.DecimalField(max_digits=4, decimal_places=2, rounding='ROUND_UP')
|
||||||
|
assert field.to_representation(Decimal('1.234')) == '1.24'
|
||||||
|
|
||||||
|
field = serializers.DecimalField(max_digits=4, decimal_places=2, rounding='ROUND_DOWN')
|
||||||
|
assert field.to_representation(Decimal('1.234')) == '1.23'
|
||||||
|
|
||||||
|
def test_invalid_rounding(self):
|
||||||
|
with pytest.raises(AssertionError) as excinfo:
|
||||||
|
serializers.DecimalField(max_digits=1, decimal_places=1, rounding='ROUND_UNKNOWN')
|
||||||
|
assert 'Invalid rounding option' in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Date & time serializers...
|
# Date & time serializers...
|
||||||
|
|
||||||
class TestDateField(FieldValues):
|
class TestDateField(FieldValues):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user