Files
guilan-ace-backend/apps/gallery/tests/integration/test_tasks.py
Amirhossein Khalili ff99130938 test: migrate backend suites to pytest with module coverage gate
Split backend tests into unit and integration suites, add isolated fixtures and coverage enforcement, and update CI and test documentation. Cover current authentication, content, notification, payment, media, and admin flows; fix behaviors revealed by the new tests. Validate both suites and the per-module gate against local PostgreSQL.
2026-09-26 16:50:29 +03:30

29 lines
1.2 KiB
Python

import pytest
from django.core.files.base import ContentFile
from apps.gallery.models import Gallery
from apps.gallery.tasks import process_uploaded_image
pytestmark = [pytest.mark.integration, pytest.mark.django_db]
def test_gallery_processing_updates_metadata(user_factory, tmp_path, settings, mocker):
settings.MEDIA_ROOT = str(tmp_path)
gallery = Gallery(title="Photo", uploaded_by=user_factory())
gallery._defer_image_processing = True
gallery.image.save("gallery/photo.jpg", ContentFile(b"image data"))
result = mocker.Mock(file_size=10, width=20, height=30)
process = mocker.patch("apps.gallery.tasks.safe_process_public_image", return_value=result)
assert process_uploaded_image.run(gallery.pk) == "Processed image: Photo"
gallery.refresh_from_db()
assert (gallery.file_size, gallery.width, gallery.height) == (10, 20, 30)
process.assert_called_once()
def test_gallery_processing_missing_image_and_id(user_factory):
empty = Gallery.objects.create(title="Empty", uploaded_by=user_factory())
assert process_uploaded_image.run(empty.pk) is None
with pytest.raises(Gallery.DoesNotExist):
process_uploaded_image.run(999999)