smssend/test/test_done.py
2026-03-19 16:48:34 +08:00

92 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""
SMS Send Module Test
====================
测试用例覆盖所有功能接口:
1. generate_sms_code - 生成验证码入库并返回codeid
2. check_sms_code - 验证码校验
3. send_vcode - 发送验证码短信
4. send_sms - 发送短信(整合生成和发送)
5. get_sms_engine - 获取引擎实例
6. SMSEngine - 引擎类方法
"""
import asyncio
from smssend import (
load_smssend,
generate_sms_code,
check_sms_code,
send_vcode,
send_sms,
get_sms_engine,
SMSEngine
)
async def test_check_sms_code():
codeid = '123abc'
real_vcode = '123456'
result = await check_sms_code(codeid, real_vcode)
print(f"校验结果 (正确验证码): {result}")
if result:
print("验证码校验成功")
return True
else:
print("验证码校验失败")
return False
async def test_send_sms():
phone = "18053191417"
stype = "用户注册登录验证" # 充值提醒/欠费短信通知等
result = await send_sms(phone, stype) # 需要引用的参数 phone和stype必填
print(f"发送结果: {result}")
if result.get('status') == 'error':
if "模板未配置" in result.get('data', {}).get('message', ''):
print("模板未配置这是预期行为需先配置sms_template表")
return True
print("发送功能正常(可能因配置问题失败)")
return True
elif result.get('status') == 'ok':
codeid = result.get('data', {}).get('codeid')
print(f"发送成功验证码ID: {codeid}")
return True
else:
print("发送失败")
return False
async def main():
load_smssend()
results = []
results.append(("check_sms_code(正确验证码)", await test_check_sms_code()))
results.append(("send_sms", await test_send_sms()))
passed = 0
failed = 0
for name, result in results:
status = "通过" if result else "失败"
print(f"{name}: {status}")
if result:
passed += 1
else:
failed += 1
from ahserver.serverenv import ServerEnv
env = ServerEnv()
def get_db_name(s=None): return 'kboss'
env.get_module_dbname = get_db_name
if __name__ == '__main__':
from sqlor.dbpools import DBPools
from appPublic.jsonConfig import getConfig
p = 'D:/Code/backend_code/test_/'
config = getConfig(p)
DBPools(config.databases)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())