bot tests: Support optional provided state between test calls.
This commit is contained in:
parent
45527c4cf4
commit
6421a6fd49
|
@ -54,8 +54,9 @@ class BotTestCase(TestCase):
|
||||||
|
|
||||||
def check_expected_responses(self, expectations, expected_method='send_reply',
|
def check_expected_responses(self, expectations, expected_method='send_reply',
|
||||||
email="foo_sender@zulip.com", recipient="foo", subject="foo",
|
email="foo_sender@zulip.com", recipient="foo", subject="foo",
|
||||||
sender_id=0, sender_full_name="Foo Bar", type="all"):
|
sender_id=0, sender_full_name="Foo Bar", type="all",
|
||||||
# type: (Dict[str, Any], str, str, str, str, int, str, str) -> None
|
state_handler=None):
|
||||||
|
# type: (Dict[str, Any], str, str, str, str, int, str, str, Optional[StateHandler]) -> None
|
||||||
# To test send_message, Any would be a Dict type,
|
# To test send_message, Any would be a Dict type,
|
||||||
# to test send_reply, Any would be a str type.
|
# to test send_reply, Any would be a str type.
|
||||||
if type not in ["private", "stream", "all"]:
|
if type not in ["private", "stream", "all"]:
|
||||||
|
@ -69,17 +70,21 @@ class BotTestCase(TestCase):
|
||||||
message = {'content': m, 'type': "private", 'display_recipient': recipient,
|
message = {'content': m, 'type': "private", 'display_recipient': recipient,
|
||||||
'sender_email': email, 'sender_id': sender_id,
|
'sender_email': email, 'sender_id': sender_id,
|
||||||
'sender_full_name': sender_full_name}
|
'sender_full_name': sender_full_name}
|
||||||
self.assert_bot_response(message=message, response=response, expected_method=expected_method)
|
self.assert_bot_response(message=message, response=response,
|
||||||
|
expected_method=expected_method, state_handler=state_handler)
|
||||||
if type != "private":
|
if type != "private":
|
||||||
message = {'content': m, 'type': "stream", 'display_recipient': recipient,
|
message = {'content': m, 'type': "stream", 'display_recipient': recipient,
|
||||||
'subject': subject, 'sender_email': email, 'sender_id': sender_id,
|
'subject': subject, 'sender_email': email, 'sender_id': sender_id,
|
||||||
'sender_full_name': sender_full_name}
|
'sender_full_name': sender_full_name}
|
||||||
self.assert_bot_response(message=message, response=response, expected_method=expected_method)
|
self.assert_bot_response(message=message, response=response,
|
||||||
|
expected_method=expected_method, state_handler=state_handler)
|
||||||
|
|
||||||
def call_request(self, message, expected_method, response):
|
def call_request(self, message, expected_method, response, state_handler):
|
||||||
# type: (Dict[str, Any], str, Dict[str, Any]) -> None
|
# type: (Dict[str, Any], str, Dict[str, Any], Optional[StateHandler]) -> None
|
||||||
|
if state_handler is None:
|
||||||
|
state_handler = StateHandler()
|
||||||
# Send message to the concerned bot
|
# Send message to the concerned bot
|
||||||
self.message_handler.handle_message(message, self.MockClass(), StateHandler())
|
self.message_handler.handle_message(message, self.MockClass(), state_handler)
|
||||||
|
|
||||||
# Check if the bot is sending a message via `send_message` function.
|
# Check if the bot is sending a message via `send_message` function.
|
||||||
# Where response is a dictionary here.
|
# Where response is a dictionary here.
|
||||||
|
@ -127,8 +132,8 @@ class BotTestCase(TestCase):
|
||||||
else:
|
else:
|
||||||
mock_get.assert_called_with(http_request['api_url'], params=params)
|
mock_get.assert_called_with(http_request['api_url'], params=params)
|
||||||
|
|
||||||
def assert_bot_response(self, message, response, expected_method):
|
def assert_bot_response(self, message, response, expected_method, state_handler = None):
|
||||||
# type: (Dict[str, Any], Dict[str, Any], str) -> None
|
# type: (Dict[str, Any], Dict[str, Any], str, Optional[StateHandler]) -> None
|
||||||
# Strictly speaking, this function is not needed anymore,
|
# Strictly speaking, this function is not needed anymore,
|
||||||
# kept for now for legacy reasons.
|
# kept for now for legacy reasons.
|
||||||
self.call_request(message, expected_method, response)
|
self.call_request(message, expected_method, response, state_handler)
|
||||||
|
|
Loading…
Reference in a new issue