Skip to content

Commit

Permalink
✅ update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shoucandanghehe committed Jun 14, 2024
1 parent 500a29c commit 5dee38b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
4 changes: 4 additions & 0 deletions tests/fake.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from datetime import datetime
from typing import TYPE_CHECKING, Literal

from nonebot.adapters.satori.models import Login, LoginStatus

FAKE_SATORI_LOGIN = Login(status=LoginStatus.ONLINE)

if TYPE_CHECKING:
from nonebot.adapters.qq import MessageCreateEvent as MessageCreateEvent
from nonebot.adapters.satori.event import MessageEvent as SatoriMessageEvent
Expand Down
6 changes: 3 additions & 3 deletions tests/test_builtin_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from nonebot import get_adapter
from nonebot.adapters.satori import Bot, Adapter, Message, MessageSegment

from tests.fake import fake_message_event_satori
from tests.fake import FAKE_SATORI_LOGIN, fake_message_event_satori


@pytest.mark.asyncio()
Expand All @@ -14,7 +14,7 @@ async def test_echo(app: App):

async with app.test_matcher() as ctx:
adapter = get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, adapter=adapter, platform="satori", info=None)
bot = ctx.create_bot(base=Bot, adapter=adapter, login=FAKE_SATORI_LOGIN, info=None)
msg = "/echo" + MessageSegment.image(raw=b"123", mime="image/png")
event = fake_message_event_satori(message=msg, id=123)
ctx.receive_event(bot, event)
Expand Down Expand Up @@ -42,7 +42,7 @@ async def tt_h():

async with app.test_matcher() as ctx:
adapter = get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, adapter=adapter, platform="satori", info=None)
bot = ctx.create_bot(base=Bot, adapter=adapter, login=FAKE_SATORI_LOGIN, info=None)
msg = Message("/help")
event = fake_message_event_satori(message=msg, id=123)
ctx.receive_event(bot, event)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from nonebot.adapters.satori import Bot, Message
from arclet.alconna import Args, Alconna, CommandMeta

from tests.fake import fake_message_event_satori
from tests.fake import FAKE_SATORI_LOGIN, fake_message_event_satori


@pytest.mark.asyncio()
Expand All @@ -20,7 +20,7 @@ async def tt_h(userid: str, ctx: dict):

async with app.test_matcher(test_cmd) as ctx:
# adapter = get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, platform="satori", info=None)
bot = ctx.create_bot(base=Bot, login=FAKE_SATORI_LOGIN, info=None)
msg = Message("test $(event.get_user_id())")
event = fake_message_event_satori(message=msg, id=123, user=User(id="456", name="test"))
ctx.receive_event(bot, event)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_filehost_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from arclet.alconna import Alconna
from nonebot.adapters.satori import Bot, Adapter, Message, MessageSegment

from tests.fake import fake_message_event_satori
from tests.fake import FAKE_SATORI_LOGIN, fake_message_event_satori


@pytest.mark.asyncio()
Expand All @@ -20,7 +20,7 @@ async def tt_h():
apply_filehost()
async with app.test_matcher(test_cmd) as ctx:
adapter = get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, adapter=adapter, platform="satori", info=None)
bot = ctx.create_bot(base=Bot, adapter=adapter, login=FAKE_SATORI_LOGIN, info=None)
msg = Message("test")
event = fake_message_event_satori(message=msg, id=123)
ctx.receive_event(bot, event)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_saa_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from nonebot import require, get_adapter
from nonebot.adapters.satori import Bot, Adapter, MessageSegment

from tests.fake import fake_message_event_satori
from tests.fake import FAKE_SATORI_LOGIN, fake_message_event_satori


@pytest.mark.asyncio()
Expand All @@ -29,7 +29,7 @@ async def tt_h(target: At):

async with app.test_matcher(test_cmd) as ctx:
adapter = get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, adapter=adapter, platform="satori", info=None)
bot = ctx.create_bot(base=Bot, adapter=adapter, login=FAKE_SATORI_LOGIN, info=None)
msg = "test" + MessageSegment.at("234")
event = fake_message_event_satori(message=msg, id=123)
ctx.receive_event(bot, event)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_satori.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from nonebot.adapters.satori.element import parse
from nonebot.adapters.satori import Bot, Adapter, Message, MessageSegment

from tests.fake import fake_message_event_satori
from tests.fake import FAKE_SATORI_LOGIN, fake_message_event_satori


def test_message_rollback():
Expand Down Expand Up @@ -82,7 +82,7 @@ async def tt_h(img: Image):

async with app.test_matcher(test_cmd) as ctx:
adapter = get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, adapter=adapter, platform="satori", info=None)
bot = ctx.create_bot(base=Bot, adapter=adapter, login=FAKE_SATORI_LOGIN, info=None)
msg = "test" + MessageSegment.image(raw=b"123", mime="image/png")
event = fake_message_event_satori(message=msg, id=123)
ctx.receive_event(bot, event)
Expand Down
15 changes: 11 additions & 4 deletions tests/test_target_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
from nonebot.adapters.onebot.v12 import Adapter as Onebot12Adapter
from nonebot.adapters.satori.models import User, Guild, Channel, PageResult, ChannelType

from tests.fake import FAKE_SATORI_LOGIN

FAKE_SATORI_CHRONOCAT_LOGIN = FAKE_SATORI_LOGIN.model_copy(update={"platform": "chronocat"})
FAKE_SATORI_QQ_LOGIN = FAKE_SATORI_LOGIN.model_copy(update={"platform": "qq"})


@pytest.mark.asyncio()
async def test_bots(app: App):
Expand All @@ -25,9 +30,11 @@ async def test_bots(app: App):
qq_bot = ctx.create_bot(base=QQBot, adapter=qq_adapter, self_id="1", bot_info=None)
satori_adapter = get_adapter(SatoriAdapter)
satori_bot_cc = ctx.create_bot(
base=SatoriBot, adapter=satori_adapter, self_id="2", platform="chronocat", info=None
base=SatoriBot, adapter=satori_adapter, self_id="2", login=FAKE_SATORI_CHRONOCAT_LOGIN, info=None
)
satori_bot_qq = ctx.create_bot(
base=SatoriBot, adapter=satori_adapter, self_id="3", login=FAKE_SATORI_QQ_LOGIN, info=None
)
satori_bot_qq = ctx.create_bot(base=SatoriBot, adapter=satori_adapter, self_id="3", platform="qq", info=None)
onebot11_adapter = get_adapter(Onebot11Adapter)
onebot11_bot = ctx.create_bot(base=Onebot11Bot, adapter=onebot11_adapter, self_id="4")
onebot12_adapter = get_adapter(Onebot12Adapter)
Expand Down Expand Up @@ -70,7 +77,7 @@ async def test_enable(app: App, mocker: MockerFixture):
async with app.test_api() as ctx:
satori_adapter = get_adapter(SatoriAdapter)
satori_bot1 = ctx.create_bot(
base=SatoriBot, adapter=satori_adapter, self_id="1", platform="chronocat", info=None
base=SatoriBot, adapter=satori_adapter, self_id="1", login=FAKE_SATORI_CHRONOCAT_LOGIN, info=None
)

ctx.should_call_api("friend_list", {}, PageResult(data=[User(id="11", name="test1")]))
Expand All @@ -81,7 +88,7 @@ async def test_enable(app: App, mocker: MockerFixture):
)
await asyncio.sleep(0.1)
satori_bot2 = ctx.create_bot(
base=SatoriBot, adapter=satori_adapter, self_id="2", platform="chronocat", info=None
base=SatoriBot, adapter=satori_adapter, self_id="2", login=FAKE_SATORI_CHRONOCAT_LOGIN, info=None
)
ctx.should_call_api("friend_list", {}, PageResult(data=[User(id="21", name="test1")]))

Expand Down

0 comments on commit 5dee38b

Please sign in to comment.