mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-15 10:42:24 +03:00
test: skip image file size validator tests if Pillow is not installed
- Remove top-level PIL import from tests/test_validators.py - Conditionally import PIL inside image-related tests and skip them if Pillow is unavailable
This commit is contained in:
parent
6c9e2266cd
commit
888df27dc3
|
@ -8,7 +8,6 @@ from django import VERSION as django_version
|
|||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.db import DataError, models
|
||||
from django.test import TestCase
|
||||
from PIL import Image
|
||||
|
||||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
@ -1186,6 +1185,11 @@ class TestFileSizeValidatorIntegration(TestCase):
|
|||
assert 'min_file_size' in serializer.errors['file'][0].code
|
||||
|
||||
def test_imagefield_max_size(self):
|
||||
try:
|
||||
from PIL import Image
|
||||
except ImportError:
|
||||
pytest.skip("PIL not available")
|
||||
|
||||
class ImageSerializer(serializers.Serializer):
|
||||
image = serializers.ImageField(validators=[MaxFileSizeValidator(1024)])
|
||||
|
||||
|
@ -1207,6 +1211,11 @@ class TestFileSizeValidatorIntegration(TestCase):
|
|||
assert 'max_file_size' in serializer.errors['image'][0].code
|
||||
|
||||
def test_imagefield_min_size(self):
|
||||
try:
|
||||
from PIL import Image
|
||||
except ImportError:
|
||||
pytest.skip("PIL not available")
|
||||
|
||||
class ImageSerializer(serializers.Serializer):
|
||||
image = serializers.ImageField(validators=[MinFileSizeValidator(100)])
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user