lib_tests.py: Set realistic spec for BotHandler mock.

This commit is contained in:
Robert Hönig 2018-02-11 10:58:17 +01:00 committed by Tim Abbott
parent f74c94ba04
commit 7dcec207eb

View file

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