Commit e0f93c7e authored by Nitanshu's avatar Nitanshu Committed by Guillaume Binet (argo.ai)

TestBot: Add multi-line command test support (#1238)

parent a0f35732
......@@ -2,6 +2,7 @@ import importlib
import logging
import sys
import unittest
import textwrap
from os.path import sep, abspath
from queue import Queue
from tempfile import mkdtemp
......@@ -450,8 +451,10 @@ class TestBot(object):
def zap_queues(self):
return self.bot.zap_queues()
def assertCommand(self, command, response, timeout=5):
def assertCommand(self, command, response, timeout=5, dedent=False):
"""Assert the given command returns the given response"""
if dedent:
command = '\n'.join(textwrap.dedent(command).splitlines()[1:])
self.bot.push_message(command)
msg = self.bot.pop_message(timeout)
assert response in msg, f'{response} not in {msg}.'
......
......@@ -364,3 +364,15 @@ def test_mock_injection(testbot):
mock_dict = {'helper_method': helper_mock}
testbot.inject_mocks('Dummy', mock_dict)
assert 'foo' in testbot.exec_command('!baz')
def test_multiline_command(testbot):
testbot.assertCommand(
'''
!bar title
first line of body
second line of body
''',
'!bar title\nfirst line of body\nsecond line of body',
dedent=True
)
......@@ -37,3 +37,8 @@ class DummyTest(BotPlugin):
def baz(self, msg, args):
"""Tests mock injection method"""
return self.helper_method('baz')
@botcmd
def bar(self, msg, args):
"""This runs bar."""
return msg
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment