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.
41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
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
|