from django.test import SimpleTestCase from sms.backends.aliyun_sms import ( get_aliyun_phone_number, get_verification_template_id, ) class AliyunSmsTemplateTest(SimpleTestCase): def test_mainland_phone_uses_domestic_verification_template(self): self.assertEqual( get_verification_template_id('13800138000'), 'SMS_205132276', ) def test_hong_kong_and_macao_phones_use_international_template(self): for phone in ('+85251234567', '+85361234567'): with self.subTest(phone=phone): self.assertEqual( get_verification_template_id(phone), 'SMS_226416620', ) def test_e164_phone_is_converted_to_aliyun_country_code_format(self): cases = { '13800138000': '13800138000', '+85251234567': '85251234567', '+85361234567': '85361234567', } for phone, expected in cases.items(): with self.subTest(phone=phone): self.assertEqual(get_aliyun_phone_number(phone), expected)