add support for heic images
This commit is contained in:
@@ -2,7 +2,9 @@ from io import BytesIO
|
||||
from pathlib import Path
|
||||
|
||||
import app.db as db_module
|
||||
import app.images as images_module
|
||||
from PIL import Image
|
||||
from fastapi import UploadFile
|
||||
|
||||
from app.models import Box, Item, SubItem
|
||||
|
||||
@@ -572,6 +574,24 @@ def test_broken_image_processing_returns_400_and_keeps_image_fields_empty(client
|
||||
assert updated_box.image_height is None
|
||||
|
||||
|
||||
def test_heic_upload_returns_clear_error_if_heif_support_is_unavailable(monkeypatch):
|
||||
heic_file = UploadFile(filename="sample.heic", file=BytesIO(b"not-a-real-heic"))
|
||||
|
||||
def fake_open(*args, **kwargs):
|
||||
raise images_module.UnidentifiedImageError("cannot identify image file")
|
||||
|
||||
monkeypatch.setattr(images_module, "HEIF_SUPPORT_ENABLED", False)
|
||||
monkeypatch.setattr(images_module.Image, "open", fake_open)
|
||||
monkeypatch.setattr(images_module.shutil, "which", lambda command: None)
|
||||
|
||||
try:
|
||||
images_module.process_upload(heic_file)
|
||||
assert False, "Expected HEIC upload to raise HTTPException"
|
||||
except Exception as exc:
|
||||
assert getattr(exc, "status_code", None) == 400
|
||||
assert "HEIC/HEIF" in getattr(exc, "detail", "")
|
||||
|
||||
|
||||
def test_can_search_box_by_name(client, db_session):
|
||||
box = Box(name="冬季衣物箱")
|
||||
db_session.add(box)
|
||||
|
||||
Reference in New Issue
Block a user