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:
Robert Hönig 2017-12-14 11:24:11 +01:00 committed by showell
parent a475077da9
commit b306324bfa
24 changed files with 51 additions and 57 deletions

View file

@ -98,7 +98,7 @@ def main():
for test in tests: for test in tests:
if isinstance(test, TestCase): if isinstance(test, TestCase):
# Exclude test base class from being tested. # Exclude test base class from being tested.
if test.__class__.__name__ not in ['StubBotTestCase', 'BotTestCase']: if test.__class__.__name__ != 'BotTestCase':
filtered_tests.addTest(test) filtered_tests.addTest(test)
else: else:
filtered_tests.addTest(filter_tests(test)) filtered_tests.addTest(filter_tests(test))

View file

@ -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" bot_name = "chess"
START_RESPONSE = '''New game! The board looks like this: START_RESPONSE = '''New game! The board looks like this:

View file

@ -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" bot_name = "converter"
def test_bot(self) -> None: def test_bot(self) -> None:

View file

@ -1,7 +1,7 @@
from zulip_bots.test_lib import StubBotTestCase from zulip_bots.test_lib import BotTestCase
from unittest.mock import patch from unittest.mock import patch
class TestDefineBot(StubBotTestCase): class TestDefineBot(BotTestCase):
bot_name = "define" bot_name = "define"
def test_bot(self) -> None: def test_bot(self) -> None:

View file

@ -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 from contextlib import contextmanager
@ -36,7 +36,7 @@ def mock_dialogflow(test_name: str, bot_name: str) -> Any:
mock_text_request.return_value = request mock_text_request.return_value = request
yield yield
class TestDialogFlowBot(StubBotTestCase): class TestDialogFlowBot(BotTestCase):
bot_name = 'dialogflow' bot_name = 'dialogflow'
def _test(self, test_name: str, message: str, response: str) -> None: def _test(self, test_name: str, message: str, response: str) -> None:

View file

@ -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" bot_name = "encrypt"
def test_bot(self) -> None: def test_bot(self) -> None:

View file

@ -1,13 +1,13 @@
from zulip_bots.test_lib import ( from zulip_bots.test_lib import (
StubBotHandler, StubBotHandler,
StubBotTestCase, BotTestCase,
get_bot_message_handler, get_bot_message_handler,
) )
from typing import Any from typing import Any
class TestFollowUpBot(StubBotTestCase): class TestFollowUpBot(BotTestCase):
bot_name = "followup" bot_name = "followup"
def test_followup_stream(self) -> None: def test_followup_stream(self) -> None:

View file

@ -2,12 +2,12 @@ from unittest.mock import patch
from requests.exceptions import HTTPError, ConnectionError from requests.exceptions import HTTPError, ConnectionError
from typing import Any, Union 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" bot_name = "giphy"
# Override default function in StubBotTestCase # Override default function in BotTestCase
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
# FIXME?: Giphy does not respond to empty messages # FIXME?: Giphy does not respond to empty messages
pass pass

View file

@ -1,12 +1,12 @@
from zulip_bots.test_lib import ( from zulip_bots.test_lib import (
StubBotHandler, StubBotHandler,
StubBotTestCase, BotTestCase,
get_bot_message_handler, get_bot_message_handler,
) )
from typing import Any from typing import Any
class TestGithubDetailBot(StubBotTestCase): class TestGithubDetailBot(BotTestCase):
bot_name = "github_detail" bot_name = "github_detail"
mock_config = {'owner': 'zulip', 'repo': 'zulip'} mock_config = {'owner': 'zulip', 'repo': 'zulip'}
@ -20,7 +20,7 @@ class TestGithubDetailBot(StubBotTestCase):
self.assertIn('displays details on github issues', bot.usage()) 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: def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info(self.mock_config): with self.mock_config_info(self.mock_config):
self.verify_reply('', 'Failed to find any issue or PR.') self.verify_reply('', 'Failed to find any issue or PR.')

View file

@ -1,8 +1,8 @@
from zulip_bots.test_lib import StubBotTestCase from zulip_bots.test_lib import BotTestCase
from unittest.mock import patch from unittest.mock import patch
class TestGoogleSearchBot(StubBotTestCase): class TestGoogleSearchBot(BotTestCase):
bot_name = 'google_search' bot_name = 'google_search'
# Simple query # Simple query

View file

@ -1,7 +1,7 @@
from unittest.mock import patch from unittest.mock import patch
from requests.exceptions import ConnectionError 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 from zulip_bots.bots.google_translate.google_translate import TranslateError
help_text = ''' help_text = '''
@ -11,7 +11,7 @@ Please format your message like:
Visit [here](https://cloud.google.com/translate/docs/languages) for all languages Visit [here](https://cloud.google.com/translate/docs/languages) for all languages
''' '''
class TestGoogleTranslateBot(StubBotTestCase): class TestGoogleTranslateBot(BotTestCase):
bot_name = "google_translate" bot_name = "google_translate"
def _test(self, message, response, http_config_fixture, http_fixture=None): def _test(self, message, response, http_config_fixture, http_fixture=None):
@ -43,7 +43,7 @@ class TestGoogleTranslateBot(StubBotTestCase):
'Translate Error. Invalid API Key..', 'Translate Error. Invalid API Key..',
'test_languages', 'test_403') 'test_languages', 'test_403')
# Override default function in StubBotTestCase # Override default function in BotTestCase
def test_bot_responds_to_empty_message(self): def test_bot_responds_to_empty_message(self):
self._test('', help_text, 'test_languages') self._test('', help_text, 'test_languages')

View file

@ -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 bot_name = "helloworld" # type: str
def test_bot(self) -> None: def test_bot(self) -> None:

View file

@ -1,8 +1,8 @@
from zulip_bots.test_lib import StubBotTestCase from zulip_bots.test_lib import BotTestCase
from typing import Any from typing import Any
class TestHelpBot(StubBotTestCase): class TestHelpBot(BotTestCase):
bot_name = "help" bot_name = "help"
def test_bot(self) -> None: def test_bot(self) -> None:

View file

@ -3,10 +3,10 @@ import mock
from zulip_bots.test_lib import ( from zulip_bots.test_lib import (
get_bot_message_handler, get_bot_message_handler,
StubBotHandler, StubBotHandler,
StubBotTestCase, BotTestCase,
) )
class TestIncrementorBot(StubBotTestCase): class TestIncrementorBot(BotTestCase):
bot_name = "incrementor" bot_name = "incrementor"
def test_bot(self) -> None: def test_bot(self) -> None:

View file

@ -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" bot_name = "link_shortener"
def _test(self, message: str, response: str) -> None: def _test(self, message: str, response: str) -> None:

View file

@ -1,8 +1,8 @@
from zulip_bots.test_lib import StubBotTestCase from zulip_bots.test_lib import BotTestCase
from mock import patch from mock import patch
class TestTictactoeBot(StubBotTestCase): class TestTictactoeBot(BotTestCase):
bot_name = 'tictactoe' bot_name = 'tictactoe'
def test_bot(self): def test_bot(self):

View file

@ -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" bot_name = "virtual_fs"
help_txt = ('foo@example.com:\n\nThis bot implements a virtual file system for a stream.\n' 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' 'The locations of text are persisted for the lifetime of the bot\n'

View file

@ -1,8 +1,8 @@
from zulip_bots.test_lib import StubBotTestCase from zulip_bots.test_lib import BotTestCase
from typing import Optional from typing import Optional
class TestWeatherBot(StubBotTestCase): class TestWeatherBot(BotTestCase):
bot_name = "weather" bot_name = "weather"
help_content = ''' help_content = '''
@ -23,7 +23,7 @@ class TestWeatherBot(StubBotTestCase):
else: else:
self.verify_reply(message, response) self.verify_reply(message, response)
# Override default function in StubBotTestCase # Override default function in BotTestCase
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
self._test('', self.help_content) self._test('', self.help_content)

View file

@ -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 from zulip_bots.request_test_lib import mock_request_exception
class TestWikipediaBot(StubBotTestCase): class TestWikipediaBot(BotTestCase):
bot_name = "wikipedia" bot_name = "wikipedia"
def test_bot(self) -> None: def test_bot(self) -> None:

View file

@ -1,8 +1,8 @@
import mock import mock
from mock import MagicMock, patch 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" bot_name = "xkcd"
def test_latest_command(self) -> None: def test_latest_command(self) -> None:

View file

@ -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" bot_name = "yoda"
help_text = ''' help_text = '''
@ -25,7 +25,7 @@ class TestYodaBot(StubBotTestCase):
else: else:
self.verify_reply(message, response) self.verify_reply(message, response)
# Override default function in StubBotTestCase # Override default function in BotTestCase
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
self._test('', self.help_text) self._test('', self.help_text)

View file

@ -98,7 +98,7 @@
"publishedAt": "2017-12-07T19:00:01.000Z", "publishedAt": "2017-12-07T19:00:01.000Z",
"channelId": "UCxwitsUVNzwS5XBSC5UQV8Q", "channelId": "UCxwitsUVNzwS5XBSC5UQV8Q",
"title": "MARVEL RISING BEGINS! | The Next Generation of Marvel Heroes (EXCLUSIVE)", "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": { "thumbnails": {
"default": { "default": {
"url": "https://i.ytimg.com/vi/6HTPCTtkWoA/default.jpg", "url": "https://i.ytimg.com/vi/6HTPCTtkWoA/default.jpg",

View file

@ -1,9 +1,9 @@
from unittest.mock import patch from unittest.mock import patch
from requests.exceptions import HTTPError, ConnectionError 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 from typing import Any, Union, Dict
class TestYoutubeBot(StubBotTestCase): class TestYoutubeBot(BotTestCase):
bot_name = "youtube" bot_name = "youtube"
normal_config = {'key': '12345678', normal_config = {'key': '12345678',
'number_of_results': '5', 'number_of_results': '5',
@ -18,7 +18,7 @@ class TestYoutubeBot(StubBotTestCase):
" * @mention-bot funny cats\n" \ " * @mention-bot funny cats\n" \
" * @mention-bot list funny dogs" " * @mention-bot list funny dogs"
# Override default function in StubBotTestCase # Override default function in BotTestCase
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info(self.normal_config), \ with self.mock_config_info(self.normal_config), \
self.mock_http_conversation('test_keyok'): self.mock_http_conversation('test_keyok'):

View file

@ -77,13 +77,7 @@ class StubBotHandler:
if len(responses) > 1: if len(responses) > 1:
raise Exception('The bot is giving too many responses for some reason.') raise Exception('The bot is giving too many responses for some reason.')
class StubBotTestCase(TestCase): class BotTestCase(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.
'''
bot_name = '' bot_name = ''
def _get_handlers(self): def _get_handlers(self):