diff --git a/tools/test-bots b/tools/test-bots index 259f0d8..ac2dbe5 100755 --- a/tools/test-bots +++ b/tools/test-bots @@ -95,19 +95,6 @@ def main(): if options.error_on_no_init: sys.exit(1) - def filter_tests(tests): - # type: (Union[TestSuite, TestCase]) -> TestSuite - filtered_tests = TestSuite() - for test in tests: - if isinstance(test, TestCase): - # Exclude test base class from being tested. - if test.__class__.__name__ != 'BotTestCase': - filtered_tests.addTest(test) - else: - filtered_tests.addTest(filter_tests(test)) - return filtered_tests - test_suites = filter_tests(test_suites) - suite = unittest.TestSuite(test_suites) runner = unittest.TextTestRunner(verbosity=2) result = runner.run(suite) diff --git a/zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py b/zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py index 4037bb7..0aad62b 100644 --- a/zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py +++ b/zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py @@ -1,9 +1,9 @@ from unittest.mock import patch -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import StubBotHandler from zulip_bots.bots.baremetrics.baremetrics import BaremetricsHandler -class TestBaremetricsBot(BotTestCase): +class TestBaremetricsBot(BotTestCase, DefaultTests): bot_name = "baremetrics" def test_bot_responds_to_empty_message(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py b/zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py index cbd0a9e..699658a 100644 --- a/zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py +++ b/zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py @@ -1,8 +1,8 @@ from unittest.mock import patch, Mock -from zulip_bots.test_lib import StubBotHandler, BotTestCase, get_bot_message_handler +from zulip_bots.test_lib import StubBotHandler, BotTestCase, DefaultTests, get_bot_message_handler from requests.exceptions import ConnectionError -class TestBeeminderBot(BotTestCase): +class TestBeeminderBot(BotTestCase, DefaultTests): bot_name = "beeminder" normal_config = { "auth_token": "XXXXXX", diff --git a/zulip_bots/zulip_bots/bots/chessbot/test_chessbot.py b/zulip_bots/zulip_bots/bots/chessbot/test_chessbot.py index 5b34006..113a9e4 100644 --- a/zulip_bots/zulip_bots/bots/chessbot/test_chessbot.py +++ b/zulip_bots/zulip_bots/bots/chessbot/test_chessbot.py @@ -1,6 +1,6 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests -class TestChessBot(BotTestCase): +class TestChessBot(BotTestCase, DefaultTests): bot_name = "chessbot" START_RESPONSE = '''New game! The board looks like this: diff --git a/zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py b/zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py index de70301..1efe812 100644 --- a/zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py +++ b/zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py @@ -1,4 +1,4 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from contextlib import contextmanager from unittest.mock import MagicMock @@ -7,7 +7,7 @@ from zulip_bots.game_handler import BadMoveException from typing import Dict, Any, List -class TestConnectFourBot(BotTestCase): +class TestConnectFourBot(BotTestCase, DefaultTests): bot_name = 'connect_four' def make_request_message( diff --git a/zulip_bots/zulip_bots/bots/converter/test_converter.py b/zulip_bots/zulip_bots/bots/converter/test_converter.py index 5328b9d..4d53876 100755 --- a/zulip_bots/zulip_bots/bots/converter/test_converter.py +++ b/zulip_bots/zulip_bots/bots/converter/test_converter.py @@ -1,8 +1,8 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.bots.converter import utils -class TestConverterBot(BotTestCase): +class TestConverterBot(BotTestCase, DefaultTests): bot_name = "converter" def test_bot(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/define/test_define.py b/zulip_bots/zulip_bots/bots/define/test_define.py index 43dd850..fcf70d9 100755 --- a/zulip_bots/zulip_bots/bots/define/test_define.py +++ b/zulip_bots/zulip_bots/bots/define/test_define.py @@ -1,7 +1,7 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from unittest.mock import patch -class TestDefineBot(BotTestCase): +class TestDefineBot(BotTestCase, DefaultTests): bot_name = "define" def test_bot(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py b/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py index 5f4424c..9472a68 100644 --- a/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py +++ b/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py @@ -1,4 +1,4 @@ -from zulip_bots.test_lib import BotTestCase, read_bot_fixture_data +from zulip_bots.test_lib import BotTestCase, DefaultTests, read_bot_fixture_data from contextlib import contextmanager @@ -40,7 +40,7 @@ def mock_dialogflow(test_name: str, bot_name: str) -> Any: mock_text_request.return_value = request yield -class TestDialogFlowBot(BotTestCase): +class TestDialogFlowBot(BotTestCase, DefaultTests): bot_name = 'dialogflow' def _test(self, test_name: str, message: str, response: str) -> None: diff --git a/zulip_bots/zulip_bots/bots/dropbox_share/test_dropbox_share.py b/zulip_bots/zulip_bots/bots/dropbox_share/test_dropbox_share.py index 8b36a5d..41cc14b 100644 --- a/zulip_bots/zulip_bots/bots/dropbox_share/test_dropbox_share.py +++ b/zulip_bots/zulip_bots/bots/dropbox_share/test_dropbox_share.py @@ -1,4 +1,4 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from typing import List from unittest.mock import patch @@ -73,7 +73,7 @@ def get_help() -> str: ``` ''' -class TestDropboxBot(BotTestCase): +class TestDropboxBot(BotTestCase, DefaultTests): bot_name = "dropbox_share" config_info = {"access_token": "1234567890"} diff --git a/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py b/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py index e5d6e7a..07a32f3 100755 --- a/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py +++ b/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py @@ -1,6 +1,6 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests -class TestEncryptBot(BotTestCase): +class TestEncryptBot(BotTestCase, DefaultTests): bot_name = "encrypt" def test_bot(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/flock/test_flock.py b/zulip_bots/zulip_bots/bots/flock/test_flock.py index 15dd3a5..804c401 100644 --- a/zulip_bots/zulip_bots/bots/flock/test_flock.py +++ b/zulip_bots/zulip_bots/bots/flock/test_flock.py @@ -1,8 +1,8 @@ from unittest.mock import patch -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from requests.exceptions import ConnectionError -class TestFlockBot(BotTestCase): +class TestFlockBot(BotTestCase, DefaultTests): bot_name = "flock" normal_config = {"token": "12345"} diff --git a/zulip_bots/zulip_bots/bots/followup/test_followup.py b/zulip_bots/zulip_bots/bots/followup/test_followup.py index 349b661..458249a 100755 --- a/zulip_bots/zulip_bots/bots/followup/test_followup.py +++ b/zulip_bots/zulip_bots/bots/followup/test_followup.py @@ -1,13 +1,14 @@ from zulip_bots.test_lib import ( StubBotHandler, BotTestCase, + DefaultTests, get_bot_message_handler, ) from typing import Any -class TestFollowUpBot(BotTestCase): +class TestFollowUpBot(BotTestCase, DefaultTests): bot_name = "followup" def test_followup_stream(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/front/test_front.py b/zulip_bots/zulip_bots/bots/front/test_front.py index 8474bf1..4f8efa1 100644 --- a/zulip_bots/zulip_bots/bots/front/test_front.py +++ b/zulip_bots/zulip_bots/bots/front/test_front.py @@ -1,8 +1,8 @@ from typing import Any, Dict -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests -class TestFrontBot(BotTestCase): +class TestFrontBot(BotTestCase, DefaultTests): bot_name = 'front' def make_request_message(self, content: str) -> Dict[str, Any]: @@ -49,7 +49,7 @@ class TestFrontBot(BotTestCase): with self.mock_http_conversation('comment'): self.verify_reply("comment " + body, "Comment was sent.") -class TestFrontBotWrongTopic(BotTestCase): +class TestFrontBotWrongTopic(BotTestCase, DefaultTests): bot_name = 'front' def make_request_message(self, content: str) -> Dict[str, Any]: diff --git a/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py b/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py index 45836f7..deaefbd 100644 --- a/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py +++ b/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py @@ -1,4 +1,4 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.game_handler import GameInstance from contextlib import contextmanager @@ -7,7 +7,7 @@ from mock import MagicMock, patch from typing import Any, Dict, List -class TestGameHandlerBot(BotTestCase): +class TestGameHandlerBot(BotTestCase, DefaultTests): bot_name = 'game_handler_bot' def make_request_message( diff --git a/zulip_bots/zulip_bots/bots/game_of_fifteen/test_game_of_fifteen.py b/zulip_bots/zulip_bots/bots/game_of_fifteen/test_game_of_fifteen.py index 830b8d1..6c50700 100644 --- a/zulip_bots/zulip_bots/bots/game_of_fifteen/test_game_of_fifteen.py +++ b/zulip_bots/zulip_bots/bots/game_of_fifteen/test_game_of_fifteen.py @@ -1,4 +1,4 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from contextlib import contextmanager from unittest.mock import MagicMock @@ -7,7 +7,7 @@ from zulip_bots.game_handler import BadMoveException from typing import Dict, Any, List, Tuple -class TestGameOfFifteenBot(BotTestCase): +class TestGameOfFifteenBot(BotTestCase, DefaultTests): bot_name = 'game_of_fifteen' def make_request_message( diff --git a/zulip_bots/zulip_bots/bots/giphy/test_giphy.py b/zulip_bots/zulip_bots/bots/giphy/test_giphy.py index 7f60e1d..6c82982 100755 --- a/zulip_bots/zulip_bots/bots/giphy/test_giphy.py +++ b/zulip_bots/zulip_bots/bots/giphy/test_giphy.py @@ -2,9 +2,9 @@ from unittest.mock import patch, MagicMock from requests.exceptions import HTTPError, ConnectionError from typing import Any, Union -from zulip_bots.test_lib import StubBotHandler, BotTestCase, get_bot_message_handler +from zulip_bots.test_lib import StubBotHandler, BotTestCase, DefaultTests, get_bot_message_handler -class TestGiphyBot(BotTestCase): +class TestGiphyBot(BotTestCase, DefaultTests): bot_name = "giphy" # Test for bot response to empty message diff --git a/zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py b/zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py index 05a2ae2..ffbba00 100755 --- a/zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py +++ b/zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py @@ -1,12 +1,13 @@ from zulip_bots.test_lib import ( StubBotHandler, BotTestCase, + DefaultTests, get_bot_message_handler, ) from typing import Any -class TestGithubDetailBot(BotTestCase): +class TestGithubDetailBot(BotTestCase, DefaultTests): bot_name = "github_detail" mock_config = {'owner': 'zulip', 'repo': 'zulip'} empty_config = {'owner': '', 'repo': ''} diff --git a/zulip_bots/zulip_bots/bots/google_search/test_google_search.py b/zulip_bots/zulip_bots/bots/google_search/test_google_search.py index 4d8d79d..8162992 100644 --- a/zulip_bots/zulip_bots/bots/google_search/test_google_search.py +++ b/zulip_bots/zulip_bots/bots/google_search/test_google_search.py @@ -1,8 +1,8 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from unittest.mock import patch -class TestGoogleSearchBot(BotTestCase): +class TestGoogleSearchBot(BotTestCase, DefaultTests): bot_name = 'google_search' # Simple query diff --git a/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py b/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py index b39997b..8a1860b 100644 --- a/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py +++ b/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py @@ -1,7 +1,7 @@ from unittest.mock import patch from requests.exceptions import ConnectionError -from zulip_bots.test_lib import BotTestCase, StubBotHandler +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler from zulip_bots.bots.google_translate.google_translate import TranslateError help_text = ''' @@ -11,7 +11,7 @@ Please format your message like: Visit [here](https://cloud.google.com/translate/docs/languages) for all languages ''' -class TestGoogleTranslateBot(BotTestCase): +class TestGoogleTranslateBot(BotTestCase, DefaultTests): bot_name = "google_translate" def _test(self, message, response, http_config_fixture, http_fixture=None): diff --git a/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py b/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py index 7ccfb9c..e65268f 100755 --- a/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py +++ b/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py @@ -1,6 +1,6 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests -class TestHelpBot(BotTestCase): +class TestHelpBot(BotTestCase, DefaultTests): bot_name = "helloworld" # type: str def test_bot(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/help/test_help.py b/zulip_bots/zulip_bots/bots/help/test_help.py index 79d0f9c..69ad6a6 100755 --- a/zulip_bots/zulip_bots/bots/help/test_help.py +++ b/zulip_bots/zulip_bots/bots/help/test_help.py @@ -1,8 +1,8 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from typing import Any -class TestHelpBot(BotTestCase): +class TestHelpBot(BotTestCase, DefaultTests): bot_name = "help" def test_bot(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/idonethis/test_idonethis.py b/zulip_bots/zulip_bots/bots/idonethis/test_idonethis.py index 4f540b6..6f63dba 100644 --- a/zulip_bots/zulip_bots/bots/idonethis/test_idonethis.py +++ b/zulip_bots/zulip_bots/bots/idonethis/test_idonethis.py @@ -1,10 +1,10 @@ from unittest.mock import patch -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests import requests -class TestIDoneThisBot(BotTestCase): +class TestIDoneThisBot(BotTestCase, DefaultTests): bot_name = "idonethis" # type: str def test_create_entry_default_team(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py b/zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py index 7c11bf5..7125504 100644 --- a/zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py +++ b/zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py @@ -3,10 +3,11 @@ from unittest import mock from zulip_bots.test_lib import ( get_bot_message_handler, StubBotHandler, + DefaultTests, BotTestCase, ) -class TestIncrementorBot(BotTestCase): +class TestIncrementorBot(BotTestCase, DefaultTests): bot_name = "incrementor" def test_bot(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/jira/test_jira.py b/zulip_bots/zulip_bots/bots/jira/test_jira.py index 5644a17..0d6f90f 100644 --- a/zulip_bots/zulip_bots/bots/jira/test_jira.py +++ b/zulip_bots/zulip_bots/bots/jira/test_jira.py @@ -1,7 +1,7 @@ from unittest.mock import patch -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests -class TestJiraBot(BotTestCase): +class TestJiraBot(BotTestCase, DefaultTests): bot_name = 'jira' MOCK_CONFIG_INFO = { diff --git a/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py b/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py index 0eb5d2c..e078fdb 100644 --- a/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py +++ b/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py @@ -1,10 +1,10 @@ from unittest.mock import patch -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import StubBotHandler from zulip_bots.bots.link_shortener.link_shortener import LinkShortenerHandler -class TestLinkShortenerBot(BotTestCase): +class TestLinkShortenerBot(BotTestCase, DefaultTests): bot_name = "link_shortener" def _test(self, message: str, response: str) -> None: diff --git a/zulip_bots/zulip_bots/bots/mention/test_mention.py b/zulip_bots/zulip_bots/bots/mention/test_mention.py index a958c50..1aac508 100644 --- a/zulip_bots/zulip_bots/bots/mention/test_mention.py +++ b/zulip_bots/zulip_bots/bots/mention/test_mention.py @@ -1,9 +1,9 @@ from zulip_bots.bots.mention.mention import MentionHandler from unittest.mock import patch -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import StubBotHandler -class TestMentionBot(BotTestCase): +class TestMentionBot(BotTestCase, DefaultTests): bot_name = "mention" def test_bot_responds_to_empty_message(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/merels/test_merels.py b/zulip_bots/zulip_bots/bots/merels/test_merels.py index b7c5a1e..e1fbf91 100644 --- a/zulip_bots/zulip_bots/bots/merels/test_merels.py +++ b/zulip_bots/zulip_bots/bots/merels/test_merels.py @@ -10,7 +10,7 @@ import zulip_bots.bots.merels.merels import zulip_bots.test_lib -class TestFollowUpBot(zulip_bots.test_lib.BotTestCase): +class TestFollowUpBot(zulip_bots.test_lib.BotTestCase, DefaultTests): bot_name = "merels" def test_no_command(self): diff --git a/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py b/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py index 09f574f..fd06172 100644 --- a/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py +++ b/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py @@ -2,13 +2,13 @@ import unittest from unittest import mock from importlib import import_module -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests # TODO: Figure out a way to test bots that depends # on the Python version of the environment. @unittest.skip("Fails on Python3.4.") -class TestMonkeyTestitBot(BotTestCase): +class TestMonkeyTestitBot(BotTestCase, DefaultTests): bot_name = "monkeytestit" def setUp(self): diff --git a/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py b/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py index e33def3..00d5128 100644 --- a/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py +++ b/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py @@ -1,4 +1,4 @@ -from zulip_bots.test_lib import BotTestCase, StubBotHandler, read_bot_fixture_data +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler, read_bot_fixture_data import simple_salesforce from simple_salesforce.exceptions import SalesforceAuthenticationFailed from contextlib import contextmanager @@ -107,7 +107,7 @@ mock_object_types = { } -class TestSalesforceBot(BotTestCase): +class TestSalesforceBot(BotTestCase, DefaultTests): bot_name = "salesforce" # type: str def _test(self, test_name: str, message: str, response: str, auth_success: bool=True) -> None: diff --git a/zulip_bots/zulip_bots/bots/stack_overflow/test_stack_overflow.py b/zulip_bots/zulip_bots/bots/stack_overflow/test_stack_overflow.py index 8bec785..5904a07 100755 --- a/zulip_bots/zulip_bots/bots/stack_overflow/test_stack_overflow.py +++ b/zulip_bots/zulip_bots/bots/stack_overflow/test_stack_overflow.py @@ -1,7 +1,7 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.request_test_lib import mock_request_exception -class TestStackoverflowBot(BotTestCase): +class TestStackoverflowBot(BotTestCase, DefaultTests): bot_name = "stack_overflow" def test_bot(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/susi/test_susi.py b/zulip_bots/zulip_bots/bots/susi/test_susi.py index a2f4b16..4aa4a65 100644 --- a/zulip_bots/zulip_bots/bots/susi/test_susi.py +++ b/zulip_bots/zulip_bots/bots/susi/test_susi.py @@ -1,10 +1,11 @@ from zulip_bots.test_lib import ( BotTestCase, + DefaultTests, ) from typing import Any -class TestSusiBot(BotTestCase): +class TestSusiBot(BotTestCase, DefaultTests): bot_name = "susi" def test_help(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py b/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py index 93679f0..efb0cc0 100644 --- a/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py +++ b/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py @@ -1,11 +1,11 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.game_handler import GameInstance from unittest.mock import patch from typing import List, Tuple, Any -class TestTicTacToeBot(BotTestCase): +class TestTicTacToeBot(BotTestCase, DefaultTests): bot_name = 'tictactoe' # FIXME: Add tests for computer moves diff --git a/zulip_bots/zulip_bots/bots/trello/test_trello.py b/zulip_bots/zulip_bots/bots/trello/test_trello.py index 3df36cf..ad18a98 100644 --- a/zulip_bots/zulip_bots/bots/trello/test_trello.py +++ b/zulip_bots/zulip_bots/bots/trello/test_trello.py @@ -1,7 +1,7 @@ from unittest.mock import patch from zulip_bots.bots.trello.trello import TrelloHandler -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import StubBotHandler mock_config = { @@ -10,7 +10,7 @@ mock_config = { 'user_name': 'TEST' } -class TestTrelloBot(BotTestCase): +class TestTrelloBot(BotTestCase, DefaultTests): bot_name = "trello" # type: str def test_bot_responds_to_empty_message(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/trivia_quiz/test_trivia_quiz.py b/zulip_bots/zulip_bots/bots/trivia_quiz/test_trivia_quiz.py index 1e8f547..bdd33c4 100644 --- a/zulip_bots/zulip_bots/bots/trivia_quiz/test_trivia_quiz.py +++ b/zulip_bots/zulip_bots/bots/trivia_quiz/test_trivia_quiz.py @@ -5,6 +5,7 @@ from typing import Optional from zulip_bots.test_lib import ( BotTestCase, + DefaultTests, read_bot_fixture_data, ) @@ -12,7 +13,7 @@ from zulip_bots.bots.trivia_quiz.trivia_quiz import ( get_quiz_from_payload, ) -class TestTriviaQuizBot(BotTestCase): +class TestTriviaQuizBot(BotTestCase, DefaultTests): bot_name = "trivia_quiz" # type: str new_question_response = '\nQ: Which class of animals are newts members of?\n\n' + \ diff --git a/zulip_bots/zulip_bots/bots/twitpost/test_twitpost.py b/zulip_bots/zulip_bots/bots/twitpost/test_twitpost.py index 0d77a17..bd5e970 100644 --- a/zulip_bots/zulip_bots/bots/twitpost/test_twitpost.py +++ b/zulip_bots/zulip_bots/bots/twitpost/test_twitpost.py @@ -1,6 +1,7 @@ from zulip_bots.test_lib import ( StubBotHandler, BotTestCase, + DefaultTests, get_bot_message_handler, ) from zulip_bots.test_file_utils import ( @@ -12,7 +13,7 @@ import os import json -class TestTwitpostBot(BotTestCase): +class TestTwitpostBot(BotTestCase, DefaultTests): bot_name = "twitpost" mock_config = {'consumer_key': 'abcdefghijklmnopqrstuvwxy', 'consumer_secret': 'aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy', diff --git a/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py b/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py index 69b26c9..1012d30 100755 --- a/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py +++ b/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py @@ -1,8 +1,8 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.bots.virtual_fs.virtual_fs import sample_conversation from unittest.mock import patch -class TestVirtualFsBot(BotTestCase): +class TestVirtualFsBot(BotTestCase, DefaultTests): bot_name = "virtual_fs" help_txt = ('foo@example.com:\n\nThis bot implements a virtual file system for a stream.\n' 'The locations of text are persisted for the lifetime of the bot\n' diff --git a/zulip_bots/zulip_bots/bots/weather/test_weather.py b/zulip_bots/zulip_bots/bots/weather/test_weather.py index a338339..ee9506e 100644 --- a/zulip_bots/zulip_bots/bots/weather/test_weather.py +++ b/zulip_bots/zulip_bots/bots/weather/test_weather.py @@ -1,9 +1,9 @@ from unittest.mock import patch -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from typing import Optional -class TestWeatherBot(BotTestCase): +class TestWeatherBot(BotTestCase, DefaultTests): bot_name = "weather" help_content = ''' diff --git a/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py b/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py index 0a7e60f..8c7df56 100755 --- a/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py +++ b/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py @@ -1,7 +1,7 @@ -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.request_test_lib import mock_request_exception -class TestWikipediaBot(BotTestCase): +class TestWikipediaBot(BotTestCase, DefaultTests): bot_name = "wikipedia" def test_bot(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/witai/test_witai.py b/zulip_bots/zulip_bots/bots/witai/test_witai.py index 5cb8e49..9f1a980 100644 --- a/zulip_bots/zulip_bots/bots/witai/test_witai.py +++ b/zulip_bots/zulip_bots/bots/witai/test_witai.py @@ -1,9 +1,9 @@ from unittest.mock import patch import sys from typing import Dict, Any, Optional -from zulip_bots.test_lib import BotTestCase, get_bot_message_handler, StubBotHandler +from zulip_bots.test_lib import BotTestCase, DefaultTests, get_bot_message_handler, StubBotHandler -class TestWitaiBot(BotTestCase): +class TestWitaiBot(BotTestCase, DefaultTests): bot_name = 'witai' MOCK_CONFIG_INFO = { diff --git a/zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py b/zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py index c4b80a2..cde20f0 100755 --- a/zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py +++ b/zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py @@ -1,8 +1,8 @@ from unittest import mock from unittest.mock import MagicMock, patch -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests -class TestXkcdBot(BotTestCase): +class TestXkcdBot(BotTestCase, DefaultTests): bot_name = "xkcd" def test_latest_command(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/yoda/test_yoda.py b/zulip_bots/zulip_bots/bots/yoda/test_yoda.py index 9596f14..3ebbde3 100644 --- a/zulip_bots/zulip_bots/bots/yoda/test_yoda.py +++ b/zulip_bots/zulip_bots/bots/yoda/test_yoda.py @@ -1,9 +1,9 @@ from zulip_bots.bots.yoda.yoda import ServiceUnavailableError -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase, DefaultTests from typing import Optional -class TestYodaBot(BotTestCase): +class TestYodaBot(BotTestCase, DefaultTests): bot_name = "yoda" help_text = ''' diff --git a/zulip_bots/zulip_bots/bots/youtube/test_youtube.py b/zulip_bots/zulip_bots/bots/youtube/test_youtube.py index 6273d4b..1ea6ede 100644 --- a/zulip_bots/zulip_bots/bots/youtube/test_youtube.py +++ b/zulip_bots/zulip_bots/bots/youtube/test_youtube.py @@ -1,9 +1,9 @@ from unittest.mock import patch from requests.exceptions import HTTPError, ConnectionError -from zulip_bots.test_lib import StubBotHandler, BotTestCase, get_bot_message_handler +from zulip_bots.test_lib import StubBotHandler, BotTestCase, DefaultTests, get_bot_message_handler from typing import Any, Union, Dict -class TestYoutubeBot(BotTestCase): +class TestYoutubeBot(BotTestCase, DefaultTests): bot_name = "youtube" normal_config = {'key': '12345678', 'number_of_results': '5', diff --git a/zulip_bots/zulip_bots/test_lib.py b/zulip_bots/zulip_bots/test_lib.py index 4a3b190..4fbc186 100755 --- a/zulip_bots/zulip_bots/test_lib.py +++ b/zulip_bots/zulip_bots/test_lib.py @@ -88,6 +88,29 @@ class StubBotHandler: raise Exception('The bot is giving too many responses for some reason.') +class DefaultTests: + bot_name = '' + + def make_request_message(self, content: str) -> Dict[str, Any]: + raise NotImplementedError() + + def get_response(self, message: Dict[str, Any]) -> Dict[str, Any]: + raise NotImplementedError() + + def test_bot_usage(self) -> None: + bot = get_bot_message_handler(self.bot_name) + assert bot.usage() != '' + + def test_bot_responds_to_empty_message(self) -> None: + message = self.make_request_message('') + + # get_response will fail if we don't respond at all + response = self.get_response(message) + + # we also want a non-blank response + assert len(response['content']) >= 1 + + class BotTestCase(unittest.TestCase): bot_name = '' @@ -154,19 +177,6 @@ class BotTestCase(unittest.TestCase): bot_class = type(get_bot_message_handler(self.bot_name)) bot_class.validate_config(config_data) - def test_bot_usage(self) -> None: - bot = get_bot_message_handler(self.bot_name) - self.assertNotEqual(bot.usage(), '') - - def test_bot_responds_to_empty_message(self) -> None: - message = self.make_request_message('') - - # get_response will fail if we don't respond at all - response = self.get_response(message) - - # we also want a non-blank response - self.assertTrue(len(response['content']) >= 1) - def mock_http_conversation(self, test_name: str) -> Any: assert test_name is not None http_data = read_bot_fixture_data(self.bot_name, test_name)