zulip_bots: Add common tests.
unittest includes by default all module-level classes that inherit from TestCase and implement at least one method starting with 'test'. Since it doesn't provide a convenient way for excluding TestSuites, we need to manually filter out the unwanted testing of our test base class itself.
This commit is contained in:
parent
94b7c2eaef
commit
9c37f92a01
3 changed files with 34 additions and 5 deletions
|
@ -5,10 +5,18 @@ from __future__ import print_function
|
|||
|
||||
import json
|
||||
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
from zulip_bots.test_lib import BotTestCaseBase
|
||||
|
||||
class TestGithubDetailBot(BotTestCase):
|
||||
class TestGithubDetailBot(BotTestCaseBase):
|
||||
bot_name = "github_detail"
|
||||
mock_config = {'owner': 'zulip', 'repo': 'zulip'}
|
||||
|
||||
# Overrides default test_bot_usage().
|
||||
def test_bot_usage(self):
|
||||
# type: () -> None
|
||||
with self.mock_config_info(self.mock_config):
|
||||
self.initialize_bot()
|
||||
self.assertNotEqual(self.message_handler.usage(), '')
|
||||
|
||||
def test_issue(self):
|
||||
bot_response = '**[zulip/zulip#5365](https://github.com/zulip/zulip/issues/5365)'\
|
||||
|
@ -75,8 +83,7 @@ class TestGithubDetailBot(BotTestCase):
|
|||
'the default repo is zulip.'
|
||||
# This message calls the `send_reply` function of BotHandlerApi
|
||||
|
||||
mock_config = {'owner': 'zulip', 'repo': 'zulip'}
|
||||
with self.mock_config_info(mock_config):
|
||||
with self.mock_config_info(self.mock_config):
|
||||
self.initialize_bot()
|
||||
self.assert_bot_response(
|
||||
message = {'content': 'help'},
|
||||
|
|
|
@ -26,7 +26,8 @@ from types import ModuleType
|
|||
|
||||
from copy import deepcopy
|
||||
|
||||
class BotTestCase(TestCase):
|
||||
class BotTestCaseBase(TestCase):
|
||||
"""Test class for common Bot test helper methods"""
|
||||
bot_name = '' # type: str
|
||||
|
||||
def get_bot_message_handler(self):
|
||||
|
@ -153,3 +154,10 @@ class BotTestCase(TestCase):
|
|||
# Strictly speaking, this function is not needed anymore,
|
||||
# kept for now for legacy reasons.
|
||||
self.call_request(message, expected_method, response)
|
||||
|
||||
class BotTestCase(BotTestCaseBase):
|
||||
"""Test class extending BotTestCaseBase to add common default tests
|
||||
that should be run (by default) for all our bots"""
|
||||
def test_bot_usage(self):
|
||||
# type: () -> None
|
||||
self.assertNotEqual(self.message_handler.usage(), '')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue