summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
authorPetras Zdanavičius <petraszd@gmail.com>2014-07-26 15:25:44 +0300
committerTim Graham <timograham@gmail.com>2014-08-01 09:30:58 -0400
commit8b7347220f3d86b46f5f87270c6cdcb9960895fd (patch)
treee3068d20f882efd6b853fd64a538d601f088ba79 /tests/forms_tests
parent8c2b405ba8343e68bc32ac2c860be0c6cfd7d631 (diff)
downloaddjango-8b7347220f3d86b46f5f87270c6cdcb9960895fd.tar.gz
Fixed #23103 -- Annotated ImageField file with image and content_type attributes.
Thanks Jeremy Dunck for the suggestion and Nick Sanford for review.
Diffstat (limited to 'tests/forms_tests')
-rw-r--r--tests/forms_tests/tests/filepath_test_files/1x1.pngbin0 -> 150 bytes
-rw-r--r--tests/forms_tests/tests/test_fields.py27
2 files changed, 26 insertions, 1 deletions
diff --git a/tests/forms_tests/tests/filepath_test_files/1x1.png b/tests/forms_tests/tests/filepath_test_files/1x1.png
new file mode 100644
index 0000000000..5e2f43a2e1
--- /dev/null
+++ b/tests/forms_tests/tests/filepath_test_files/1x1.png
Binary files differ
diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py
index 2482fe0682..0b82b3940b 100644
--- a/tests/forms_tests/tests/test_fields.py
+++ b/tests/forms_tests/tests/test_fields.py
@@ -31,12 +31,18 @@ import pickle
import re
import os
from decimal import Decimal
+from unittest import skipIf
+
+try:
+ from PIL import Image
+except ImportError:
+ Image = None
from django.core.files.uploadedfile import SimpleUploadedFile
from django.forms import (
BooleanField, CharField, ChoiceField, ComboField, DateField, DateTimeField,
DecimalField, EmailField, Field, FileField, FilePathField, FloatField,
- Form, forms, HiddenInput, IntegerField, MultipleChoiceField,
+ Form, forms, HiddenInput, ImageField, IntegerField, MultipleChoiceField,
NullBooleanField, NumberInput, PasswordInput, RadioSelect, RegexField,
SplitDateTimeField, TextInput, Textarea, TimeField, TypedChoiceField,
TypedMultipleChoiceField, URLField, ValidationError, Widget,
@@ -741,6 +747,24 @@ class FieldsTests(SimpleTestCase):
# with here)
self.assertTrue(f._has_changed('resume.txt', {'filename': 'resume.txt', 'content': 'My resume'}))
+ # ImageField ##################################################################
+
+ @skipIf(Image is None, "Pillow is required to test ImageField")
+ def test_imagefield_annotate_with_image_after_clean(self):
+ f = ImageField()
+
+ img_path = os.path.dirname(upath(__file__)) + '/filepath_test_files/1x1.png'
+ with open(img_path, 'rb') as img_file:
+ img_data = img_file.read()
+
+ img_file = SimpleUploadedFile('1x1.png', img_data)
+ img_file.content_type = 'text/plain'
+
+ uploaded_file = f.clean(img_file)
+
+ self.assertEqual('PNG', uploaded_file.image.format)
+ self.assertEqual('image/png', uploaded_file.content_type)
+
# URLField ##################################################################
def test_urlfield_1(self):
@@ -1262,6 +1286,7 @@ class FieldsTests(SimpleTestCase):
f.choices.sort()
expected = [
('/tests/forms_tests/tests/filepath_test_files/.dot-file', '.dot-file'),
+ ('/tests/forms_tests/tests/filepath_test_files/1x1.png', '1x1.png'),
('/tests/forms_tests/tests/filepath_test_files/directory', 'directory'),
('/tests/forms_tests/tests/filepath_test_files/fake-image.jpg', 'fake-image.jpg'),
('/tests/forms_tests/tests/filepath_test_files/real-text-file.txt', 'real-text-file.txt'),