diff --git a/zulip_bots/MANIFEST.in b/zulip_bots/MANIFEST.in index 4d7887c..4d76de2 100644 --- a/zulip_bots/MANIFEST.in +++ b/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 diff --git a/zulip_bots/zulip_bots/bots/define/fixtures/test_incorrect_word.json b/zulip_bots/zulip_bots/bots/define/fixtures/test_incorrect_word.json new file mode 100644 index 0000000..8f56269 --- /dev/null +++ b/zulip_bots/zulip_bots/bots/define/fixtures/test_incorrect_word.json @@ -0,0 +1,12 @@ +{ + "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" + } +} diff --git a/zulip_bots/zulip_bots/bots/define/fixtures/test_multi_type_word.json b/zulip_bots/zulip_bots/bots/define/fixtures/test_multi_type_word.json new file mode 100644 index 0000000..7eb1bbf --- /dev/null +++ b/zulip_bots/zulip_bots/bots/define/fixtures/test_multi_type_word.json @@ -0,0 +1,37 @@ +{ + "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" + } +} diff --git a/zulip_bots/zulip_bots/bots/define/fixtures/test_single_type_word.json b/zulip_bots/zulip_bots/bots/define/fixtures/test_single_type_word.json new file mode 100644 index 0000000..6f286ed --- /dev/null +++ b/zulip_bots/zulip_bots/bots/define/fixtures/test_single_type_word.json @@ -0,0 +1,17 @@ +{ + "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" + } +} diff --git a/zulip_bots/zulip_bots/bots/define/test_define.py b/zulip_bots/zulip_bots/bots/define/test_define.py index d0ced38..fd0e839 100755 --- a/zulip_bots/zulip_bots/bots/define/test_define.py +++ b/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 " - "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  their pet cat\n\n"), - } - self.check_expected_responses(expected) + + # 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  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" + "  they helped her with domestic chores\n\n\n" + "* (**verb**) serve someone with (food or drink).\n" + "  may I help you to some more meat?\n\n\n" + "* (**verb**) cannot or could not avoid.\n" + "  he couldn't help laughing\n\n\n" + "* (**noun**) the action of helping someone to do something.\n" + "  I asked for help from my neighbours\n\n\n" + "* (**exclamation**) used as an appeal for urgent assistance.\n" + "  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' + )