summaryrefslogtreecommitdiff
path: root/test/test_plugin_funny.py
blob: 851a922f1dc9345a6bd43c679f4d5c0c3c3f0f42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import pytest
from nonebug import App

from .utils import make_fake_message, make_fake_event


@pytest.mark.asyncio
async def test_get_laugh(app: App):
    from ATRI.plugins.funny import get_laugh

    Message = make_fake_message()

    async with app.test_matcher(get_laugh) as ctx:
        bot = ctx.create_bot()

        msg = Message("来句笑话")
        event = make_fake_event(_message=msg)()

        ctx.receive_event(bot, event)
        ctx.should_call_send(event, "哈 哈 哈", True)


@pytest.mark.asyncio
async def test_me_re_you(app: App):
    from ATRI.plugins.funny import me_re_you

    Message = make_fake_message()

    async with app.test_matcher(me_re_you) as ctx:
        bot = ctx.create_bot()

        msg = Message("超市我")
        event = make_fake_event(_message=msg)()

        ctx.receive_event(bot, event)
        ctx.should_call_send(event, "超市你", True)


@pytest.mark.asyncio
async def test_fake_msg(app: App):
    from ATRI.plugins.funny import fake_msg

    Message = make_fake_message()

    async with app.test_matcher(fake_msg) as ctx:
        bot = ctx.create_bot()

        msg = Message("/fakemsg")
        event = make_fake_event(_message=msg)()

        ctx.receive_event(bot, event)
        ctx.should_call_send(event, "内容呢?格式:qq-name-content\n可构造多条,以上仅为一条,使用空格隔开", True)

        msg = Message("114514")
        event = make_fake_event(_message=msg)()

        ctx.receive_event(bot, event)
        ctx.should_call_send(event, "内容格式错误,请检查(", True)

    async with app.test_matcher(fake_msg) as ctx:
        bot = ctx.create_bot()

        msg = Message("/fakemsg")
        event = make_fake_event(_message=msg)()

        ctx.receive_event(bot, event)
        ctx.should_call_send(event, "内容呢?格式:qq-name-content\n可构造多条,以上仅为一条,使用空格隔开", True)

        msg = Message("114514-0w0-testing")
        event = make_fake_event(_message=msg)()

        ctx.receive_event(bot, event)
        ctx.should_call_send(
            event,
            "[{'type': 'node', 'data': {'name': '0w0', 'uin': '114514', 'content': 'testing'}}]",
            True,
        )

    async with app.test_matcher(fake_msg) as ctx:
        bot = ctx.create_bot()

        msg = Message("/fakemsg")
        event = make_fake_event(_message=msg)()

        ctx.receive_event(bot, event)
        ctx.should_call_send(event, "内容呢?格式:qq-name-content\n可构造多条,以上仅为一条,使用空格隔开", True)

        msg = Message("114514-0w0-testing")
        event = make_fake_event(_message=msg)()

        ctx.receive_event(bot, event)
        ctx.should_call_send(event, "构造失败惹...可能是被制裁了(", True)

    async with app.test_matcher(fake_msg) as ctx:
        bot = ctx.create_bot()

        msg = Message("/fakemsg")
        event = make_fake_event(_message=msg)()

        ctx.receive_event(bot, event)
        ctx.should_call_send(event, "慢...慢一..点❤", True)


@pytest.mark.asyncio
async def test_eat_what(app: App):
    from ATRI.plugins.funny import eat_what

    Message = make_fake_message()

    async with app.test_matcher(eat_what) as ctx:
        bot = ctx.create_bot()

        msg = Message("今天吃什么")
        event = make_fake_event(_message=msg)()

        ctx.receive_event(bot, event)
        ctx.should_call_send(event, "欧尼酱的智商低下想不到今天要吃甚么,所以由我来选择,我给的答案是(串烧)。选我正解!!", True)