mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-28 16:20:56 +08:00
✨ 添加仓库目录多获取渠道
This commit is contained in:
@@ -2,6 +2,7 @@ from typing import cast
|
||||
from pathlib import Path
|
||||
from collections.abc import Callable
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
from respx import MockRouter
|
||||
from pytest_mock import MockerFixture
|
||||
@@ -14,7 +15,9 @@ from tests.config import BotId, UserId, GroupId, MessageId
|
||||
from tests.builtin_plugins.plugin_store.utils import init_mocked_api
|
||||
|
||||
|
||||
@pytest.mark.parametrize("package_api", ["jsd", "gh"])
|
||||
async def test_add_plugin_basic(
|
||||
package_api: str,
|
||||
app: App,
|
||||
mocker: MockerFixture,
|
||||
mocked_api: MockRouter,
|
||||
@@ -32,6 +35,11 @@ async def test_add_plugin_basic(
|
||||
new=tmp_path / "zhenxun",
|
||||
)
|
||||
|
||||
if package_api != "jsd":
|
||||
mocked_api["zhenxun_bot_plugins_metadata"].respond(404)
|
||||
if package_api != "gh":
|
||||
mocked_api["zhenxun_bot_plugins_tree"].respond(404)
|
||||
|
||||
plugin_id = 1
|
||||
|
||||
async with app.test_matcher(_matcher) as ctx:
|
||||
@@ -61,12 +69,13 @@ async def test_add_plugin_basic(
|
||||
)
|
||||
assert mocked_api["basic_plugins"].called
|
||||
assert mocked_api["extra_plugins"].called
|
||||
assert mocked_api["zhenxun_bot_plugins_metadata"].called
|
||||
assert mocked_api["search_image_plugin_file_init"].called
|
||||
assert (mock_base_path / "plugins" / "search_image" / "__init__.py").is_file()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("package_api", ["jsd", "gh"])
|
||||
async def test_add_plugin_basic_is_not_dir(
|
||||
package_api: str,
|
||||
app: App,
|
||||
mocker: MockerFixture,
|
||||
mocked_api: MockRouter,
|
||||
@@ -84,6 +93,11 @@ async def test_add_plugin_basic_is_not_dir(
|
||||
new=tmp_path / "zhenxun",
|
||||
)
|
||||
|
||||
if package_api != "jsd":
|
||||
mocked_api["zhenxun_bot_plugins_metadata"].respond(404)
|
||||
if package_api != "gh":
|
||||
mocked_api["zhenxun_bot_plugins_tree"].respond(404)
|
||||
|
||||
plugin_id = 0
|
||||
|
||||
async with app.test_matcher(_matcher) as ctx:
|
||||
@@ -113,12 +127,13 @@ async def test_add_plugin_basic_is_not_dir(
|
||||
)
|
||||
assert mocked_api["basic_plugins"].called
|
||||
assert mocked_api["extra_plugins"].called
|
||||
assert mocked_api["zhenxun_bot_plugins_metadata"].called
|
||||
assert mocked_api["jitang_plugin_file"].called
|
||||
assert (mock_base_path / "plugins" / "alapi" / "jitang.py").is_file()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("package_api", ["jsd", "gh"])
|
||||
async def test_add_plugin_extra(
|
||||
package_api: str,
|
||||
app: App,
|
||||
mocker: MockerFixture,
|
||||
mocked_api: MockRouter,
|
||||
@@ -136,6 +151,11 @@ async def test_add_plugin_extra(
|
||||
new=tmp_path / "zhenxun",
|
||||
)
|
||||
|
||||
if package_api != "jsd":
|
||||
mocked_api["zhenxun_github_sub_metadata"].respond(404)
|
||||
if package_api != "gh":
|
||||
mocked_api["zhenxun_github_sub_tree"].respond(404)
|
||||
|
||||
plugin_id = 3
|
||||
|
||||
async with app.test_matcher(_matcher) as ctx:
|
||||
@@ -165,7 +185,6 @@ async def test_add_plugin_extra(
|
||||
)
|
||||
assert mocked_api["basic_plugins"].called
|
||||
assert mocked_api["extra_plugins"].called
|
||||
assert mocked_api["github_sub_plugin_metadata"].called
|
||||
assert mocked_api["github_sub_plugin_file_init"].called
|
||||
assert (mock_base_path / "plugins" / "github_sub" / "__init__.py").is_file()
|
||||
|
||||
|
||||
@@ -17,14 +17,24 @@ def get_content_bytes(file: str) -> bytes:
|
||||
|
||||
|
||||
def init_mocked_api(mocked_api: MockRouter) -> None:
|
||||
mocked_api.get(
|
||||
"https://data.jsdelivr.com/v1/packages/gh/xuanerwa/zhenxun_github_sub@main",
|
||||
name="github_sub_plugin_metadata",
|
||||
).respond(json=get_response_json("github_sub_plugin_metadata.json"))
|
||||
mocked_api.get(
|
||||
"https://data.jsdelivr.com/v1/packages/gh/zhenxun-org/zhenxun_bot_plugins@main",
|
||||
name="zhenxun_bot_plugins_metadata",
|
||||
).respond(json=get_response_json("zhenxun_bot_plugins_metadata.json"))
|
||||
mocked_api.get(
|
||||
"https://data.jsdelivr.com/v1/packages/gh/xuanerwa/zhenxun_github_sub@main",
|
||||
name="zhenxun_github_sub_metadata",
|
||||
).respond(json=get_response_json("zhenxun_github_sub_metadata.json"))
|
||||
|
||||
mocked_api.get(
|
||||
"https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/trees/main?recursive=1",
|
||||
name="zhenxun_bot_plugins_tree",
|
||||
).respond(json=get_response_json("zhenxun_bot_plugins_tree.json"))
|
||||
mocked_api.get(
|
||||
"https://api.github.com/repos/xuanerwa/zhenxun_github_sub/git/trees/main?recursive=1",
|
||||
name="zhenxun_github_sub_tree",
|
||||
).respond(json=get_response_json("zhenxun_github_sub_tree.json"))
|
||||
|
||||
mocked_api.head(
|
||||
"https://raw.githubusercontent.com/zhenxun-org/zhenxun_bot_plugins/main/plugins.json",
|
||||
name="head_basic_plugins",
|
||||
|
||||
Reference in New Issue
Block a user