diff options
| author | Manatsawin Hanmongkolchai <manatsawin+git@gmail.com> | 2017-05-28 14:05:21 +0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-06-01 10:13:23 -0400 |
| commit | a0c07d77fc313388c72a17cd59411265069f037f (patch) | |
| tree | 6ca6565eb41de7db58122fe41cc853667ee83a76 /tests/forms_tests | |
| parent | 6bb3b2bff4bca24896023758a720f16fa6b1e2bb (diff) | |
Fixed #28242 -- Moved ImageField file extension validation to the form field.
Diffstat (limited to 'tests/forms_tests')
| -rw-r--r-- | tests/forms_tests/field_tests/test_imagefield.py | 11 |
1 files changed, 10 insertions, 1 deletions
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) |
