bots: Add mock test for 'send_message' function in 'bots_test_lib' file.

Since few bots directly call 'send_message' function of
'BotHandlerApi' class instead of calling 'send_reply' function
first, add 'mock_test_send_message' to check for 'send_message'
function.

All test_<bot>.py files now need to specify which function the bot
will be sending the response to, for each particular message.

Make 'test_virtual_fs.py' and 'test_thesaurus.py' test files
consistent with other bots.
This commit is contained in:
Abhijeet Kaur 2017-05-29 05:24:32 +05:30 committed by Tim Abbott
parent 894adb1e43
commit e857a97427
3 changed files with 98 additions and 106 deletions

View file

@ -17,32 +17,17 @@ class TestThesaurusBot(BotTestCase):
bot_name = "thesaurus"
def test_bot(self):
self.assert_bot_output(
{'content': "synonym good", 'type': "private", 'sender_email': "foo"},
"great, satisfying, exceptional, positive, acceptable"
)
self.assert_bot_output(
{'content': "synonym nice", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
"cordial, kind, good, okay, fair"
)
self.assert_bot_output(
{'content': "synonym foo", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
"bar, thud, X, baz, corge"
)
self.assert_bot_output(
{'content': "antonym dirty", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
"ordered, sterile, spotless, moral, clean"
)
self.assert_bot_output(
{'content': "antonym bar", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
"loss, whole, advantage, aid, failure"
)
self.assert_bot_output(
{'content': "", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
("To use this bot, start messages with either "
"@mention-bot synonym (to get the synonyms of a given word) "
"or @mention-bot antonym (to get the antonyms of a given word). "
"Phrases are not accepted so only use single words "
"to search. For example you could search '@mention-bot synonym hello' "
"or '@mention-bot antonym goodbye'."),
)
expected = {
"synonym good": "great, satisfying, exceptional, positive, acceptable",
"synonym nice": "cordial, kind, good, okay, fair",
"synonym foo": "bar, thud, X, baz, corge",
"antonym dirty": "ordered, sterile, spotless, moral, clean",
"antonym bar": "loss, whole, advantage, aid, failure",
"": ("To use this bot, start messages with either "
"@mention-bot synonym (to get the synonyms of a given word) "
"or @mention-bot antonym (to get the antonyms of a given word). "
"Phrases are not accepted so only use single words "
"to search. For example you could search '@mention-bot synonym hello' "
"or '@mention-bot antonym goodbye'."),
}
self.check_expected_responses(expected)

View file

@ -17,55 +17,40 @@ class TestVirtualFsBot(BotTestCase):
bot_name = "virtual_fs"
def test_bot(self):
self.assert_bot_output(
{'content': "cd /home", 'type': "private", 'display_recipient': "foo", 'sender_email': "foo_sender@zulip.com"},
"foo_sender@zulip.com:\nERROR: invalid path"
)
self.assert_bot_output(
{'content': "mkdir home", 'type': "stream", 'display_recipient': "foo", 'subject': "foo", 'sender_email': "foo_sender@zulip.com"},
"foo_sender@zulip.com:\ndirectory created"
)
self.assert_bot_output(
{'content': "pwd", 'type': "stream", 'display_recipient': "foo", 'subject': "foo", 'sender_email': "foo_sender@zulip.com"},
"foo_sender@zulip.com:\n/"
)
self.assert_bot_output(
{'content': "help", 'type': "stream", 'display_recipient': "foo", 'subject': "foo", 'sender_email': "foo_sender@zulip.com"},
('foo_sender@zulip.com:\n\nThis bot implements a virtual file system for a stream.\n'
'The locations of text are persisted for the lifetime of the bot\n'
'running, and if you rename a stream, you will lose the info.\n'
'Example commands:\n\n```\n'
'@mention-bot sample_conversation: sample conversation with the bot\n'
'@mention-bot mkdir: create a directory\n'
'@mention-bot ls: list a directory\n'
'@mention-bot cd: change directory\n'
'@mention-bot pwd: show current path\n'
'@mention-bot write: write text\n'
'@mention-bot read: read text\n'
'@mention-bot rm: remove a file\n'
'@mention-bot rmdir: remove a directory\n'
'```\n'
'Use commands like `@mention-bot help write` for more details on specific\ncommands.\n'),
)
self.assert_bot_output(
{'content': "help ls", 'type': "stream", 'display_recipient': "foo", 'subject': "foo", 'sender_email': "foo_sender@zulip.com"},
"foo_sender@zulip.com:\nsyntax: ls <optional_path>"
)
self.assert_bot_output(
{'content': "", 'type': "stream", 'display_recipient': "foo", 'subject': "foo", 'sender_email': "foo_sender@zulip.com"},
('foo_sender@zulip.com:\n\nThis bot implements a virtual file system for a stream.\n'
'The locations of text are persisted for the lifetime of the bot\n'
'running, and if you rename a stream, you will lose the info.\n'
'Example commands:\n\n```\n'
'@mention-bot sample_conversation: sample conversation with the bot\n'
'@mention-bot mkdir: create a directory\n'
'@mention-bot ls: list a directory\n'
'@mention-bot cd: change directory\n'
'@mention-bot pwd: show current path\n'
'@mention-bot write: write text\n'
'@mention-bot read: read text\n'
'@mention-bot rm: remove a file\n'
'@mention-bot rmdir: remove a directory\n'
'```\n'
'Use commands like `@mention-bot help write` for more details on specific\ncommands.\n'),
)
expected = {
"cd /home": "foo_sender@zulip.com:\nERROR: invalid path",
"mkdir home": "foo_sender@zulip.com:\ndirectory created",
"pwd": "foo_sender@zulip.com:\n/",
"help": ('foo_sender@zulip.com:\n\nThis bot implements a virtual file system for a stream.\n'
'The locations of text are persisted for the lifetime of the bot\n'
'running, and if you rename a stream, you will lose the info.\n'
'Example commands:\n\n```\n'
'@mention-bot sample_conversation: sample conversation with the bot\n'
'@mention-bot mkdir: create a directory\n'
'@mention-bot ls: list a directory\n'
'@mention-bot cd: change directory\n'
'@mention-bot pwd: show current path\n'
'@mention-bot write: write text\n'
'@mention-bot read: read text\n'
'@mention-bot rm: remove a file\n'
'@mention-bot rmdir: remove a directory\n'
'```\n'
'Use commands like `@mention-bot help write` for more details on specific\ncommands.\n'),
"help ls": "foo_sender@zulip.com:\nsyntax: ls <optional_path>",
"": ('foo_sender@zulip.com:\n\nThis bot implements a virtual file system for a stream.\n'
'The locations of text are persisted for the lifetime of the bot\n'
'running, and if you rename a stream, you will lose the info.\n'
'Example commands:\n\n```\n'
'@mention-bot sample_conversation: sample conversation with the bot\n'
'@mention-bot mkdir: create a directory\n'
'@mention-bot ls: list a directory\n'
'@mention-bot cd: change directory\n'
'@mention-bot pwd: show current path\n'
'@mention-bot write: write text\n'
'@mention-bot read: read text\n'
'@mention-bot rm: remove a file\n'
'@mention-bot rmdir: remove a directory\n'
'```\n'
'Use commands like `@mention-bot help write` for more details on specific\ncommands.\n'),
}
self.check_expected_responses(expected)