Skip to content

Commit c01cb9a

Browse files
committed
Make pillow a dependency (required for django's ImageField)
1 parent fdeb142 commit c01cb9a

File tree

4 files changed

+107
-467
lines changed

4 files changed

+107
-467
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies = [
99
"django-stubs-ext>=4.2.7",
1010
"pyvips>=2.2.2",
1111
"tqdm>=4.66.2",
12+
"pillow",
1213
]
1314
requires-python = ">=3.8"
1415
readme = "README.md"
@@ -57,4 +58,4 @@ pythonpath = "."
5758
addopts = "--cov=easy_images --cov-report=term-missing"
5859

5960
[dependency-groups]
60-
dev = ["pillow", "mkdocs>=1.6.1", "pytest-cov>=5.0.0", "pytest-django>=4.11.0"]
61+
dev = ["mkdocs>=1.6.1", "pytest-cov>=5.0.0", "pytest-django>=4.11.0"]

tests/easy_images_tests/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class Profile(models.Model):
55
name = models.CharField(max_length=100)
6-
image = models.FileField(upload_to="profile-images/")
6+
image = models.ImageField(upload_to="profile-images/")
77
second_image = models.FileField(upload_to="profile-images/", null=True, blank=True)
88

99
def __str__(self):

tests/test_signals.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,24 @@ def test_queued_img_signal(profile_queue_img):
137137
)
138138
# .queue is triggered, which triggers the queued_img signal
139139
assert handler.called
140+
141+
142+
@pytest.mark.django_db
143+
def test_imagefield_signal_trigger(profile_queue_img):
144+
"""Test that saving a model with an ImageField triggers the queue signal."""
145+
# img and queue setup is handled by the fixture
146+
147+
handler = MagicMock()
148+
queued_img.connect(handler)
149+
150+
# Use a minimal valid image content
151+
content = pyvips.Image.black(10, 10).write_to_buffer(".jpg")
152+
Profile.objects.create(
153+
name="ImageField Test",
154+
image=SimpleUploadedFile(name="test_img.jpg", content=content),
155+
)
156+
157+
# Assert the signal was called, indicating queuing happened for ImageField
158+
assert handler.called
159+
# Assert no objects were actually created in DB yet due to lazy loading (default behavior)
160+
assert EasyImage.objects.count() == 0

0 commit comments

Comments
 (0)