bots: Add complete tests for offline testing of define bot.
This commit is contained in:
parent
2e48392884
commit
f955eb0c8d
|
@ -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_404.json
|
||||||
include zulip_bots/bots/github_detail/fixtures/test_issue.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/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
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,12 +9,59 @@ class TestDefineBot(BotTestCase):
|
||||||
bot_name = "define"
|
bot_name = "define"
|
||||||
|
|
||||||
def test_bot(self):
|
def test_bot(self):
|
||||||
expected = {
|
|
||||||
"": 'Please enter a word to define.',
|
# Only one type(noun) of word.
|
||||||
"foo": "**foo**:\nDefinition not available.",
|
bot_response = ("**cat**:\n\n* (**noun**) a small domesticated carnivorous mammal "
|
||||||
"cat": ("**cat**:\n\n* (**noun**) a small domesticated carnivorous mammal "
|
|
||||||
"with soft fur, a short snout, and retractile claws. It is widely "
|
"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 "
|
"kept as a pet or for catching mice, and many breeds have been "
|
||||||
"developed.\n their pet cat\n\n"),
|
"developed.\n their pet cat\n\n")
|
||||||
}
|
with self.mock_http_conversation('test_single_type_word'):
|
||||||
self.check_expected_responses(expected)
|
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'
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue