From 3d508ececbd3b7b652aedc66b0d3d2c7baa4795a Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 5 Dec 2024 08:08:09 +0100 Subject: [PATCH] Refs #21286 -- Fixed serializers tests if Pillow isn't installed. --- tests/serializers/models/data.py | 13 +++++++++---- tests/serializers/test_data.py | 12 +++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/serializers/models/data.py b/tests/serializers/models/data.py index 0e08a9b125..77625c05e9 100644 --- a/tests/serializers/models/data.py +++ b/tests/serializers/models/data.py @@ -13,6 +13,15 @@ from django.db import models from .base import BaseModel +try: + from PIL import Image # NOQA +except ImportError: + ImageData = None +else: + + class ImageData(models.Model): + data = models.ImageField(null=True) + class BinaryData(models.Model): data = models.BinaryField(null=True) @@ -62,10 +71,6 @@ class BigIntegerData(models.Model): data = models.BigIntegerField(null=True) -class ImageData(models.Model): - data = models.ImageField(null=True) - - class GenericIPAddressData(models.Model): data = models.GenericIPAddressField(null=True) diff --git a/tests/serializers/test_data.py b/tests/serializers/test_data.py index c0f5a38900..bd81ce0c14 100644 --- a/tests/serializers/test_data.py +++ b/tests/serializers/test_data.py @@ -292,9 +292,6 @@ test_data = [ (data_obj, 81, IntegerData, -123456789), (data_obj, 82, IntegerData, 0), (data_obj, 83, IntegerData, None), - (data_obj, 86, ImageData, "file:///foo/bar/whiz.png"), - # (data_obj, 87, ImageData, None), - (data_obj, 88, ImageData, ""), (data_obj, 95, GenericIPAddressData, "fe80:1424:2223:6cff:fe8a:2e8a:2151:abcd"), (data_obj, 96, GenericIPAddressData, None), (data_obj, 110, PositiveBigIntegerData, 9223372036854775807), @@ -408,6 +405,15 @@ The end.""", (data_obj, 1005, LengthModel, 1), ] +if ImageData is not None: + test_data.extend( + [ + (data_obj, 86, ImageData, "file:///foo/bar/whiz.png"), + # (data_obj, 87, ImageData, None), + (data_obj, 88, ImageData, ""), + ] + ) + class SerializerDataTests(TestCase): pass