适配新告警短信模板

This commit is contained in:
stu2not
2026-07-24 15:06:11 +08:00
parent e44efaed73
commit e9f89841a0
2 changed files with 38 additions and 4 deletions

View File

@@ -42,8 +42,8 @@ def configure_enabled_sms(monkeypatch):
monkeypatch.setattr("banban.service.sms_notification.settings.aliyun_sms_access_key_id", "access-key-id")
monkeypatch.setattr("banban.service.sms_notification.settings.aliyun_sms_access_key_secret", "access-key-secret")
monkeypatch.setattr("banban.service.sms_notification.settings.aliyun_sms_sign_name", "短信签名")
monkeypatch.setattr("banban.service.sms_notification.settings.aliyun_sms_template_code", "SMS_507185027")
monkeypatch.setattr("banban.service.sms_notification.settings.aliyun_sms_alarm_template_code", "")
monkeypatch.setattr("banban.service.sms_notification.settings.aliyun_sms_template_code", "")
monkeypatch.setattr("banban.service.sms_notification.settings.aliyun_sms_alarm_template_code", "SMS_509735147")
monkeypatch.setattr("banban.service.sms_notification.settings.aliyun_sms_leave_message_template_code", "")
@@ -77,7 +77,7 @@ async def test_notify_alarm_sends_to_unique_family_phone_numbers(monkeypatch):
)
assert [item["phone_number"] for item in sent] == ["13800138000", "13900139000"]
assert all(item["template_code"] == "SMS_507185027" for item in sent)
assert all(item["template_code"] == "SMS_509735147" for item in sent)
assert sent[0]["template_params"]["conference"] == "孩子"
assert sent[0]["template_params"]["address"] == "杭州市"
@@ -115,6 +115,27 @@ def test_sms_address_sanitizer_falls_back_for_coordinates():
assert service._sanitize_sms_address("30.245,120.215") == "请打开小程序查看"
@pytest.mark.asyncio
async def test_notify_alarm_skips_when_child_name_is_missing(monkeypatch):
configure_enabled_sms(monkeypatch)
service = SmsNotificationService()
sent = []
async def fake_send_sms(**kwargs):
sent.append(kwargs)
return {"ok": True, "code": "OK", "message": "OK", "request_id": "request-id"}
monkeypatch.setattr(service, "_send_sms", fake_send_sms)
await service.notify_alarm(
device_id="TalkingQ_XQSN00001005",
child_name=" ",
address="杭州市",
)
assert sent == []
@pytest.mark.asyncio
async def test_notify_alarm_dedupes_same_device_and_phone(monkeypatch):
configure_enabled_sms(monkeypatch)