From 47c879407c72451ac0cd4f4db06ef4a40b4a1ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6nig?= Date: Mon, 28 May 2018 13:25:16 +0200 Subject: [PATCH] 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. --- .../bots/monkeytestit/test_monkeytestit.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py b/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py index ba9f37c..4ee6720 100644 --- a/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py +++ b/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py @@ -1,20 +1,22 @@ from unittest import mock -import zulip_bots.bots.monkeytestit.monkeytestit +from importlib import import_module from zulip_bots.test_lib import BotTestCase class TestMonkeyTestitBot(BotTestCase): 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): message = dict( content='', type='stream', ) - with mock.patch.object( - zulip_bots.bots.monkeytestit.monkeytestit.MonkeyTestitBot, - 'initialize', return_value=None): + with mock.patch.object(self.monkeytestit_class, 'initialize', return_value=None): with self.mock_config_info({'api_key': "magic"}): res = self.get_response(message) self.assertTrue("Unknown command" in res['content']) @@ -24,9 +26,7 @@ class TestMonkeyTestitBot(BotTestCase): content='check https://website.com', type='stream', ) - with mock.patch.object( - zulip_bots.bots.monkeytestit.monkeytestit.MonkeyTestitBot, - 'initialize', return_value=None): + with mock.patch.object(self.monkeytestit_class, 'initialize', return_value=None): with self.mock_config_info({'api_key': "magic"}): with self.mock_http_conversation('website_result_fail'): res = self.get_response(message) @@ -37,9 +37,7 @@ class TestMonkeyTestitBot(BotTestCase): content='check https://website.com', type='stream', ) - with mock.patch.object( - zulip_bots.bots.monkeytestit.monkeytestit.MonkeyTestitBot, - 'initialize', return_value=None): + with mock.patch.object(self.monkeytestit_class, 'initialize', return_value=None): with self.mock_config_info({'api_key': "magic"}): with self.mock_http_conversation('website_result_success'): res = self.get_response(message)