Improve test coverage for Yoda bot.
ADD
zulip_bots/zulip_bots/bots/yoda/fixtures/test_api_key_error.json
+{
+ "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"
+ }
+}

ADD
zulip_bots/zulip_bots/bots/yoda/fixtures/test_service_unavailable_error.json
+{
+ "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"
+ }
+}

ADD
zulip_bots/zulip_bots/bots/yoda/fixtures/test_unknown_error.json
+{
+ "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"
+ }
+}

MODIFY
zulip_bots/zulip_bots/bots/yoda/test_yoda.py
zulip_bots/zulip_bots/bots/yoda/test_yoda.py
+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')

MODIFY
zulip_bots/zulip_bots/bots/yoda/yoda.py
zulip_bots/zulip_bots/bots/yoda/yoda.py
@@ -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

Improve test coverage for Yoda bot.