mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
parent
6a42128ddf
commit
602eec8fa0
|
@ -7,6 +7,7 @@ from decimal import ROUND_DOWN, ROUND_UP, Decimal
|
|||
|
||||
import pytest
|
||||
import pytz
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from django.http import QueryDict
|
||||
from django.test import TestCase, override_settings
|
||||
|
@ -17,6 +18,11 @@ import rest_framework
|
|||
from rest_framework import exceptions, serializers
|
||||
from rest_framework.fields import DjangoImageField, is_simple_callable
|
||||
|
||||
try:
|
||||
import cdecimal
|
||||
except ImportError:
|
||||
cdecimal = False
|
||||
|
||||
try:
|
||||
import typings
|
||||
except ImportError:
|
||||
|
@ -1128,6 +1134,16 @@ class TestQuantizedValueForDecimal(TestCase):
|
|||
expected_digit_tuple = (0, (1, 2, 0, 0), -2)
|
||||
assert value == expected_digit_tuple
|
||||
|
||||
@unittest.skipUnless(cdecimal, 'requires python 2.7')
|
||||
def test_quantize_on_monkey_patched_cdecimal(self):
|
||||
# Monkey-patch cdecimal to replace decimal in for DecimalField
|
||||
monkeypatch = MonkeyPatch()
|
||||
|
||||
with monkeypatch.context() as m:
|
||||
m.setattr('rest_framework.fields.decimal', cdecimal)
|
||||
f = rest_framework.fields.DecimalField(max_digits=4, decimal_places=2)
|
||||
f.quantize(cdecimal.Decimal('1.234'))
|
||||
|
||||
|
||||
class TestNoDecimalPlaces(FieldValues):
|
||||
valid_inputs = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user