bot tests: Adjust TestCase inheritance to avoid need to skip/filter.

Previously the test-bots script filtered out base-class tests from
BotTestCase. With this change, BotTestCase continues to inherit from
unittest.TestCase, but the default test_* methods previously in this
class are now in a new DefaultTests class, which does not. Instead, each
bot needs to inherit from BotTestCase and DefaultTests *explicitly*.

This avoids the need to filter out the base-class tests, which
simplifies the test-bots script, and may ease any migration to eg.
pytest.

The DefaultTests class does require some non-implemented methods which
BotTestCase provides.
This commit is contained in:
neiljp (Neil Pilgrim) 2018-06-08 14:30:50 -07:00 committed by showell
parent c636a5ac49
commit 6cdb83ce72
43 changed files with 105 additions and 102 deletions

View file

@ -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)