diff --git a/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py b/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py index a41097a..5d29add 100644 --- a/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py +++ b/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py @@ -21,16 +21,16 @@ class BaremetricsHandler(object): 'List the sources', 'List the plans for the source', 'List the customers in the source', 'List the subscriptions in the source'] - self.check_api_key() + self.check_api_key(bot_handler) - def check_api_key(self) -> None: + def check_api_key(self, bot_handler) -> None: url = "https://api.baremetrics.com/v1/account" test_query_response = requests.get(url, headers=self.auth_header) test_query_data = test_query_response.json() try: if test_query_data['error'] == "Unauthorized. Token not found": - logging.error('API Key not valid. Please see doc.md to find out how to get it.') + bot_handler.quit('API Key not valid. Please see doc.md to find out how to get it.') except KeyError: pass diff --git a/zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py b/zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py index cd0b0e4..6751d11 100644 --- a/zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py +++ b/zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py @@ -1,14 +1,17 @@ +from unittest.mock import patch from zulip_bots.test_lib import BotTestCase class TestBaremetricsBot(BotTestCase): bot_name = "baremetrics" def test_bot_responds_to_empty_message(self) -> None: - with self.mock_config_info({'api_key': 'TEST'}): + with self.mock_config_info({'api_key': 'TEST'}), \ + patch('requests.get'): self.verify_reply('', 'No Command Specified') def test_help_query(self) -> None: - with self.mock_config_info({'api_key': 'TEST'}): + with self.mock_config_info({'api_key': 'TEST'}), \ + patch('requests.get'): self.verify_reply('help', ''' This bot gives updates about customer behavior, financial performance, and analytics for an organization using the Baremetrics Api.\n @@ -17,7 +20,8 @@ class TestBaremetricsBot(BotTestCase): ''') def test_list_commands_command(self) -> None: - with self.mock_config_info({'api_key': 'TEST'}): + with self.mock_config_info({'api_key': 'TEST'}), \ + patch('requests.get'): self.verify_reply('list-commands', '**Available Commands:** \n - help : Display bot info\n - list-commands ' ': Display the list of available commands\n - account-info : Display ' 'the account info\n - list-sources : List the sources\n - list-plans '