zulip_bots: Make BotTestCase the only helper library.
Renames StubBotTestCase to BotTestCase and removes legacy code for supporting both names.
This commit is contained in:
parent
a475077da9
commit
b306324bfa
|
@ -98,7 +98,7 @@ def main():
|
|||
for test in tests:
|
||||
if isinstance(test, TestCase):
|
||||
# Exclude test base class from being tested.
|
||||
if test.__class__.__name__ not in ['StubBotTestCase', 'BotTestCase']:
|
||||
if test.__class__.__name__ != 'BotTestCase':
|
||||
filtered_tests.addTest(test)
|
||||
else:
|
||||
filtered_tests.addTest(filter_tests(test))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
class TestChessBot(StubBotTestCase):
|
||||
class TestChessBot(BotTestCase):
|
||||
bot_name = "chess"
|
||||
|
||||
START_RESPONSE = '''New game! The board looks like this:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
class TestConverterBot(StubBotTestCase):
|
||||
class TestConverterBot(BotTestCase):
|
||||
bot_name = "converter"
|
||||
|
||||
def test_bot(self) -> None:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
from unittest.mock import patch
|
||||
|
||||
class TestDefineBot(StubBotTestCase):
|
||||
class TestDefineBot(BotTestCase):
|
||||
bot_name = "define"
|
||||
|
||||
def test_bot(self) -> None:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase, read_bot_fixture_data
|
||||
from zulip_bots.test_lib import BotTestCase, read_bot_fixture_data
|
||||
|
||||
from contextlib import contextmanager
|
||||
|
||||
|
@ -36,7 +36,7 @@ def mock_dialogflow(test_name: str, bot_name: str) -> Any:
|
|||
mock_text_request.return_value = request
|
||||
yield
|
||||
|
||||
class TestDialogFlowBot(StubBotTestCase):
|
||||
class TestDialogFlowBot(BotTestCase):
|
||||
bot_name = 'dialogflow'
|
||||
|
||||
def _test(self, test_name: str, message: str, response: str) -> None:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
class TestEncryptBot(StubBotTestCase):
|
||||
class TestEncryptBot(BotTestCase):
|
||||
bot_name = "encrypt"
|
||||
|
||||
def test_bot(self) -> None:
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
from zulip_bots.test_lib import (
|
||||
StubBotHandler,
|
||||
StubBotTestCase,
|
||||
BotTestCase,
|
||||
get_bot_message_handler,
|
||||
)
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
class TestFollowUpBot(StubBotTestCase):
|
||||
class TestFollowUpBot(BotTestCase):
|
||||
bot_name = "followup"
|
||||
|
||||
def test_followup_stream(self) -> None:
|
||||
|
|
|
@ -2,12 +2,12 @@ from unittest.mock import patch
|
|||
from requests.exceptions import HTTPError, ConnectionError
|
||||
|
||||
from typing import Any, Union
|
||||
from zulip_bots.test_lib import StubBotHandler, StubBotTestCase, get_bot_message_handler
|
||||
from zulip_bots.test_lib import StubBotHandler, BotTestCase, get_bot_message_handler
|
||||
|
||||
class TestGiphyBot(StubBotTestCase):
|
||||
class TestGiphyBot(BotTestCase):
|
||||
bot_name = "giphy"
|
||||
|
||||
# Override default function in StubBotTestCase
|
||||
# Override default function in BotTestCase
|
||||
def test_bot_responds_to_empty_message(self) -> None:
|
||||
# FIXME?: Giphy does not respond to empty messages
|
||||
pass
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
from zulip_bots.test_lib import (
|
||||
StubBotHandler,
|
||||
StubBotTestCase,
|
||||
BotTestCase,
|
||||
get_bot_message_handler,
|
||||
)
|
||||
|
||||
from typing import Any
|
||||
|
||||
class TestGithubDetailBot(StubBotTestCase):
|
||||
class TestGithubDetailBot(BotTestCase):
|
||||
bot_name = "github_detail"
|
||||
mock_config = {'owner': 'zulip', 'repo': 'zulip'}
|
||||
|
||||
|
@ -20,7 +20,7 @@ class TestGithubDetailBot(StubBotTestCase):
|
|||
|
||||
self.assertIn('displays details on github issues', bot.usage())
|
||||
|
||||
# Override default function in StubBotTestCase
|
||||
# Override default function in BotTestCase
|
||||
def test_bot_responds_to_empty_message(self) -> None:
|
||||
with self.mock_config_info(self.mock_config):
|
||||
self.verify_reply('', 'Failed to find any issue or PR.')
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
class TestGoogleSearchBot(StubBotTestCase):
|
||||
class TestGoogleSearchBot(BotTestCase):
|
||||
bot_name = 'google_search'
|
||||
|
||||
# Simple query
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from unittest.mock import patch
|
||||
from requests.exceptions import ConnectionError
|
||||
|
||||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
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(StubBotTestCase):
|
||||
class TestGoogleTranslateBot(BotTestCase):
|
||||
bot_name = "google_translate"
|
||||
|
||||
def _test(self, message, response, http_config_fixture, http_fixture=None):
|
||||
|
@ -43,7 +43,7 @@ class TestGoogleTranslateBot(StubBotTestCase):
|
|||
'Translate Error. Invalid API Key..',
|
||||
'test_languages', 'test_403')
|
||||
|
||||
# Override default function in StubBotTestCase
|
||||
# Override default function in BotTestCase
|
||||
def test_bot_responds_to_empty_message(self):
|
||||
self._test('', help_text, 'test_languages')
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
class TestHelpBot(StubBotTestCase):
|
||||
class TestHelpBot(BotTestCase):
|
||||
bot_name = "helloworld" # type: str
|
||||
|
||||
def test_bot(self) -> None:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
from typing import Any
|
||||
|
||||
class TestHelpBot(StubBotTestCase):
|
||||
class TestHelpBot(BotTestCase):
|
||||
bot_name = "help"
|
||||
|
||||
def test_bot(self) -> None:
|
||||
|
|
|
@ -3,10 +3,10 @@ import mock
|
|||
from zulip_bots.test_lib import (
|
||||
get_bot_message_handler,
|
||||
StubBotHandler,
|
||||
StubBotTestCase,
|
||||
BotTestCase,
|
||||
)
|
||||
|
||||
class TestIncrementorBot(StubBotTestCase):
|
||||
class TestIncrementorBot(BotTestCase):
|
||||
bot_name = "incrementor"
|
||||
|
||||
def test_bot(self) -> None:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
class TestLinkShortenerBot(StubBotTestCase):
|
||||
class TestLinkShortenerBot(BotTestCase):
|
||||
bot_name = "link_shortener"
|
||||
|
||||
def _test(self, message: str, response: str) -> None:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
from mock import patch
|
||||
|
||||
class TestTictactoeBot(StubBotTestCase):
|
||||
class TestTictactoeBot(BotTestCase):
|
||||
bot_name = 'tictactoe'
|
||||
|
||||
def test_bot(self):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
class TestVirtualFsBot(StubBotTestCase):
|
||||
class TestVirtualFsBot(BotTestCase):
|
||||
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'
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
from typing import Optional
|
||||
|
||||
class TestWeatherBot(StubBotTestCase):
|
||||
class TestWeatherBot(BotTestCase):
|
||||
bot_name = "weather"
|
||||
|
||||
help_content = '''
|
||||
|
@ -23,7 +23,7 @@ class TestWeatherBot(StubBotTestCase):
|
|||
else:
|
||||
self.verify_reply(message, response)
|
||||
|
||||
# Override default function in StubBotTestCase
|
||||
# Override default function in BotTestCase
|
||||
def test_bot_responds_to_empty_message(self) -> None:
|
||||
self._test('', self.help_content)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
from zulip_bots.request_test_lib import mock_request_exception
|
||||
|
||||
class TestWikipediaBot(StubBotTestCase):
|
||||
class TestWikipediaBot(BotTestCase):
|
||||
bot_name = "wikipedia"
|
||||
|
||||
def test_bot(self) -> None:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import mock
|
||||
from mock import MagicMock, patch
|
||||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
class TestXkcdBot(StubBotTestCase):
|
||||
class TestXkcdBot(BotTestCase):
|
||||
bot_name = "xkcd"
|
||||
|
||||
def test_latest_command(self) -> None:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from zulip_bots.test_lib import StubBotTestCase
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
class TestYodaBot(StubBotTestCase):
|
||||
class TestYodaBot(BotTestCase):
|
||||
bot_name = "yoda"
|
||||
|
||||
help_text = '''
|
||||
|
@ -25,7 +25,7 @@ class TestYodaBot(StubBotTestCase):
|
|||
else:
|
||||
self.verify_reply(message, response)
|
||||
|
||||
# Override default function in StubBotTestCase
|
||||
# Override default function in BotTestCase
|
||||
def test_bot_responds_to_empty_message(self) -> None:
|
||||
self._test('', self.help_text)
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@
|
|||
"publishedAt": "2017-12-07T19:00:01.000Z",
|
||||
"channelId": "UCxwitsUVNzwS5XBSC5UQV8Q",
|
||||
"title": "MARVEL RISING BEGINS! | The Next Generation of Marvel Heroes (EXCLUSIVE)",
|
||||
"description": "With “Marvel Rising,” the next generation of Marvel heroes has arrived. Rising 2018. --- Cast: Kathleen Khavari – Kamala Khan/Ms. Marvel Milana Vayntrub – Doreen Green/Squirrel Girl...",
|
||||
"description": "With “Marvel Rising,” the next generation of Marvel heroes has arrived. Rising 2018. --- Cast: Kathleen Khavari – Kamala KhanM Marvel Milana Vayntrub – Doreen Green/Squirrel Girl...",
|
||||
"thumbnails": {
|
||||
"default": {
|
||||
"url": "https://i.ytimg.com/vi/6HTPCTtkWoA/default.jpg",
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from unittest.mock import patch
|
||||
from requests.exceptions import HTTPError, ConnectionError
|
||||
|
||||
from zulip_bots.test_lib import StubBotHandler, StubBotTestCase, get_bot_message_handler
|
||||
from zulip_bots.test_lib import StubBotHandler, BotTestCase, get_bot_message_handler
|
||||
from typing import Any, Union, Dict
|
||||
class TestYoutubeBot(StubBotTestCase):
|
||||
class TestYoutubeBot(BotTestCase):
|
||||
bot_name = "youtube"
|
||||
normal_config = {'key': '12345678',
|
||||
'number_of_results': '5',
|
||||
|
@ -18,7 +18,7 @@ class TestYoutubeBot(StubBotTestCase):
|
|||
" * @mention-bot funny cats\n" \
|
||||
" * @mention-bot list funny dogs"
|
||||
|
||||
# Override default function in StubBotTestCase
|
||||
# Override default function in BotTestCase
|
||||
def test_bot_responds_to_empty_message(self) -> None:
|
||||
with self.mock_config_info(self.normal_config), \
|
||||
self.mock_http_conversation('test_keyok'):
|
||||
|
|
|
@ -77,13 +77,7 @@ class StubBotHandler:
|
|||
if len(responses) > 1:
|
||||
raise Exception('The bot is giving too many responses for some reason.')
|
||||
|
||||
class StubBotTestCase(TestCase):
|
||||
'''
|
||||
The goal for this class is to eventually replace
|
||||
BotTestCase for places where we may want more
|
||||
fine-grained control and less heavy setup.
|
||||
'''
|
||||
|
||||
class BotTestCase(TestCase):
|
||||
bot_name = ''
|
||||
|
||||
def _get_handlers(self):
|
||||
|
|
Loading…
Reference in a new issue