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,33 @@
from types import SimpleNamespace
import pytest
from django.contrib import admin
from apps.blog.admin import CommentAdmin, PostAdmin
from apps.blog.models import Comment, Post
pytestmark = pytest.mark.unit
def test_blog_admin_preview_shortens_long_comment():
model_admin = CommentAdmin(Comment, admin.site)
assert model_admin.content_preview(SimpleNamespace(content="short")) == "short"
assert model_admin.content_preview(SimpleNamespace(content="x" * 51)) == "x" * 50 + "..."
def test_post_admin_actions_update_status_and_featured_flag(mocker):
model_admin = PostAdmin(Post, admin.site)
mocker.patch.object(model_admin, "message_user")
queryset = mocker.Mock()
queryset.count.return_value = 1
user = SimpleNamespace(id=1)
request = SimpleNamespace(user=user)
model_admin.submit_for_review(request, queryset)
queryset.update.assert_called_with(status="submitted")
model_admin.request_changes(request, queryset)
queryset.update.assert_called_with(status="changes_requested", reviewed_by=user)
model_admin.make_published(request, queryset)
queryset.update.assert_called_with(status="published", published_by=user)
model_admin.make_featured(request, queryset)
queryset.update.assert_called_with(is_featured=True)