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,27 @@
import pytest
from apps.users.tasks import send_critical_sms
pytestmark = pytest.mark.unit
def test_sms_skips_when_credentials_are_missing(settings, mocker):
settings.SMS_APIKEY = ""
settings.SMS_AUTH_OTP_TEMPLATE_ID = ""
post = mocker.patch("apps.users.tasks.requests.post")
result = send_critical_sms.run("09190000001", "auth_register_otp", "12345")
assert result["sent"] is False
post.assert_not_called()
def test_sms_uses_otp_template_and_message_template(settings, mocker):
settings.SMS_APIKEY = "test-key"
settings.SMS_AUTH_OTP_TEMPLATE_ID = "12"
settings.SMS_EVENT_CANCELLATION_TEMPLATE_ID = "13"
post = mocker.patch("apps.users.tasks.requests.post")
assert send_critical_sms.run("09190000001", "auth_register_otp", "12345")["sent"]
assert post.call_args.kwargs["json"]["parameters"] == [{"name": "OTP", "value": "12345"}]
assert send_critical_sms.run("09190000001", "event_cancellation", "Cancelled")["sent"]
assert post.call_args.kwargs["json"]["parameters"] == [{"name": "MESSAGE", "value": "Cancelled"}]
assert post.call_args.kwargs["json"]["templateId"] == 13