Imago/tests/test_storage_extended.py
Bruno Charest cc99fea20a
Some checks failed
CI / Lint & Format (push) Has been cancelled
CI / Tests (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
Add comprehensive test suite for image processing and related services
- Implement tests for database generator to ensure proper session handling.
- Create tests for EXIF extraction and conversion functions.
- Add tests for image-related endpoints, ensuring proper data retrieval and isolation between clients.
- Develop tests for OCR functionality, including language detection and text extraction.
- Introduce tests for the image processing pipeline, covering success and failure scenarios.
- Validate rate limiting functionality and ensure independent counters for different clients.
- Implement scraper tests to verify HTML content fetching and error handling.
- Add unit tests for various services, including storage and filename generation.
- Establish worker entry point for ARQ to handle background image processing tasks.
2026-02-24 11:22:10 -05:00

47 lines
1.4 KiB
Python

import pytest
from fastapi import HTTPException
from app.services.storage import save_upload, delete_files, get_image_url
from unittest.mock import MagicMock, patch, AsyncMock
import io
@pytest.mark.asyncio
async def test_save_upload_unsupported_mime():
mock_file = MagicMock()
mock_file.content_type = "text/plain"
with pytest.raises(HTTPException) as exc:
await save_upload(mock_file, "client_id")
assert exc.value.status_code == 415
@pytest.mark.asyncio
@patch("app.services.storage.settings")
async def test_save_upload_too_large(mock_settings):
mock_settings.max_upload_bytes = 10
mock_settings.MAX_UPLOAD_SIZE_MB = 10
mock_file = MagicMock()
mock_file.content_type = "image/jpeg"
mock_file.read = AsyncMock(return_value=b"a" * 20)
with pytest.raises(HTTPException) as exc:
await save_upload(mock_file, "client_id")
assert exc.value.status_code == 413
def test_delete_files_exists(tmp_path):
f1 = tmp_path / "f1.txt"
f1.write_text("hello")
f2 = tmp_path / "f2.txt"
f2.write_text("world")
assert f1.exists()
assert f2.exists()
delete_files(str(f1), str(f2))
assert not f1.exists()
assert not f2.exists()
def test_get_image_url():
url = get_image_url("img.jpg", "client1")
assert "/static/uploads/client1/img.jpg" in url
thumb_url = get_image_url("img.jpg", "client1", thumb=True)
assert "/static/thumbnails/client1/img.jpg" in thumb_url