Rewrite incrementor bot tests.
Using StubBotHandler makes it fairly easy to verify the key feature of the incrementor bot, which is that it updates messages sequentially.
This commit is contained in:
parent
fc251460fa
commit
c0ceb9857f
|
@ -1,33 +1,31 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
import mock
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from zulip_bots.test_lib import (
|
||||||
from __future__ import print_function
|
get_bot_message_handler,
|
||||||
|
StubBotHandler,
|
||||||
|
StubBotTestCase,
|
||||||
|
)
|
||||||
|
|
||||||
from zulip_bots.test_lib import BotTestCase
|
class TestIncrementorBot(StubBotTestCase):
|
||||||
from zulip_bots.lib import StateHandler
|
|
||||||
|
|
||||||
|
|
||||||
class TestIncrementorBot(BotTestCase):
|
|
||||||
bot_name = "incrementor"
|
bot_name = "incrementor"
|
||||||
|
|
||||||
def test_bot(self):
|
def test_bot(self):
|
||||||
self.initialize_bot()
|
bot = get_bot_message_handler(self.bot_name)
|
||||||
messages = [ # Template for message inputs to test, absent of message content
|
bot_handler = StubBotHandler()
|
||||||
{
|
|
||||||
'type': 'stream',
|
|
||||||
'display_recipient': 'some stream',
|
|
||||||
'subject': 'some subject',
|
|
||||||
'sender_email': 'foo_sender@zulip.com',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'private',
|
|
||||||
'sender_email': 'foo_sender@zulip.com',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
self.assert_bot_response(dict(messages[0], content=""), {'content': "1"},
|
|
||||||
'send_reply')
|
|
||||||
# Last test commented out since we don't have update_message
|
|
||||||
# support in the test framework yet.
|
|
||||||
|
|
||||||
# self.assert_bot_response(dict(messages[0], content=""), {'message_id': 5, 'content': "2"},
|
message = dict(type='stream')
|
||||||
# 'update_message', storage)
|
|
||||||
|
bot.initialize(bot_handler)
|
||||||
|
bot.handle_message(message, bot_handler)
|
||||||
|
|
||||||
|
with mock.patch('zulip_bots.simple_lib.SimpleMessageServer.update') as m:
|
||||||
|
bot.handle_message(message, bot_handler)
|
||||||
|
bot.handle_message(message, bot_handler)
|
||||||
|
bot.handle_message(message, bot_handler)
|
||||||
|
|
||||||
|
content_updates = [
|
||||||
|
item[0][0]['content']
|
||||||
|
for item in m.call_args_list
|
||||||
|
]
|
||||||
|
self.assertEqual(content_updates, ['2', '3', '4'])
|
||||||
|
|
Loading…
Reference in a new issue