import json
from datetime import datetime
from pathlib import Path
from typing import Any
import httpx
import pytest
import respx
from nonebot import get_adapter
from nonebot.adapters.onebot.v11 import Adapter, Bot, Message, MessageSegment
from nonebug import App
from pytest_mock import MockerFixture
from respx import MockRouter
from sqlalchemy import delete
from tests.fake import fake_group_message_event_v11
@pytest.fixture
async def app(app: App):
yield app
# 清理数据库
from nonebot_plugin_orm import get_session
from src.plugins.ff14.plugins.ff14_fflogs.data import FFLOGS_DATA
from src.plugins.ff14.plugins.ff14_fflogs.models import User
async with get_session() as session, session.begin():
await session.execute(delete(User))
# 清除缓存的数据
FFLOGS_DATA._data = None
@pytest.fixture
async def fflogs_data(app: App) -> dict[str, Any]:
path = Path(__file__).parent / "fflogs_data.json"
with path.open("r", encoding="utf-8") as f:
data = json.load(f)
return data
@pytest.fixture
async def fflogs_character_rankings(app: App) -> dict[str, Any]:
path = Path(__file__).parent / "fflogs_character_rankings.json"
with path.open("r", encoding="utf-8") as f:
data = json.load(f)
return data
@pytest.fixture
async def fflogs_job_rankings(app: App) -> dict[str, Any]:
path = Path(__file__).parent / "fflogs_job_rankings.json"
with path.open("r", encoding="utf-8") as f:
data = json.load(f)
return data
@pytest.fixture
async def fflogs_job_rankings_empty(app: App) -> dict[str, Any]:
path = Path(__file__).parent / "fflogs_job_rankings_empty.json"
with path.open("r", encoding="utf-8") as f:
data = json.load(f)
return data
async def test_dps_help(app: App, mocker: MockerFixture):
"""测试 FFLOGS,返回帮助的情况"""
from src.plugins.ff14.plugins.ff14_fflogs import (
__plugin_meta__,
fflogs_cmd,
plugin_config,
)
help_msg = f"{__plugin_meta__.name}\n\n{__plugin_meta__.usage}"
mocker.patch.object(plugin_config, "fflogs_token", "test")
async with app.test_matcher(fflogs_cmd) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event_v11(message=Message("/dps"), user_id=10000)
ctx.receive_event(bot, event)
ctx.should_call_send(event, help_msg, True)
ctx.should_finished(fflogs_cmd)
async with app.test_matcher(fflogs_cmd) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event_v11(message=Message("/dps "), user_id=10000)
ctx.receive_event(bot, event)
ctx.should_call_send(event, help_msg, True)
ctx.should_finished(fflogs_cmd)
async with app.test_matcher(fflogs_cmd) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event_v11(
message=Message("/dps test"), user_id=10000
)
ctx.receive_event(bot, event)
ctx.should_call_send(event, help_msg, True)
ctx.should_finished(fflogs_cmd)
async def test_dps_missing_token(app: App):
"""测试 FFLOGS,缺少 Token 的情况"""
from src.plugins.ff14.plugins.ff14_fflogs import fflogs_cmd
async with app.test_matcher(fflogs_cmd) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event_v11(message=Message("/dps me"))
ctx.receive_event(bot, event)
ctx.should_call_send(
event,
"对不起,Token 未设置,无法查询数据。\n请先在 .env 中配置好 Token 后再尝试查询数据。",
True,
)
ctx.should_finished(fflogs_cmd)
async def test_dps_cache(app: App, mocker: MockerFixture):
"""测试 FFLOGS,设置缓存的情况"""
from src.plugins.ff14.plugins.ff14_fflogs import fflogs_cmd, plugin_config
mocker.patch.object(plugin_config, "fflogs_token", "test")
async with app.test_matcher(fflogs_cmd) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event_v11(message=Message("/dps cache list"))
ctx.receive_event(bot, event)
ctx.should_call_send(event, "当前没有缓存副本。", True)
ctx.should_finished(fflogs_cmd)
async with app.test_matcher(fflogs_cmd) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event_v11(message=Message("/dps cache add p1s"))
ctx.receive_event(bot, event)
ctx.should_call_send(event, "已添加副本 p1s。", True)
ctx.should_finished(fflogs_cmd)
async with app.test_matcher(fflogs_cmd) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event_v11(message=Message("/dps cache list"))
ctx.receive_event(bot, event)
ctx.should_call_send(event, "当前缓存的副本有:\np1s", True)
ctx.should_finished(fflogs_cmd)
async with app.test_matcher(fflogs_cmd) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event_v11(message=Message("/dps cache del p2s"))
ctx.receive_event(bot, event)
ctx.should_call_send(event, "没有缓存 p2s,无法删除。", True)
ctx.should_finished(fflogs_cmd)
async with app.test_matcher(fflogs_cmd) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event_v11(message=Message("/dps cache del p1s"))
ctx.receive_event(bot, event)
ctx.should_call_send(event, "已删除副本 p1s。", True)
ctx.should_finished(fflogs_cmd)
async with app.test_matcher(fflogs_cmd) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event_v11(message=Message("/dps cache list"))
ctx.receive_event(bot, event)
ctx.should_call_send(event, "当前没有缓存副本。", True)
ctx.should_finished(fflogs_cmd)
async def test_dps_permission(app: App, mocker: MockerFixture):
"""测试 FFLOGS,没有权限情况"""
from src.plugins.ff14.plugins.ff14_fflogs import fflogs_cmd, plugin_config
mocker.patch.object(plugin_config, "fflogs_token", "test")
async with app.test_matcher(fflogs_cmd) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event_v11(
message=Message("/dps cache del p2s"), user_id=10000
)
ctx.receive_event(bot, event)
ctx.should_call_send(event, "抱歉,你没有权限设置缓存。", True)
ctx.should_finished(fflogs_cmd)
async def test_dps_bind(app: App, mocker: MockerFixture):
"""测试绑定角色"""
from src.plugins.ff14.plugins.ff14_fflogs import fflogs_cmd, plugin_config
mocker.patch.object(plugin_config, "fflogs_token", "test")
# 查询自己的绑定角色
async with app.test_matcher(fflogs_cmd) as ctx:
adapter = get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, adapter=adapter)
event = fake_group_message_event_v11(message=Message("/dps me"))
ctx.receive_event(bot, event)
ctx.should_call_send(
event,
MessageSegment.at(10)
+ "抱歉,你没有绑定最终幻想14的角色。\n请使用\n/dps me 角色名 服务器名\n绑定自己的角色。",
True,
)
ctx.should_finished(fflogs_cmd)
# 查询别人的绑定角色
async with app.test_matcher(fflogs_cmd) as ctx:
adapter = get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, adapter=adapter)
event = fake_group_message_event_v11(
message=Message("/dps" + MessageSegment.at(10))
)
ctx.receive_event(bot, event)
ctx.should_call_send(
event,
MessageSegment.at(10) + "抱歉,该用户没有绑定最终幻想14的角色。",
True,
)
ctx.should_finished(fflogs_cmd)
# 绑定角色
async with app.test_matcher(fflogs_cmd) as ctx:
adapter =
.whl
- 粉丝: 3960
- 资源: 4908
最新资源
- gps追踪器源码和pcb资料,量产资料,可以直接生产用
- flash spi w25q128 w25q64 w25q32 w25q16 verilog fpga程序代码 fpga w25q128 64 32 16 verilog代码 资料包清单: 1.w2
- 全国计算机等级考试《三级数据库技术》复习核心内容讲解与备考指导
- 弯管机程序使用三菱FX系列 PLC和昆仑通态触摸屏,也可以用三菱F940系列触摸屏
- 信捷PLC上位机源代码例子,modbusTCP通信,通俗易懂,C#源代码
- 关于粒子滤波在电力负荷预测中的应用 python源代码,代码按照高水平文章复现,有详细说明,保证正确 在线预测电力负荷,在贝叶斯框架的动态模型 提供了顺序蒙特卡罗方法的回顾,并提供了所谓的粒子过滤
- 能源价格风险管理matlab源代码,代码按照高水平文章复现,保证正确 电力价格的波动性远远大于其他通常以极端波动著称的价格 由于电力不能经济地储存,终端用户的需求在很大程度上取决于天气,而电网的可靠
- 电力市场中生产者的战略招标:一种凸松弛方法matlab 源代码,代码按照高水平文章复现,保证正确 电力市场中的战略投标问题在电力系统中得到了广泛研究,通常是通过制定难以解决的复杂的双层优化问题来进行的
- FMC ADC12D2000RF 模块,忍痛出射频直接采集FMC ADC模块,模块基于Ti公司高端ADC12D2000RF芯片,芯片为单通道4GSPS,双通道2GSPS,12bit分辨率,这款芯片国
- 西门子200smart与施耐德ATV变频器modbus通讯 西门子s7-200smart与施耐德ATV12变频器通讯,可靠稳定,同时解决施耐德ATV变频器断电重启后,自准备工作,无需人为准备 器件:
- 2025/1/15 自用
- siddhi 的核心jar
- 上市公司的高压软启动控制源码,源码,需要的联系,平台TI,厂家见图,也有低压软起动的方案,
- 基于Atrix7 Kitex7 Vertex7系列FPGA的DDR3内存驱动器代码(Verilog语言),把2GB的内存做成一个可以同时读写的大型FIFO 有代码,有测试文档
- 圈乘问题求解问题pdf
- 关于配电网调压通信的需求VoltVAR反馈控制法则的比较完全分散与网络化策略 matlab源代码 代码按照高水平文章复现,保证正确 我们首先介绍了一类非常普遍的纯局部控制策略,并通过一个反例演示
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈