/
test_echo.py
173 lines (127 loc) · 6.05 KB
/
test_echo.py
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
"""Tests for metabot.modules.echo."""
from __future__ import absolute_import, division, print_function, unicode_literals
import pytest
from metabot.modules import echo
@pytest.fixture
def conversation(build_conversation): # pylint: disable=missing-docstring
return build_conversation(echo)
# pylint: disable=line-too-long
def test_echo(conversation): # pylint: disable=redefined-outer-name
"""Verify the echo module (which uses dynamic commands)."""
assert conversation.message('/myecho') == ''
conversation.multibot.conf['bots']['modulestestbot']['issue37']['echo']['myecho'] = {
'text': 'These are the rules: Have fun!',
}
assert conversation.message('/myecho') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
These are the rules: Have fun!
"""
conversation.multibot.conf['bots']['modulestestbot']['issue37']['echo']['about'] = {
'text': ('First line.\n'
'Second line.\n'
' \n'
'Last line.'),
}
assert conversation.message('/about') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
First line.
Second line.
Last line.
"""
conversation.multibot.conf['bots']['modulestestbot']['issue37']['echo']['about'] = {
'text': ('First line.\n'
'Second line.\n'
' \n'
'Last line.'),
'paginate': True,
}
assert conversation.message('/about') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
First line.
[More (1/3) | /about 2]
"""
assert conversation.message('/about 2') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
First line.
Second line.
[More (2/3) | /about 3]
"""
assert conversation.message('/about 3') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
First line.
Second line.
Last line.
"""
assert conversation.message('/about 1000') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
First line.
Second line.
Last line.
"""
assert conversation.message('/about bogus') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
First line.
[More (1/3) | /about 2]
"""
def test_help(conversation): # pylint: disable=redefined-outer-name
"""Test /help."""
conversation.multibot.conf['bots']['modulestestbot']['issue37']['echo']['rules1'] = {
'text': 'These are the rules: Have fun!',
}
conversation.multibot.conf['bots']['modulestestbot']['issue37']['echo']['rules2'] = {
'text': 'These are the rules: Have fun!!',
}
assert conversation.message('/help', user_id=2000) == """\
[chat_id=2000 disable_web_page_preview=True parse_mode=HTML]
<b>Commands</b>
/rules1 \u2013 "These are the rules: Have fun!"
/rules2 \u2013 "These are the rules: Have fun\u2026"
"""
def test_admin(conversation): # pylint: disable=redefined-outer-name
"""Test /admin BOTNAME echo."""
assert conversation.message('/admin modulestestbot echo') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a echo: <b>Choose a command</b>
Type the name of a command to add (like <code>rules</code>\u2014don't include a slash at the beginning!), or select an existing echo.
[Back | /admin modulestestbot]
"""
assert conversation.message('EchoTest') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a echo \u203a echotest: <b>Choose a field</b>
[text \u2022 The message, sticker, or image to send in response to /echotest. | /admin modulestestbot echo echotest text]
[paginate \u2022 For multiline messages, display just one line at a time? | /admin modulestestbot echo echotest paginate]
[private \u2022 Send the message in group chats, or just in private? | /admin modulestestbot echo echotest private]
[Back | /admin modulestestbot echo]
"""
assert conversation.message('text') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a echo \u203a echotest \u203a text: <b>Type a new value for text</b>
The message, sticker, or image to send in response to /echotest.
Type your new value, or type "off" to disable/reset to default.
[Back | /admin modulestestbot echo echotest]
"""
assert conversation.message('my message') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a echo \u203a echotest: <b>Choose a field</b>
Set <code>text</code> to <code>my message</code>.
[text (my message) \u2022 The message, sticker, or image to send in response to /echotest. | /admin modulestestbot echo echotest text]
[paginate \u2022 For multiline messages, display just one line at a time? | /admin modulestestbot echo echotest paginate]
[private \u2022 Send the message in group chats, or just in private? | /admin modulestestbot echo echotest private]
[Back | /admin modulestestbot echo]
"""
assert conversation.message('/admin modulestestbot echo echotest text new message') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a echo \u203a echotest: <b>Choose a field</b>
Changed <code>text</code> from <code>my message</code> to <code>new message</code>.
[text (new messa\u2026) \u2022 The message, sticker, or image to send in response to /echotest. | /admin modulestestbot echo echotest text]
[paginate \u2022 For multiline messages, display just one line at a time? | /admin modulestestbot echo echotest paginate]
[private \u2022 Send the message in group chats, or just in private? | /admin modulestestbot echo echotest private]
[Back | /admin modulestestbot echo]
"""
assert conversation.message('/admin modulestestbot echo') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a echo: <b>Choose a command</b>
Type the name of a command to add (like <code>rules</code>\u2014don't include a slash at the beginning!), or select an existing echo.
[/echotest (new message) | /admin modulestestbot echo echotest]
[Back | /admin modulestestbot]
"""