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:
27
apps/users/tests/unit/test_sms_tasks.py
Normal file
27
apps/users/tests/unit/test_sms_tasks.py
Normal 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
|
||||
Reference in New Issue
Block a user