lib_tests.py: Set realistic spec for BotHandler mock.
This commit is contained in:
parent
f74c94ba04
commit
7dcec207eb
|
@ -1,5 +1,5 @@
|
||||||
from unittest import TestCase
|
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 (
|
from zulip_bots.lib import (
|
||||||
ExternalBotHandler,
|
ExternalBotHandler,
|
||||||
StateHandler,
|
StateHandler,
|
||||||
|
@ -34,6 +34,16 @@ class FakeClient:
|
||||||
def send_message(self, message):
|
def send_message(self, message):
|
||||||
pass
|
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):
|
class LibTest(TestCase):
|
||||||
def test_basics(self):
|
def test_basics(self):
|
||||||
client = FakeClient()
|
client = FakeClient()
|
||||||
|
@ -99,7 +109,7 @@ class LibTest(TestCase):
|
||||||
mock_lib_module = MagicMock()
|
mock_lib_module = MagicMock()
|
||||||
# __file__ is not mocked by MagicMock(), so we assign a mock value manually.
|
# __file__ is not mocked by MagicMock(), so we assign a mock value manually.
|
||||||
mock_lib_module.__file__ = "foo"
|
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
|
mock_lib_module.handler_class.return_value = mock_bot_handler
|
||||||
|
|
||||||
def call_on_each_event_mock(self, callback, event_types=None, narrow=None):
|
def call_on_each_event_mock(self, callback, event_types=None, narrow=None):
|
||||||
|
|
Loading…
Reference in a new issue