From 7dcec207eb3984ac8163a033fb19923b5a3518cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6nig?= Date: Sun, 11 Feb 2018 10:58:17 +0100 Subject: [PATCH] lib_tests.py: Set realistic spec for BotHandler mock. --- zulip_bots/zulip_bots/lib_tests.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/zulip_bots/zulip_bots/lib_tests.py b/zulip_bots/zulip_bots/lib_tests.py index 86803fe..5116c5a 100644 --- a/zulip_bots/zulip_bots/lib_tests.py +++ b/zulip_bots/zulip_bots/lib_tests.py @@ -1,5 +1,5 @@ from unittest import TestCase -from unittest.mock import MagicMock, patch, ANY +from unittest.mock import MagicMock, patch, ANY, create_autospec from zulip_bots.lib import ( ExternalBotHandler, StateHandler, @@ -34,6 +34,16 @@ class FakeClient: def send_message(self, message): pass +class FakeBotHandler: + def usage(self): + return ''' + This is a fake bot handler that is used + to spec BotHandler mocks. + ''' + + def handle_message(self, message, bot_handler): + pass + class LibTest(TestCase): def test_basics(self): client = FakeClient() @@ -99,7 +109,7 @@ class LibTest(TestCase): mock_lib_module = MagicMock() # __file__ is not mocked by MagicMock(), so we assign a mock value manually. mock_lib_module.__file__ = "foo" - mock_bot_handler = MagicMock() + mock_bot_handler = create_autospec(FakeBotHandler) mock_lib_module.handler_class.return_value = mock_bot_handler def call_on_each_event_mock(self, callback, event_types=None, narrow=None):