feat(qqpush): 私聊推送接口与抽卡API token读取兼容
This commit is contained in:
@@ -115,6 +115,59 @@ def success_data(data):
|
||||
return {"code": 200, "message": "", "data": data}
|
||||
|
||||
|
||||
def test_config_reads_token_from_nonebot_driver_config(monkeypatch):
|
||||
"""NoneBot 只把 .env 注入 driver.config 时,抽卡 API token 不能为空。"""
|
||||
|
||||
for key in (
|
||||
"DANDING_BOT_TOKEN",
|
||||
"ONMYOJI_BOT_TOKEN",
|
||||
"DANDING_API_TOKEN",
|
||||
"BOT_TOKEN",
|
||||
"WEB_ADMIN_TOKEN",
|
||||
"DANDING_BOT_USER",
|
||||
"DANDING_GACHA_API_HOST",
|
||||
):
|
||||
monkeypatch.delenv(key, raising=False)
|
||||
|
||||
class FakeDriver:
|
||||
config = types.SimpleNamespace(
|
||||
danding_api_token="driver-api-token",
|
||||
web_admin_token="driver-admin-token",
|
||||
danding_bot_user="driver-user",
|
||||
danding_gacha_api_host="http://driver.test/bot/gacha/",
|
||||
)
|
||||
|
||||
fake_nonebot = types.ModuleType("nonebot")
|
||||
fake_nonebot.get_driver = lambda: FakeDriver()
|
||||
monkeypatch.setitem(sys.modules, "nonebot", fake_nonebot)
|
||||
|
||||
test_config = Config()
|
||||
|
||||
assert test_config.BOT_TOKEN == "driver-api-token"
|
||||
assert test_config.WEB_ADMIN_TOKEN == "driver-admin-token"
|
||||
assert test_config.BOT_USER_ID == "driver-user"
|
||||
assert test_config.GACHA_API_HOST == "http://driver.test/bot/gacha"
|
||||
|
||||
|
||||
def test_config_keeps_explicit_bot_token_priority(monkeypatch):
|
||||
"""显式抽卡 token 优先于兼容旧 token,避免多 token 配置时误读。"""
|
||||
|
||||
for key in ("DANDING_BOT_TOKEN", "ONMYOJI_BOT_TOKEN", "DANDING_API_TOKEN", "BOT_TOKEN"):
|
||||
monkeypatch.delenv(key, raising=False)
|
||||
|
||||
class FakeDriver:
|
||||
config = types.SimpleNamespace(
|
||||
danding_bot_token="driver-bot-token",
|
||||
danding_api_token="driver-api-token",
|
||||
)
|
||||
|
||||
fake_nonebot = types.ModuleType("nonebot")
|
||||
fake_nonebot.get_driver = lambda: FakeDriver()
|
||||
monkeypatch.setitem(sys.modules, "nonebot", fake_nonebot)
|
||||
|
||||
assert Config().BOT_TOKEN == "driver-bot-token"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_shikigami_cache_and_draw_send_auth_to_xapi(fake_aiohttp):
|
||||
responses, calls = fake_aiohttp
|
||||
|
||||
Reference in New Issue
Block a user