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

This commit is contained in:
Abhijeet Kaur 2017-07-23 02:22:09 +05:30
parent f955eb0c8d
commit 35353f6d7f
6 changed files with 133 additions and 12 deletions

View file

@ -5,4 +5,8 @@ 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
include zulip_bots/bots/wikipedia/fixtures/test_single_word.json
include zulip_bots/bots/wikipedia/fixtures/test_multi_word.json
include zulip_bots/bots/wikipedia/fixtures/test_incorrect_query.json
include zulip_bots/bots/wikipedia/fixtures/test_number_query.json

View file

@ -0,0 +1,19 @@
{
"request": {
"api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=sssssss kkkkk&format=json"
},
"response": {
"data": {
"status_code":200
},
"query": {
"search": [
]
}
},
"response-headers":{
"status":200,
"ok":true,
"content-type":"application/json; charset=utf-8"
}
}

View file

@ -0,0 +1,22 @@
{
"request": {
"api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=The sky is blue&format=json"
},
"response": {
"data": {
"status_code":200
},
"query": {
"search": [
{
"title":"Sky blue"
}
]
}
},
"response-headers":{
"status":200,
"ok":true,
"content-type":"application/json; charset=utf-8"
}
}

View file

@ -0,0 +1,22 @@
{
"request": {
"api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=123&format=json"
},
"response": {
"data": {
"status_code":200
},
"query": {
"search": [
{
"title":"123"
}
]
}
},
"response-headers":{
"status":200,
"ok":true,
"content-type":"application/json; charset=utf-8"
}
}

View file

@ -0,0 +1,22 @@
{
"request": {
"api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=happy&format=json"
},
"response": {
"data": {
"status_code":200
},
"query": {
"search": [
{
"title":"Happiness"
}
]
}
},
"response-headers":{
"status":200,
"ok":true,
"content-type":"application/json; charset=utf-8"
}
}

View file

@ -9,15 +9,47 @@ class TestWikipediaBot(BotTestCase):
bot_name = "wikipedia"
def test_bot(self):
expected = {
"": 'Please enter your message after @mention-bot',
"sssssss kkkkk": ('I am sorry. The search term you provided '
'is not found :slightly_frowning_face:'),
"foo": ('For search term "foo", '
'https://en.wikipedia.org/wiki/Foobar'),
"123": ('For search term "123", '
'https://en.wikipedia.org/wiki/123'),
"laugh": ('For search term "laugh", '
'https://en.wikipedia.org/wiki/Laughter'),
}
self.check_expected_responses(expected)
# Single-word query
bot_response = "For search term \"happy\", https://en.wikipedia.org/wiki/Happiness"
with self.mock_http_conversation('test_single_word'):
self.assert_bot_response(
message = {'content': 'happy'},
response = {'content': bot_response},
expected_method='send_reply'
)
# Multi-word query
bot_response = "For search term \"The sky is blue\", https://en.wikipedia.org/wiki/Sky_blue"
with self.mock_http_conversation('test_multi_word'):
self.assert_bot_response(
message = {'content': 'The sky is blue'},
response = {'content': bot_response},
expected_method='send_reply'
)
# Number query
bot_response = "For search term \"123\", https://en.wikipedia.org/wiki/123"
with self.mock_http_conversation('test_number_query'):
self.assert_bot_response(
message = {'content': '123'},
response = {'content': bot_response},
expected_method='send_reply'
)
# Incorrect word
bot_response = "I am sorry. The search term you provided is not found :slightly_frowning_face:"
with self.mock_http_conversation('test_incorrect_query'):
self.assert_bot_response(
message = {'content': 'sssssss kkkkk'},
response = {'content': bot_response},
expected_method='send_reply'
)
# Empty query, no request made to the Internet.
bot_response = "Please enter your message after @mention-bot"
self.assert_bot_response(
message = {'content': ''},
response = {'content': bot_response},
expected_method='send_reply'
)