1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #21548 -- Added FileExtensionValidator and validate_image_file_extension.

This commit is contained in:
Berker Peksag
2016-03-26 22:09:08 +02:00
committed by Tim Graham
parent c9d0a0f7f4
commit 12b4280444
6 changed files with 141 additions and 6 deletions

View File

@@ -4,7 +4,7 @@ import os
import shutil
from unittest import skipIf
from django.core.exceptions import ImproperlyConfigured
from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.core.files import File
from django.core.files.images import ImageFile
from django.test import TestCase
@@ -133,6 +133,12 @@ class ImageFieldTests(ImageFieldTestMixin, TestCase):
self.assertEqual(hash(p1_db.mugshot), hash(p1.mugshot))
self.assertIs(p1_db.mugshot != p1.mugshot, False)
def test_validation(self):
p = self.PersonModel(name="Joan")
p.mugshot.save("shot.txt", self.file1)
with self.assertRaisesMessage(ValidationError, "File extension 'txt' is not allowed."):
p.full_clean()
def test_instantiate_missing(self):
"""
If the underlying file is unavailable, still create instantiate the