summaryrefslogtreecommitdiff
path: root/tests/regressiontests/forms/fields.py
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2008-11-10 20:04:42 +0000
committerKaren Tracey <kmtracey@gmail.com>2008-11-10 20:04:42 +0000
commit21e0efcd64b7aa0ffdbb7254574644af6d7b7727 (patch)
tree5ea8c391d7889b6b479841620998a962b8439043 /tests/regressiontests/forms/fields.py
parent8c31bb7ca366b6daf393e7f1b4d695837c7f5795 (diff)
[1.0.X] Fixed #7064: Made DemicmalField validation support max_digits equal to decimal_places.
r9387 and r9388 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9389 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/forms/fields.py')
-rw-r--r--tests/regressiontests/forms/fields.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py
index f31ea6fa20..fa5a62ac51 100644
--- a/tests/regressiontests/forms/fields.py
+++ b/tests/regressiontests/forms/fields.py
@@ -366,7 +366,7 @@ True
Traceback (most recent call last):
...
ValidationError: [u'Ensure that there are no more than 2 decimal places.']
->>> f.clean('-000.1234')
+>>> f.clean('-000.12345')
Traceback (most recent call last):
...
ValidationError: [u'Ensure that there are no more than 4 digits in total.']
@@ -416,18 +416,28 @@ ValidationError: [u'Ensure that there are no more than 2 decimal places.']
# Leading whole zeros "collapse" to one digit.
>>> f.clean('0000000.10') == Decimal("0.1")
True
->>> f.clean('0000000.100')
-Traceback (most recent call last):
-...
-ValidationError: [u'Ensure that there are no more than 3 digits in total.']
+
+# But a leading 0 before the . doesn't count towards max_digits
+>>> f.clean('0000000.100') == Decimal("0.100")
+True
# Only leading whole zeros "collapse" to one digit.
>>> f.clean('000000.02') == Decimal('0.02')
True
->>> f.clean('000000.002')
+>>> f.clean('000000.0002')
Traceback (most recent call last):
...
ValidationError: [u'Ensure that there are no more than 3 digits in total.']
+>>> f.clean('.002') == Decimal("0.002")
+True
+
+>>> f = DecimalField(max_digits=2, decimal_places=2)
+>>> f.clean('.01') == Decimal(".01")
+True
+>>> f.clean('1.1')
+Traceback (most recent call last):
+...
+ValidationError: [u'Ensure that there are no more than 0 digits before the decimal point.']
# DateField ###################################################################