Improve test coverage for Yoda bot.
This commit is contained in:
parent
fd97ffce77
commit
e32336eb6e
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue