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