1- from typing import Any , List , Tuple
1+ from typing import Any , List , Tuple , Dict
22
33from zulip_bots .game_handler import GameInstance
4+ from typing_extensions import override
45from zulip_bots .test_lib import BotTestCase , DefaultTests
56
6- from .libraries .constants import EMPTY_BOARD
7+ from zulip_bots .bots .merels .libraries .constants import EMPTY_BOARD
8+
79
810
911class TestMerelsBot (BotTestCase , DefaultTests ):
1012 bot_name = "merels"
1113
14+ @override
15+ def make_request_message (
16+ self , content : str , user : str = "foo@example.com" , 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+
1221 def test_no_command (self ):
1322 message = dict (
1423 content = "magic" , type = "stream" , sender_email = "boo@email.com" , sender_full_name = "boo"
@@ -18,6 +27,58 @@ def test_no_command(self):
1827 res ["content" ], "You are not in a game at the moment. Type `help` for help."
1928 )
2029
30+ def verify_response (
31+ self ,
32+ request : str ,
33+ expected_response : str ,
34+ response_number : int ,
35+ user : str = "foo@example.com" ,
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+
2182 # FIXME: Add tests for computer moves
2283 # FIXME: Add test lib for game_handler
2384
@@ -30,6 +91,7 @@ def test_static_responses(self) -> None:
3091 self .assertEqual (
3192 message_handler .alert_move_message ("foo" , "moved right" ), "foo :moved right"
3293 )
94+ self .verify_response ("help" , self .help_message (), 0 )
3395
3496 # Test to see if the attributes exist
3597 def test_has_attributes (self ) -> None :
0 commit comments