monkeytestit bot tests: Import bot class inside test.

We need to import the bot class inside the tests, so
we are able to temporarily resolve problems with the
bot class by simply skipping the test. It also makes
the code look nicer.
This commit is contained in:
Robert Hönig 2018-05-28 13:25:16 +02:00
parent a8045a8fa9
commit 47c879407c

View file

@ -1,20 +1,22 @@
from unittest import mock from unittest import mock
import zulip_bots.bots.monkeytestit.monkeytestit from importlib import import_module
from zulip_bots.test_lib import BotTestCase from zulip_bots.test_lib import BotTestCase
class TestMonkeyTestitBot(BotTestCase): class TestMonkeyTestitBot(BotTestCase):
bot_name = "monkeytestit" bot_name = "monkeytestit"
def setUp(self):
self.monkeytestit_class = import_module(
"zulip_bots.bots.monkeytestit.monkeytestit").MonkeyTestitBot
def test_bot_responds_to_empty_message(self): def test_bot_responds_to_empty_message(self):
message = dict( message = dict(
content='', content='',
type='stream', type='stream',
) )
with mock.patch.object( with mock.patch.object(self.monkeytestit_class, 'initialize', return_value=None):
zulip_bots.bots.monkeytestit.monkeytestit.MonkeyTestitBot,
'initialize', return_value=None):
with self.mock_config_info({'api_key': "magic"}): with self.mock_config_info({'api_key': "magic"}):
res = self.get_response(message) res = self.get_response(message)
self.assertTrue("Unknown command" in res['content']) self.assertTrue("Unknown command" in res['content'])
@ -24,9 +26,7 @@ class TestMonkeyTestitBot(BotTestCase):
content='check https://website.com', content='check https://website.com',
type='stream', type='stream',
) )
with mock.patch.object( with mock.patch.object(self.monkeytestit_class, 'initialize', return_value=None):
zulip_bots.bots.monkeytestit.monkeytestit.MonkeyTestitBot,
'initialize', return_value=None):
with self.mock_config_info({'api_key': "magic"}): with self.mock_config_info({'api_key': "magic"}):
with self.mock_http_conversation('website_result_fail'): with self.mock_http_conversation('website_result_fail'):
res = self.get_response(message) res = self.get_response(message)
@ -37,9 +37,7 @@ class TestMonkeyTestitBot(BotTestCase):
content='check https://website.com', content='check https://website.com',
type='stream', type='stream',
) )
with mock.patch.object( with mock.patch.object(self.monkeytestit_class, 'initialize', return_value=None):
zulip_bots.bots.monkeytestit.monkeytestit.MonkeyTestitBot,
'initialize', return_value=None):
with self.mock_config_info({'api_key': "magic"}): with self.mock_config_info({'api_key': "magic"}):
with self.mock_http_conversation('website_result_success'): with self.mock_http_conversation('website_result_success'):
res = self.get_response(message) res = self.get_response(message)