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:
2026-09-26 16:50:29 +03:30
parent 3ec28638d1
commit ff99130938
76 changed files with 3271 additions and 1357 deletions

View File

@@ -0,0 +1,35 @@
from types import SimpleNamespace
import pytest
from django.contrib import admin
from apps.events.models import Event
from core.admin import BaseModelAdmin, SoftDeleteListFilter
pytestmark = pytest.mark.unit
def test_soft_delete_filter_selects_active_deleted_or_all(mocker):
filt = SoftDeleteListFilter(SimpleNamespace(GET={}), {}, Event, admin.site)
queryset = mocker.Mock()
queryset.model = Event
mocker.patch.object(filt, "value", return_value="0")
filt.queryset(None, queryset)
queryset.filter.assert_called_with(is_deleted=False)
filt.value.return_value = "1"
assert filt.queryset(None, queryset).model == Event
filt.value.return_value = None
assert filt.queryset(None, queryset) is queryset
def test_admin_delete_permission_and_restore_action(mocker):
model_admin = BaseModelAdmin(Event, admin.site)
assert not model_admin.has_delete_permission(SimpleNamespace(user=SimpleNamespace(is_superuser=False)))
assert model_admin.has_delete_permission(SimpleNamespace(user=SimpleNamespace(is_superuser=True)))
mocker.patch.object(model_admin, "message_user")
deleted = SimpleNamespace(is_deleted=True, restore=mocker.Mock())
active = SimpleNamespace(is_deleted=False, restore=mocker.Mock())
model_admin.restore_selected(SimpleNamespace(), [deleted, active])
deleted.restore.assert_called_once()
active.restore.assert_not_called()