mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 16:01:58 +00:00
contrib_bots: Add check_expected_responses() test helper and use it.
This further simplifies the logic for testing a contrib_bots bot to require very little code per test in the common case.
This commit is contained in:
@@ -6,6 +6,7 @@ from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
import logging
|
||||
|
||||
from mock import MagicMock, patch
|
||||
|
||||
@@ -31,6 +32,19 @@ class BotTestCase(TestCase):
|
||||
self.bot_test(messages=[request], bot_module=bot_module,
|
||||
bot_response=[response])
|
||||
|
||||
def check_expected_responses(self, expectations, email="foo", recipient="foo", subject="foo", type="all"):
|
||||
# type: (Dict[str, str], str, str, str, str) -> None
|
||||
if type not in ["private", "stream", "all"]:
|
||||
logging.exception("check_expected_response expects type to be 'private', 'stream' or 'all'")
|
||||
for m, r in expectations.items():
|
||||
if type != "stream":
|
||||
self.assert_bot_output(
|
||||
{'content': m, 'type': "private", 'sender_email': email}, r)
|
||||
if type != "private":
|
||||
self.assert_bot_output(
|
||||
{'content': m, 'type': "stream", 'display_recipient': recipient,
|
||||
'subject': subject}, r)
|
||||
|
||||
def mock_test(self, messages, message_handler, bot_response):
|
||||
# message_handler is of type Any, since it can contain any bot's
|
||||
# handler class. Eventually, we want bot's handler classes to
|
||||
|
||||
Reference in New Issue
Block a user