summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphael Michel <mail@raphaelmichel.de>2017-04-06 17:34:00 +0200
committerFlorian Apolloner <apollo13@users.noreply.github.com>2017-04-07 12:45:08 +0200
commitbde814142a933bd96c3fa54a64cb1f74a575bb38 (patch)
treeb235a8ee4f10513f9c2782a16a122cca91137249 /tests
parentfd892f3443fe9a35684b7b798a8fe1b07d118e3c (diff)
Fixed #22654 -- Broken decimal validation
Diffstat (limited to 'tests')
-rw-r--r--tests/forms_tests/field_tests/test_decimalfield.py17
-rw-r--r--tests/forms_tests/field_tests/test_floatfield.py16
2 files changed, 32 insertions, 1 deletions
diff --git a/tests/forms_tests/field_tests/test_decimalfield.py b/tests/forms_tests/field_tests/test_decimalfield.py
index c8fd95fd68..1d5d27c8a0 100644
--- a/tests/forms_tests/field_tests/test_decimalfield.py
+++ b/tests/forms_tests/field_tests/test_decimalfield.py
@@ -1,7 +1,7 @@
import decimal
from django.forms import DecimalField, NumberInput, ValidationError, Widget
-from django.test import SimpleTestCase
+from django.test import SimpleTestCase, override_settings
from django.utils import formats, translation
from . import FormFieldAssertionsMixin
@@ -156,3 +156,18 @@ class DecimalFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
f = DecimalField(max_digits=2, decimal_places=2, localize=True)
localized_d = formats.localize_input(d) # -> '0,1' in French
self.assertFalse(f.has_changed(d, localized_d))
+
+ @override_settings(USE_L10N=False, DECIMAL_SEPARATOR=',')
+ def test_decimalfield_support_decimal_separator(self):
+ f = DecimalField(localize=True)
+ self.assertEqual(f.clean('1001,10'), decimal.Decimal("1001.10"))
+ self.assertEqual(f.clean('1001.10'), decimal.Decimal("1001.10"))
+
+ @override_settings(USE_L10N=False, DECIMAL_SEPARATOR=',', USE_THOUSAND_SEPARATOR=True,
+ THOUSAND_SEPARATOR='.')
+ def test_decimalfield_support_thousands_separator(self):
+ f = DecimalField(localize=True)
+ self.assertEqual(f.clean('1.001,10'), decimal.Decimal("1001.10"))
+ msg = "'Enter a number.'"
+ with self.assertRaisesMessage(ValidationError, msg):
+ f.clean('1,001.1')
diff --git a/tests/forms_tests/field_tests/test_floatfield.py b/tests/forms_tests/field_tests/test_floatfield.py
index 83209d7c66..b36942afa4 100644
--- a/tests/forms_tests/field_tests/test_floatfield.py
+++ b/tests/forms_tests/field_tests/test_floatfield.py
@@ -1,5 +1,6 @@
from django.forms import FloatField, NumberInput, ValidationError
from django.test import SimpleTestCase
+from django.test.utils import override_settings
from django.utils import formats, translation
from . import FormFieldAssertionsMixin
@@ -83,3 +84,18 @@ class FloatFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
f = FloatField(localize=True)
localized_n = formats.localize_input(n) # -> '4,35' in French
self.assertFalse(f.has_changed(n, localized_n))
+
+ @override_settings(USE_L10N=False, DECIMAL_SEPARATOR=',')
+ def test_decimalfield_support_decimal_separator(self):
+ f = FloatField(localize=True)
+ self.assertEqual(f.clean('1001,10'), 1001.10)
+ self.assertEqual(f.clean('1001.10'), 1001.10)
+
+ @override_settings(USE_L10N=False, DECIMAL_SEPARATOR=',', USE_THOUSAND_SEPARATOR=True,
+ THOUSAND_SEPARATOR='.')
+ def test_decimalfield_support_thousands_separator(self):
+ f = FloatField(localize=True)
+ self.assertEqual(f.clean('1.001,10'), 1001.10)
+ msg = "'Enter a number.'"
+ with self.assertRaisesMessage(ValidationError, msg):
+ f.clean('1,001.1')