mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-05-31 16:16:11 +08:00
test: 添加 ff14 官方公告的测试
This commit is contained in:
parent
45fed0b232
commit
a6a2fdb908
1
.gitignore
vendored
1
.gitignore
vendored
@ -319,3 +319,4 @@ data*/*
|
||||
.env.*
|
||||
.vim/*
|
||||
!dist/.gitkeep
|
||||
.vscode
|
||||
|
1
tests/platforms/static/ff14-newdata-0.json
Normal file
1
tests/platforms/static/ff14-newdata-0.json
Normal file
@ -0,0 +1 @@
|
||||
{"Code":"0","Message":"","PageCount":293,"TotalCount":1465,"RecordCount":5,"Data":[{"Id":336868,"Articletype":3,"ApplicationCode":92,"CategoryCode":5310,"SortIndex":9,"GroupIndex":0,"TitleClass":"","Title":"LIVE番外:第68回制作人来信转播 2月19日上演","Summary":"第68回制作人来信将于2022年2月19日放送,届时FFXIV的制作人兼导演吉田直树将会以「FFXIV的全新挑战 ~面向下一个10年~」为话题为大家介绍今后的更新情报。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336868","PublishDate":"2022/02/15 16:02:21","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16448326143171.jpg"},{"Id":336969,"Articletype":3,"ApplicationCode":92,"CategoryCode":5310,"SortIndex":8,"GroupIndex":0,"TitleClass":"","Title":"群狼盛宴第20赛季对战数据查询开放","Summary":"群狼盛宴第20赛季对战数据查询开放。冒险现在可以在专题页面点击右上角的「对战数据查询」来查询第20赛季的总对战场次和胜利场次数据。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336969","PublishDate":"2022/02/17 15:09:31","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16450708307681.jpg"},{"Id":336870,"Articletype":3,"ApplicationCode":92,"CategoryCode":5310,"SortIndex":7,"GroupIndex":0,"TitleClass":"","Title":"最终幻想XIV 银质坠饰 <友谊永存>预售开启!","Summary":"最终幻想XIV 银质坠饰 <友谊永存>现已开启预售!","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336870","PublishDate":"2022/02/15 14:11:09","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16448345978202.jpg"},{"Id":336869,"Articletype":3,"ApplicationCode":92,"CategoryCode":5312,"SortIndex":6,"GroupIndex":0,"TitleClass":"","Title":"2月22日「太阳海岸」、「伊修加德」服务器临时维护公告","Summary":"我们将于2月22日14:00-16:00对豆豆柴区进行临时维护。维护结束后将开启「太阳海岸」、「伊修加德」服务器个人及部队房屋购买功能。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336869","PublishDate":"2022/02/15 16:17:13","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16448330187049.jpg"},{"Id":336978,"Articletype":3,"ApplicationCode":92,"CategoryCode":5312,"SortIndex":5,"GroupIndex":0,"TitleClass":"","Title":"《最终幻想14》2月17日违规账号处罚公告","Summary":"为了更好地维护游戏内的游戏秩序,保障各位冒险者良好公正的游戏体验,近期我们对游戏中违反了游戏规定的账号进行了查处,封号名单已更新至违规处理平台中。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336978","PublishDate":"2022/02/17 15:38:20","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16450834782144.jpg"}]}
|
1
tests/platforms/static/ff14-newdata-1.json
Normal file
1
tests/platforms/static/ff14-newdata-1.json
Normal file
@ -0,0 +1 @@
|
||||
{"Code":"0","Message":"","PageCount":293,"TotalCount":1465,"RecordCount":5,"Data":[{"Id":336868,"Articletype":3,"ApplicationCode":92,"CategoryCode":5310,"SortIndex":9,"GroupIndex":0,"TitleClass":"","Title":"LIVE番外:第68回制作人来信转播 2月19日上演","Summary":"第68回制作人来信将于2022年2月19日放送,届时FFXIV的制作人兼导演吉田直树将会以「FFXIV的全新挑战 ~面向下一个10年~」为话题为大家介绍今后的更新情报。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336868","PublishDate":"2022/02/15 16:02:21","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16448326143171.jpg"},{"Id":336969,"Articletype":3,"ApplicationCode":92,"CategoryCode":5310,"SortIndex":8,"GroupIndex":0,"TitleClass":"","Title":"群狼盛宴第20赛季对战数据查询开放","Summary":"群狼盛宴第20赛季对战数据查询开放。冒险现在可以在专题页面点击右上角的「对战数据查询」来查询第20赛季的总对战场次和胜利场次数据。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336969","PublishDate":"2022/02/17 15:09:31","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16450708307681.jpg"},{"Id":336870,"Articletype":3,"ApplicationCode":92,"CategoryCode":5310,"SortIndex":7,"GroupIndex":0,"TitleClass":"","Title":"最终幻想XIV 银质坠饰 <友谊永存>预售开启!","Summary":"最终幻想XIV 银质坠饰 <友谊永存>现已开启预售!","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336870","PublishDate":"2022/02/18 14:11:09","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16448345978202.jpg"},{"Id":336869,"Articletype":3,"ApplicationCode":92,"CategoryCode":5312,"SortIndex":6,"GroupIndex":0,"TitleClass":"","Title":"2月22日「太阳海岸」、「伊修加德」服务器临时维护公告","Summary":"我们将于2月22日14:00-16:00对豆豆柴区进行临时维护。维护结束后将开启「太阳海岸」、「伊修加德」服务器个人及部队房屋购买功能。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336869","PublishDate":"2022/02/15 16:17:13","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16448330187049.jpg"},{"Id":336978,"Articletype":3,"ApplicationCode":92,"CategoryCode":5312,"SortIndex":5,"GroupIndex":0,"TitleClass":"","Title":"《最终幻想14》2月17日违规账号处罚公告","Summary":"为了更好地维护游戏内的游戏秩序,保障各位冒险者良好公正的游戏体验,近期我们对游戏中违反了游戏规定的账号进行了查处,封号名单已更新至违规处理平台中。","Author":"https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336978","PublishDate":"2022/02/17 15:38:20","OutLink":"","HomeImagePath":"https://fu5.web.sdo.com/10036/202202/16450834782144.jpg"}]}
|
46
tests/platforms/test_ff14.py
Normal file
46
tests/platforms/test_ff14.py
Normal file
@ -0,0 +1,46 @@
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import Response
|
||||
from nonebug.app import App
|
||||
|
||||
from .utils import get_json
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ff14(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
return platform_manager["ff14"]
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def ff14_newdata_json_0():
|
||||
return get_json("ff14-newdata-0.json")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def ff14_newdata_json_1():
|
||||
return get_json("ff14-newdata-1.json")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_fetch_new(
|
||||
ff14, dummy_user_subinfo, ff14_newdata_json_0, ff14_newdata_json_1
|
||||
):
|
||||
newdata = respx.get(
|
||||
"https://ff.web.sdo.com/inc/newdata.ashx?url=List?gameCode=ff&category=5309,5310,5311,5312,5313&pageIndex=0&pageSize=5"
|
||||
)
|
||||
newdata.mock(return_value=Response(200, json=ff14_newdata_json_0))
|
||||
target = ""
|
||||
res = await ff14.fetch_new_post(target, [dummy_user_subinfo])
|
||||
assert newdata.called
|
||||
assert len(res) == 0
|
||||
newdata.mock(return_value=Response(200, json=ff14_newdata_json_1))
|
||||
res = await ff14.fetch_new_post(target, [dummy_user_subinfo])
|
||||
assert newdata.called
|
||||
post = res[0][1][0]
|
||||
assert post.target_type == "ff14"
|
||||
assert post.text == "最终幻想XIV 银质坠饰 <友谊永存>预售开启!\n最终幻想XIV 银质坠饰 <友谊永存>现已开启预售!"
|
||||
assert post.url == "https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336870"
|
||||
assert post.target_name == "最终幻想XIV官方公告"
|
@ -5,12 +5,12 @@ path = Path(__file__).parent / "static"
|
||||
|
||||
|
||||
def get_json(file_name: str):
|
||||
with open(path / file_name, "r") as f:
|
||||
with open(path / file_name, "r", encoding="utf8") as f:
|
||||
file_text = f.read()
|
||||
return json.loads(file_text)
|
||||
|
||||
|
||||
def get_file(file_name: str):
|
||||
with open(path / file_name, "r") as f:
|
||||
with open(path / file_name, "r", encoding="utf8") as f:
|
||||
file_text = f.read()
|
||||
return file_text
|
||||
|
Loading…
x
Reference in New Issue
Block a user