Improve test coverage for Yoda bot.

This commit is contained in:
Viraat Chandra 2018-01-06 21:20:50 +05:30 committed by showell
parent fd97ffce77
commit e32336eb6e
5 changed files with 62 additions and 1 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": {},
"response-headers": {
"status": 403,
"content-type": "text/html; charset=utf-8"
}
}

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": {},
"response-headers": {
"status": 503,
"content-type": "text/html; charset=utf-8"
}
}

View file

@ -0,0 +1,16 @@
{
"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": {
"message": "Unknown Error."
},
"response-headers": {
"status": 123,
"content-type": "text/html; charset=utf-8"
}
}

View file

@ -1,3 +1,4 @@
from zulip_bots.bots.yoda.yoda import ServiceUnavailableError
from zulip_bots.test_lib import BotTestCase
class TestYodaBot(BotTestCase):
@ -51,3 +52,19 @@ class TestYodaBot(BotTestCase):
self._test('@#$%^&*',
"Invalid input, please check the sentence you have entered.",
'test_invalid_input')
# Test 403 response.
self._test('You will learn how to speak like me someday.',
"Invalid Api Key. Did you follow the instructions in the `readme.md` file?",
'test_api_key_error')
# Test 503 response.
with self.assertRaises(ServiceUnavailableError):
self._test('You will learn how to speak like me someday.',
"The service is temporarily unavailable, please try again.",
'test_service_unavailable_error')
# Test unknown response.
self._test('You will learn how to speak like me someday.',
"Unknown Error.Error code: 123 Did you follow the instructions in the `readme.md` file?",
'test_unknown_error')

View file

@ -72,7 +72,7 @@ class YodaSpeakHandler(object):
error_message = response.json()['message']
logging.error(error_message)
error_code = response.status_code
error_message = error_message + 'Error code: ' + error_code +\
error_message = error_message + 'Error code: ' + str(error_code) +\
' Did you follow the instructions in the `readme.md` file?'
return error_message