diff options
| author | Iulia Chiriac <iulia.chiriac@eaudeweb.ro> | 2015-04-14 18:11:12 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2015-09-18 14:30:20 -0400 |
| commit | 75ed5900321d170debef4ac452b8b3cf8a1c2384 (patch) | |
| tree | ec56a72e05f2ab8b588d48453ee0fcc4a31331ba /tests | |
| parent | 6f1b09bb5c1bafe4633514cbff37f9a7ed7a63ae (diff) | |
Fixed #24636 -- Added model field validation for decimal places and max digits.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/model_fields/tests.py | 18 | ||||
| -rw-r--r-- | tests/validators/tests.py | 29 |
2 files changed, 42 insertions, 5 deletions
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): diff --git a/tests/validators/tests.py b/tests/validators/tests.py index 2acafbfcef..f696f8e573 100644 --- a/tests/validators/tests.py +++ b/tests/validators/tests.py @@ -10,11 +10,12 @@ from unittest import TestCase from django.core.exceptions import ValidationError from django.core.validators import ( - BaseValidator, EmailValidator, MaxLengthValidator, MaxValueValidator, - MinLengthValidator, MinValueValidator, RegexValidator, URLValidator, - int_list_validator, validate_comma_separated_integer_list, validate_email, - validate_integer, validate_ipv4_address, validate_ipv6_address, - validate_ipv46_address, validate_slug, validate_unicode_slug, + BaseValidator, DecimalValidator, EmailValidator, MaxLengthValidator, + MaxValueValidator, MinLengthValidator, MinValueValidator, RegexValidator, + URLValidator, int_list_validator, validate_comma_separated_integer_list, + validate_email, validate_integer, validate_ipv4_address, + validate_ipv6_address, validate_ipv46_address, validate_slug, + validate_unicode_slug, ) from django.test import SimpleTestCase from django.test.utils import str_prefix @@ -401,3 +402,21 @@ class TestValidatorEquality(TestCase): MinValueValidator(45), MinValueValidator(11), ) + + def test_decimal_equality(self): + self.assertEqual( + DecimalValidator(1, 2), + DecimalValidator(1, 2), + ) + self.assertNotEqual( + DecimalValidator(1, 2), + DecimalValidator(1, 1), + ) + self.assertNotEqual( + DecimalValidator(1, 2), + DecimalValidator(2, 2), + ) + self.assertNotEqual( + DecimalValidator(1, 2), + MinValueValidator(11), + ) |
