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

Since yoda api returns response of text form, made changes
in test_lib.py to handle responses that can either be json
or plain text.
This commit is contained in:
Abhijeet Kaur 2017-08-03 19:09:03 +05:30 committed by Tim Abbott
parent 1e84e2eb5e
commit 29d33e86fe
4 changed files with 46 additions and 5 deletions

View file

@ -0,0 +1,14 @@
{
"request": {
"api_url": "https://yoda.p.mashape.com/yoda?sentence=You+will+learn+how+to+speak+like+me+someday.",
"headers": {
"X-Mashape-Key": "12345678",
"Accept": "text/plain"
}
},
"response": {"text": "Learn how to speak like me someday, you will. Yes, hmmm."},
"response-headers": {
"status": 200,
"content-type": "text/html; charset=utf-8"
}
}

View file

@ -0,0 +1,23 @@
#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import print_function
import json
from zulip_bots.test_lib import BotTestCase
class TestYodaBot(BotTestCase):
bot_name = "yoda"
def test_bot(self):
bot_response = "Learn how to speak like me someday, you will. Yes, hmmm."
with self.mock_config_info({'api_key': '12345678'}), \
self.mock_http_conversation('test_1'):
self.initialize_bot()
self.assert_bot_response(
message = {'content': 'You will learn how to speak like me someday.'},
response = {'content': bot_response},
expected_method='send_reply'
)

View file

@ -58,7 +58,6 @@ class YodaSpeakHandler(object):
def send_to_yoda_api(self, sentence):
# function for sending sentence to api
response = requests.get("https://yoda.p.mashape.com/yoda?sentence=" + sentence,
headers={
"X-Mashape-Key": self.api_key,