From a0c07d77fc313388c72a17cd59411265069f037f Mon Sep 17 00:00:00 2001 From: Manatsawin Hanmongkolchai Date: Sun, 28 May 2017 14:05:21 +0700 Subject: Fixed #28242 -- Moved ImageField file extension validation to the form field. --- tests/forms_tests/field_tests/test_imagefield.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests/forms_tests') diff --git a/tests/forms_tests/field_tests/test_imagefield.py b/tests/forms_tests/field_tests/test_imagefield.py index 6fb4bed03c..0a0f60440e 100644 --- a/tests/forms_tests/field_tests/test_imagefield.py +++ b/tests/forms_tests/field_tests/test_imagefield.py @@ -2,7 +2,7 @@ import os import unittest from django.core.files.uploadedfile import SimpleUploadedFile -from django.forms import ImageField +from django.forms import ImageField, ValidationError from django.test import SimpleTestCase try: @@ -55,3 +55,12 @@ class ImageFieldTest(SimpleTestCase): self.assertIsNone(uploaded_file.content_type) finally: Image.register_mime(BmpImageFile.format, 'image/bmp') + + def test_file_extension_validation(self): + f = ImageField() + img_path = get_img_path('filepath_test_files/1x1.png') + with open(img_path, 'rb') as img_file: + img_data = img_file.read() + img_file = SimpleUploadedFile('1x1.txt', img_data) + with self.assertRaisesMessage(ValidationError, "File extension 'txt' is not allowed."): + f.clean(img_file) -- cgit v1.3