From 75ed5900321d170debef4ac452b8b3cf8a1c2384 Mon Sep 17 00:00:00 2001 From: Iulia Chiriac Date: Tue, 14 Apr 2015 18:11:12 -0400 Subject: Fixed #24636 -- Added model field validation for decimal places and max digits. --- tests/model_fields/tests.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/model_fields') diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index 16d8b2fe2c..3d791980ba 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -165,6 +165,24 @@ class DecimalFieldTests(test.TestCase): # This should not crash. That counts as a win for our purposes. Foo.objects.filter(d__gte=100000000000) + def test_max_digits_validation(self): + field = models.DecimalField(max_digits=2) + expected_message = validators.DecimalValidator.messages['max_digits'] % {'max': 2} + with self.assertRaisesMessage(ValidationError, expected_message): + field.clean(100, None) + + def test_max_decimal_places_validation(self): + field = models.DecimalField(decimal_places=1) + expected_message = validators.DecimalValidator.messages['max_decimal_places'] % {'max': 1} + with self.assertRaisesMessage(ValidationError, expected_message): + field.clean(Decimal('0.99'), None) + + def test_max_whole_digits_validation(self): + field = models.DecimalField(max_digits=3, decimal_places=1) + expected_message = validators.DecimalValidator.messages['max_whole_digits'] % {'max': 2} + with self.assertRaisesMessage(ValidationError, expected_message): + field.clean(Decimal('999'), None) + class ForeignKeyTests(test.TestCase): def test_callable_default(self): -- cgit v1.3