mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
* 🐛 调整ruff的pytest警告 * 🐛 调整导入关系警告 * 🐛 删除奇怪无用的赋值和取值逻辑 * ✅ 不同测试部分所用变量应加以区分 * 🐛 subs_io model添加默认值 * 🐛 修完所有的 ruff PT001 警告 * 🔧 按ruff建议修改ruff配置 warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `pyproject.toml`: - 'ignore' -> 'lint.ignore' - 'select' -> 'lint.select' --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import respx
|
|
import pytest
|
|
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
|
|
from nonebot_bison.utils import ProcessContext, DefaultClientManager
|
|
|
|
return platform_manager["ff14"](ProcessContext(DefaultClientManager()))
|
|
|
|
|
|
@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):
|
|
from nonebot_bison.post import Post
|
|
from nonebot_bison.types import Target, SubUnit
|
|
|
|
newdata = respx.get(
|
|
"https://cqnews.web.sdo.com/api/news/newsList?gameCode=ff&CategoryCode=5309,5310,5311,5312,5313&pageIndex=0&pageSize=5"
|
|
)
|
|
newdata.mock(return_value=Response(200, json=ff14_newdata_json_0))
|
|
target = Target("")
|
|
res = await ff14.fetch_new_post(SubUnit(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(SubUnit(target, [dummy_user_subinfo]))
|
|
assert newdata.called
|
|
post: Post = res[0][1][0]
|
|
assert post.platform.name == "最终幻想XIV官方公告"
|
|
assert post.title == "最终幻想XIV 银质坠饰 <友谊永存>预售开启!"
|
|
assert post.content == "最终幻想XIV 银质坠饰 <友谊永存>现已开启预售!"
|
|
assert post.url == "https://ff.web.sdo.com/web8/index.html#/newstab/newscont/336870"
|
|
assert post.nickname == "最终幻想XIV官方公告"
|