bots: Add complete tests for offline testing of define bot.
MODIFY
zulip_bots/MANIFEST.in
zulip_bots/MANIFEST.in
@@ -2,4 +2,7 @@ include zulip_bots/bots/giphy/fixtures/test_1.json
include zulip_bots/bots/github_detail/fixtures/test_404.json
include zulip_bots/bots/github_detail/fixtures/test_issue.json
include zulip_bots/bots/github_detail/fixtures/test_pull.json
+include zulip_bots/bots/define/fixtures/test_single_type_word.json
+include zulip_bots/bots/define/fixtures/test_multi_type_word.json
+include zulip_bots/bots/define/fixtures/test_incorrect_word.json

ADD
zulip_bots/zulip_bots/bots/define/fixtures/test_incorrect_word.json
+{
+ "request":{
+ "api_url":"https://owlbot.info/api/v1/dictionary/foo?format=json"
+ },
+ "response":[
+ ],
+ "response-headers":{
+ "status":200,
+ "ok":true,
+ "content-type":"application/json; charset=utf-8"
+ }
+}

ADD
zulip_bots/zulip_bots/bots/define/fixtures/test_multi_type_word.json
+{
+ "request":{
+ "api_url":"https://owlbot.info/api/v1/dictionary/help?format=json"
+ },
+ "response":[
+ {
+ "type":"verb",
+ "defenition":"make it easier or possible for (someone) to do something by offering them one's services or resources.",
+ "example":"they helped her with domestic chores"
+ },
+ {
+ "type":"verb",
+ "defenition":"serve someone with (food or drink).",
+ "example":"may I help you to some more meat?"
+ },
+ {
+ "type":"verb",
+ "defenition":"cannot or could not avoid.",
+ "example":"he couldn't help laughing"
+ },
+ {
+ "type":"noun",
+ "defenition":"the action of helping someone to do something.",
+ "example":"I asked for help from my neighbours"
+ },
+ {
+ "type":"exclamation",
+ "defenition":"used as an appeal for urgent assistance.",
+ "example":"Help! I'm drowning!"
+ }
+ ],
+ "response-headers":{
+ "status":200,
+ "ok":true,
+ "content-type":"application/json; charset=utf-8"
+ }
+}

ADD
zulip_bots/zulip_bots/bots/define/fixtures/test_single_type_word.json
+{
+ "request":{
+ "api_url":"https://owlbot.info/api/v1/dictionary/cat?format=json"
+ },
+ "response":[
+ {
+ "type":"noun",
+ "defenition":"a small domesticated carnivorous mammal with soft fur, a short snout, and retractile claws. It is widely kept as a pet or for catching mice, and many breeds have been developed.",
+ "example":"their pet cat"
+ }
+ ],
+ "response-headers":{
+ "status":200,
+ "ok":true,
+ "content-type":"application/json; charset=utf-8"
+ }
+}

MODIFY
zulip_bots/zulip_bots/bots/define/test_define.py
zulip_bots/zulip_bots/bots/define/test_define.py
@@ -9,12 +9,59 @@ class TestDefineBot(BotTestCase):
bot_name = "define"
def test_bot(self):
- expected = {
- "": 'Please enter a word to define.',
- "foo": "**foo**:\nDefinition not available.",
- "cat": ("**cat**:\n\n* (**noun**) a small domesticated carnivorous mammal "
+
+ # Only one type(noun) of word.
+ bot_response = ("**cat**:\n\n* (**noun**) a small domesticated carnivorous mammal "
"with soft fur, a short snout, and retractile claws. It is widely "
"kept as a pet or for catching mice, and many breeds have been "
- "developed.\n&nbsp;&nbsp;their pet cat\n\n"),
- }
- self.check_expected_responses(expected)
+ "developed.\n&nbsp;&nbsp;their pet cat\n\n")
+ with self.mock_http_conversation('test_single_type_word'):
+ self.assert_bot_response(
+ message = {'content': 'cat'},
+ response = {'content': bot_response},
+ expected_method='send_reply'
+ )
+
+ # Multi-type word.
+ bot_response = ("**help**:\n\n"
+ "* (**verb**) make it easier or possible for (someone) to do something by offering them one's services or resources.\n"
+ "&nbsp;&nbsp;they helped her with domestic chores\n\n\n"
+ "* (**verb**) serve someone with (food or drink).\n"
+ "&nbsp;&nbsp;may I help you to some more meat?\n\n\n"
+ "* (**verb**) cannot or could not avoid.\n"
+ "&nbsp;&nbsp;he couldn't help laughing\n\n\n"
+ "* (**noun**) the action of helping someone to do something.\n"
+ "&nbsp;&nbsp;I asked for help from my neighbours\n\n\n"
+ "* (**exclamation**) used as an appeal for urgent assistance.\n"
+ "&nbsp;&nbsp;Help! I'm drowning!\n\n")
+ with self.mock_http_conversation('test_multi_type_word'):
+ self.assert_bot_response(
+ message = {'content': 'help'},
+ response = {'content': bot_response},
+ expected_method='send_reply'
+ )
+
+ # Incorrect word.
+ bot_response = "**foo**:\nDefinition not available."
+ with self.mock_http_conversation('test_incorrect_word'):
+ self.assert_bot_response(
+ message = {'content': 'foo'},
+ response = {'content': bot_response},
+ expected_method='send_reply'
+ )
+
+ # Phrases are not defined. No request is sent to the Internet.
+ bot_response = "Definitions for phrases are not available."
+ self.assert_bot_response(
+ message = {'content': 'The sky is blue'},
+ response = {'content': bot_response},
+ expected_method='send_reply'
+ )
+
+ # Empty messages are returned with a prompt to reply. No request is sent to the Internet.
+ bot_response = "Please enter a word to define."
+ self.assert_bot_response(
+ message = {'content': ''},
+ response = {'content': bot_response},
+ expected_method='send_reply'
+ )

bots: Add complete tests for offline testing of define bot.