mention bot: Quit on invalid API key.

This commit is contained in:
Robert Hönig 2018-01-04 15:39:55 +01:00 committed by showell
parent 57342072dc
commit bed2c6c9ea
2 changed files with 8 additions and 5 deletions

View file

@ -10,9 +10,9 @@ class MentionHandler(object):
self.access_token = self.config_info['access_token']
self.account_id = ''
self.check_access_token()
self.check_access_token(bot_handler)
def check_access_token(self) -> None:
def check_access_token(self, bot_handler) -> None:
test_query_header = {
'Authorization': 'Bearer ' + self.access_token,
'Accept-Version': '1.15',
@ -23,7 +23,7 @@ class MentionHandler(object):
test_query_data = test_query_response.json()
if test_query_data['error'] == 'invalid_grant' and \
test_query_data['error_description'] == 'The access token provided is invalid.':
logging.error('Access Token Invalid. Please see doc.md to find out how to get it.')
bot_handler.quit('Access Token Invalid. Please see doc.md to find out how to get it.')
except KeyError:
pass

View file

@ -1,15 +1,18 @@
from zulip_bots.bots.mention.mention import MentionHandler
from unittest.mock import patch
from zulip_bots.test_lib import BotTestCase
class TestMentionBot(BotTestCase):
bot_name = "mention"
def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info({'access_token': '12345'}):
with self.mock_config_info({'access_token': '12345'}), \
patch('requests.get'):
self.verify_reply('', 'Empty Mention Query')
def test_help_query(self) -> None:
with self.mock_config_info({'access_token': '12345'}):
with self.mock_config_info({'access_token': '12345'}), \
patch('requests.get'):
self.verify_reply('help', '''
This is a Mention API Bot which will find mentions
of the given keyword throughout the web.