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:
43
apps/blog/tests/integration/test_commands.py
Normal file
43
apps/blog/tests/integration/test_commands.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from io import StringIO
|
||||
|
||||
import pytest
|
||||
from django.contrib.auth.models import Group
|
||||
from django.core.management import call_command
|
||||
|
||||
from apps.blog.models import Category, Post, Tag
|
||||
from apps.blog.permissions import BLOG_EDITOR_GROUP, BLOG_SUPERVISOR_GROUP
|
||||
|
||||
|
||||
pytestmark = [pytest.mark.integration, pytest.mark.django_db]
|
||||
|
||||
|
||||
def test_category_and_tag_seed_commands_support_dry_run_and_idempotence():
|
||||
output = StringIO()
|
||||
call_command("seed_blog_categories", dry_run=True, stdout=output)
|
||||
call_command("seed_blog_tags", dry_run=True, stdout=output)
|
||||
assert Category.objects.count() == 0
|
||||
assert Tag.objects.count() == 0
|
||||
call_command("seed_blog_categories", stdout=output)
|
||||
call_command("seed_blog_tags", stdout=output)
|
||||
counts = Category.objects.count(), Tag.objects.count()
|
||||
assert counts[0] > 0 and counts[1] > 0
|
||||
call_command("seed_blog_categories", stdout=output)
|
||||
call_command("seed_blog_tags", stdout=output)
|
||||
assert (Category.objects.count(), Tag.objects.count()) == counts
|
||||
|
||||
|
||||
def test_role_sync_creates_editor_and_supervisor_permissions():
|
||||
call_command("sync_blog_roles", stdout=StringIO())
|
||||
editor = Group.objects.get(name=BLOG_EDITOR_GROUP)
|
||||
supervisor = Group.objects.get(name=BLOG_SUPERVISOR_GROUP)
|
||||
assert editor.permissions.filter(codename="add_post").exists()
|
||||
assert supervisor.permissions.filter(codename="review_blog_post").exists()
|
||||
|
||||
|
||||
def test_mock_seed_creates_posts_and_can_reset(tmp_path, settings, mocker):
|
||||
settings.MEDIA_ROOT = str(tmp_path)
|
||||
mocker.patch("apps.blog.management.commands.seed_blog_mock_data.set_image_field")
|
||||
call_command("seed_blog_mock_data", stdout=StringIO())
|
||||
assert Post.objects.filter(slug__startswith="mock-").count() == 5
|
||||
call_command("seed_blog_mock_data", reset=True, stdout=StringIO())
|
||||
assert Post.objects.filter(slug__startswith="mock-").count() == 5
|
||||
Reference in New Issue
Block a user