Added tests for DecimalValidator.

This commit is contained in:
Josh Schneier 2017-09-09 22:00:31 -04:00 committed by Tim Graham
parent bd903e8a6e
commit 0dbcd0e87f
1 changed files with 12 additions and 0 deletions

View File

@ -2,6 +2,7 @@ import os
import re
import types
from datetime import datetime, timedelta
from decimal import Decimal
from unittest import TestCase, skipUnless
from django.core.exceptions import ValidationError
@ -259,6 +260,17 @@ TEST_DATA = [
(FileExtensionValidator(['TXT']), ContentFile('contents', name='file.txt'), None),
(FileExtensionValidator(), ContentFile('contents', name='file.jpg'), None),
(DecimalValidator(max_digits=2, decimal_places=2), Decimal('0.99'), None),
(DecimalValidator(max_digits=2, decimal_places=1), Decimal('0.99'), ValidationError),
(DecimalValidator(max_digits=3, decimal_places=1), Decimal('999'), ValidationError),
(DecimalValidator(max_digits=4, decimal_places=1), Decimal('999'), None),
(DecimalValidator(max_digits=20, decimal_places=2), Decimal('742403889818000000'), None),
(DecimalValidator(max_digits=20, decimal_places=2), Decimal('7424742403889818000000'), ValidationError),
(DecimalValidator(max_digits=5, decimal_places=2), Decimal('7304E-1'), None),
(DecimalValidator(max_digits=5, decimal_places=2), Decimal('7304E-3'), ValidationError),
(DecimalValidator(max_digits=5, decimal_places=5), Decimal('70E-5'), None),
(DecimalValidator(max_digits=5, decimal_places=5), Decimal('70E-6'), ValidationError),
(validate_image_file_extension, ContentFile('contents', name='file.jpg'), None),
(validate_image_file_extension, ContentFile('contents', name='file.png'), None),
(validate_image_file_extension, ContentFile('contents', name='file.PNG'), None),