1
- from typing import Any , List , Tuple
1
+ from typing import Any , List , Tuple , Dict
2
2
3
3
from zulip_bots .game_handler import GameInstance
4
+ from typing_extensions import override
4
5
from zulip_bots .test_lib import BotTestCase , DefaultTests
5
6
6
- from .libraries .constants import EMPTY_BOARD
7
+ from zulip_bots .bots .merels .libraries .constants import EMPTY_BOARD
8
+
7
9
8
10
9
11
class TestMerelsBot (BotTestCase , DefaultTests ):
10
12
bot_name = "merels"
11
13
14
+ @override
15
+ def make_request_message (
16
+ self ,
content :
str ,
user :
str = "[email protected] " ,
user_name :
str = "foo"
17
+ ) -> Dict [str , str ]:
18
+ message = dict (sender_email = user , content = content , sender_full_name = user_name )
19
+ return message
20
+
12
21
def test_no_command (self ):
13
22
message = dict (
14
23
content = "magic" ,
type = "stream" ,
sender_email = "[email protected] " ,
sender_full_name = "boo"
@@ -18,6 +27,58 @@ def test_no_command(self):
18
27
res ["content" ], "You are not in a game at the moment. Type `help` for help."
19
28
)
20
29
30
+ def verify_response (
31
+ self ,
32
+ request : str ,
33
+ expected_response : str ,
34
+ response_number : int ,
35
+
36
+ ) -> None :
37
+ """
38
+ This function serves a similar purpose
39
+ to BotTestCase.verify_dialog, but allows
40
+ for multiple responses to be validated,
41
+ and for mocking of the bot's internal data
42
+ """
43
+
44
+ bot , bot_handler = self ._get_handlers ()
45
+ message = self .make_request_message (request , user )
46
+ bot_handler .reset_transcript ()
47
+
48
+ bot .handle_message (message , bot_handler )
49
+
50
+ responses = [message for (method , message ) in bot_handler .transcript ]
51
+
52
+ first_response = responses [response_number ]
53
+ self .assertEqual (expected_response , first_response ["content" ])
54
+
55
+ def help_message (self ) -> str :
56
+ return """** Connect Four Bot Help:**
57
+ *Preface all commands with @**test-bot***
58
+ * To start a game in a stream (*recommended*), type
59
+ `start game`
60
+ * To start a game against another player, type
61
+ `start game with @<player-name>`
62
+ * To play game with the current number of players, type
63
+ `play game`
64
+ * To quit a game at any time, type
65
+ `quit`
66
+ * To end a game with a draw, type
67
+ `draw`
68
+ * To forfeit a game, type
69
+ `forfeit`
70
+ * To see the leaderboard, type
71
+ `leaderboard`
72
+ * To withdraw an invitation, type
73
+ `cancel game`
74
+ * To see rules of this game, type
75
+ `rules`
76
+ * To make your move during a game, type
77
+ ```move <column-number>``` or ```<column-number>```"""
78
+
79
+
80
+
81
+
21
82
# FIXME: Add tests for computer moves
22
83
# FIXME: Add test lib for game_handler
23
84
@@ -30,6 +91,7 @@ def test_static_responses(self) -> None:
30
91
self .assertEqual (
31
92
message_handler .alert_move_message ("foo" , "moved right" ), "foo :moved right"
32
93
)
94
+ self .verify_response ("help" , self .help_message (), 0 )
33
95
34
96
# Test to see if the attributes exist
35
97
def test_has_attributes (self ) -> None :
0 commit comments