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.
This commit is contained in:
41
apps/gallery/tests/unit/test_admin.py
Normal file
41
apps/gallery/tests/unit/test_admin.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from apps.gallery.admin import GalleryAdmin
|
||||
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
|
||||
def test_gallery_admin_metadata_and_previews():
|
||||
admin = GalleryAdmin.__new__(GalleryAdmin)
|
||||
empty = SimpleNamespace(image=None, file_size=0, width=0, height=0)
|
||||
assert admin.image_preview(empty) == "No Image"
|
||||
assert admin.image_preview_large(empty) == "No Image"
|
||||
assert admin.file_size_display(empty) == "Unknown"
|
||||
assert admin.dimensions(empty) == "Unknown"
|
||||
image = SimpleNamespace(image=SimpleNamespace(url="/image.png"), file_size=1048576,
|
||||
file_size_mb=1, width=100, height=80)
|
||||
assert "/image.png" in admin.image_preview(image)
|
||||
assert "/image.png" in admin.image_preview_large(image)
|
||||
assert admin.file_size_display(image) == "1 MB"
|
||||
assert admin.dimensions(image) == "100 × 80"
|
||||
|
||||
|
||||
def test_gallery_admin_bulk_actions(mocker):
|
||||
admin = GalleryAdmin.__new__(GalleryAdmin)
|
||||
message = mocker.patch.object(admin, "message_user")
|
||||
queryset = mocker.Mock()
|
||||
queryset.count.return_value = 2
|
||||
admin.make_public(None, queryset)
|
||||
queryset.update.assert_called_with(is_public=True)
|
||||
admin.make_private(None, queryset)
|
||||
queryset.update.assert_called_with(is_public=False)
|
||||
first = mocker.Mock()
|
||||
second = mocker.Mock()
|
||||
queryset.__iter__ = mocker.Mock(return_value=iter([first, second]))
|
||||
admin.restore_images(None, queryset)
|
||||
first.restore.assert_called_once()
|
||||
second.restore.assert_called_once()
|
||||
assert message.call_count == 3
|
||||
Reference in New Issue
Block a user