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,40 @@
import pytest
pytestmark = [pytest.mark.integration, pytest.mark.django_db]
def test_analytics_requires_staff_and_reports_current_users(client, user_factory, auth_headers):
member = user_factory()
staff = user_factory(is_staff=True)
path = "/api/analytics/admin/users"
assert client.get(path).status_code == 401
assert client.get(path, **auth_headers(member)).status_code == 403
response = client.get(path, **auth_headers(staff))
assert response.status_code == 200
assert response.json()["summary"]["total_users"] == 2
def test_staff_analytics_endpoints_return_empty_aggregate_shapes(client, user_factory, event_factory, auth_headers):
staff = user_factory(is_staff=True)
event = event_factory()
headers = auth_headers(staff)
options = client.get("/api/analytics/admin/events/options", {"search": "Test", "limit": 1}, **headers)
assert options.status_code == 200
assert options.json()["count"] == 1
assert options.json()["results"][0]["value"] == str(event.pk)
for path in ("/api/analytics/admin/events", "/api/analytics/admin/blog", "/api/analytics/admin/dashboard"):
response = client.get(path, **headers)
assert response.status_code == 200, (path, response.content)
assert response.json()
def test_analytics_rejects_invalid_date_range(client, user_factory, auth_headers):
staff = user_factory(is_staff=True)
response = client.get(
"/api/analytics/admin/users",
{"date_from": "2026-12-31", "date_to": "2026-01-01"},
**auth_headers(staff),
)
assert response.status_code == 400