mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-06 20:16:47 +00:00
👷 Test: 移除 httpbin 并整理测试 (#2110)
This commit is contained in:
@ -3,25 +3,16 @@ from nonebug import App
|
||||
|
||||
from nonebot.permission import User
|
||||
from nonebot.matcher import Matcher, matchers
|
||||
from utils import FakeMessage, make_fake_event
|
||||
from nonebot.message import check_and_run_matcher
|
||||
from utils import make_fake_event, make_fake_message
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_matcher(app: App):
|
||||
from plugins.matcher.matcher_process import (
|
||||
test_got,
|
||||
test_handle,
|
||||
test_preset,
|
||||
test_combine,
|
||||
test_receive,
|
||||
test_overload,
|
||||
)
|
||||
async def test_matcher_handle(app: App):
|
||||
from plugins.matcher.matcher_process import test_handle
|
||||
|
||||
message = make_fake_message()("text")
|
||||
message = FakeMessage("text")
|
||||
event = make_fake_event(_message=message)()
|
||||
message_next = make_fake_message()("text_next")
|
||||
event_next = make_fake_event(_message=message_next)()
|
||||
|
||||
assert len(test_handle.handlers) == 1
|
||||
async with app.test_matcher(test_handle) as ctx:
|
||||
@ -30,6 +21,16 @@ async def test_matcher(app: App):
|
||||
ctx.should_call_send(event, "send", "result", at_sender=True)
|
||||
ctx.should_finished()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_matcher_got(app: App):
|
||||
from plugins.matcher.matcher_process import test_got
|
||||
|
||||
message = FakeMessage("text")
|
||||
event = make_fake_event(_message=message)()
|
||||
message_next = FakeMessage("text_next")
|
||||
event_next = make_fake_event(_message=message_next)()
|
||||
|
||||
assert len(test_got.handlers) == 1
|
||||
async with app.test_matcher(test_got) as ctx:
|
||||
bot = ctx.create_bot()
|
||||
@ -42,6 +43,14 @@ async def test_matcher(app: App):
|
||||
ctx.should_rejected()
|
||||
ctx.receive_event(bot, event_next)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_matcher_receive(app: App):
|
||||
from plugins.matcher.matcher_process import test_receive
|
||||
|
||||
message = FakeMessage("text")
|
||||
event = make_fake_event(_message=message)()
|
||||
|
||||
assert len(test_receive.handlers) == 1
|
||||
async with app.test_matcher(test_receive) as ctx:
|
||||
bot = ctx.create_bot()
|
||||
@ -51,7 +60,17 @@ async def test_matcher(app: App):
|
||||
ctx.should_call_send(event, "pause", "result", at_sender=True)
|
||||
ctx.should_paused()
|
||||
|
||||
assert len(test_receive.handlers) == 1
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_matcher_(app: App):
|
||||
from plugins.matcher.matcher_process import test_combine
|
||||
|
||||
message = FakeMessage("text")
|
||||
event = make_fake_event(_message=message)()
|
||||
message_next = FakeMessage("text_next")
|
||||
event_next = make_fake_event(_message=message_next)()
|
||||
|
||||
assert len(test_combine.handlers) == 1
|
||||
async with app.test_matcher(test_combine) as ctx:
|
||||
bot = ctx.create_bot()
|
||||
ctx.receive_event(bot, event)
|
||||
@ -64,6 +83,16 @@ async def test_matcher(app: App):
|
||||
ctx.should_rejected()
|
||||
ctx.receive_event(bot, event_next)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_matcher_preset(app: App):
|
||||
from plugins.matcher.matcher_process import test_preset
|
||||
|
||||
message = FakeMessage("text")
|
||||
event = make_fake_event(_message=message)()
|
||||
message_next = FakeMessage("text_next")
|
||||
event_next = make_fake_event(_message=message_next)()
|
||||
|
||||
assert len(test_preset.handlers) == 2
|
||||
async with app.test_matcher(test_preset) as ctx:
|
||||
bot = ctx.create_bot()
|
||||
@ -72,6 +101,14 @@ async def test_matcher(app: App):
|
||||
ctx.should_rejected()
|
||||
ctx.receive_event(bot, event_next)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_matcher_overload(app: App):
|
||||
from plugins.matcher.matcher_process import test_overload
|
||||
|
||||
message = FakeMessage("text")
|
||||
event = make_fake_event(_message=message)()
|
||||
|
||||
assert len(test_overload.handlers) == 2
|
||||
async with app.test_matcher(test_overload) as ctx:
|
||||
bot = ctx.create_bot()
|
||||
@ -115,12 +152,10 @@ async def test_type_updater(app: App):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_permission_updater(app: App):
|
||||
async def test_default_permission_updater(app: App):
|
||||
from plugins.matcher.matcher_permission import (
|
||||
default_permission,
|
||||
test_custom_updater,
|
||||
test_permission_updater,
|
||||
test_user_permission_updater,
|
||||
)
|
||||
|
||||
event = make_fake_event(_session_id="test")()
|
||||
@ -136,6 +171,15 @@ async def test_permission_updater(app: App):
|
||||
assert checker.users == ("test",)
|
||||
assert checker.perm is default_permission
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_user_permission_updater(app: App):
|
||||
from plugins.matcher.matcher_permission import (
|
||||
default_permission,
|
||||
test_user_permission_updater,
|
||||
)
|
||||
|
||||
event = make_fake_event(_session_id="test")()
|
||||
user_permission = list(test_user_permission_updater.permission.checkers)[0].call
|
||||
assert isinstance(user_permission, User)
|
||||
assert user_permission.perm is default_permission
|
||||
@ -149,12 +193,22 @@ async def test_permission_updater(app: App):
|
||||
assert checker.users == ("test",)
|
||||
assert checker.perm is default_permission
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_custom_permission_updater(app: App):
|
||||
from plugins.matcher.matcher_permission import (
|
||||
new_permission,
|
||||
default_permission,
|
||||
test_custom_updater,
|
||||
)
|
||||
|
||||
event = make_fake_event(_session_id="test")()
|
||||
assert test_custom_updater.permission is default_permission
|
||||
async with app.test_api() as ctx:
|
||||
bot = ctx.create_bot()
|
||||
matcher = test_custom_updater()
|
||||
new_perm = await matcher.update_permission(bot, event)
|
||||
assert new_perm is default_permission
|
||||
assert new_perm is new_permission
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -189,12 +243,8 @@ async def test_run(app: App):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_expire(app: App):
|
||||
from plugins.matcher.matcher_expire import (
|
||||
test_temp_matcher,
|
||||
test_datetime_matcher,
|
||||
test_timedelta_matcher,
|
||||
)
|
||||
async def test_temp(app: App):
|
||||
from plugins.matcher.matcher_expire import test_temp_matcher
|
||||
|
||||
event = make_fake_event(_type="test")()
|
||||
async with app.test_api() as ctx:
|
||||
@ -203,6 +253,11 @@ async def test_expire(app: App):
|
||||
await check_and_run_matcher(test_temp_matcher, bot, event, {})
|
||||
assert test_temp_matcher not in matchers[test_temp_matcher.priority]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_datetime_expire(app: App):
|
||||
from plugins.matcher.matcher_expire import test_datetime_matcher
|
||||
|
||||
event = make_fake_event()()
|
||||
async with app.test_api() as ctx:
|
||||
bot = ctx.create_bot()
|
||||
@ -210,6 +265,11 @@ async def test_expire(app: App):
|
||||
await check_and_run_matcher(test_datetime_matcher, bot, event, {})
|
||||
assert test_datetime_matcher not in matchers[test_datetime_matcher.priority]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_timedelta_expire(app: App):
|
||||
from plugins.matcher.matcher_expire import test_timedelta_matcher
|
||||
|
||||
event = make_fake_event()()
|
||||
async with app.test_api() as ctx:
|
||||
bot = ctx.create_bot()
|
||||
|
Reference in New Issue
Block a user