From 57342072dc899a4a83b3871a6c04f103cf246251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6nig?= Date: Thu, 4 Jan 2018 15:34:50 +0100 Subject: [PATCH] salesforce bot: Quit on invalid API key. --- zulip_bots/zulip_bots/bots/salesforce/salesforce.py | 4 +--- zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py | 7 ++----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/salesforce/salesforce.py b/zulip_bots/zulip_bots/bots/salesforce/salesforce.py index da42f65..94357fe 100644 --- a/zulip_bots/zulip_bots/bots/salesforce/salesforce.py +++ b/zulip_bots/zulip_bots/bots/salesforce/salesforce.py @@ -163,9 +163,7 @@ class SalesforceHandler(object): security_token=self.config_info['security_token'] ) except simple_salesforce.exceptions.SalesforceAuthenticationFailed as err: - logging.error( - 'Failed to log in to Salesforce. {} {}'.format(err.code, err.message)) - quit() + bot_handler.quit('Failed to log in to Salesforce. {} {}'.format(err.code, err.message)) def handle_message(self, message: Any, bot_handler: Any) -> None: try: diff --git a/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py b/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py index 7f8ac14..e33def3 100644 --- a/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py +++ b/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py @@ -1,4 +1,4 @@ -from zulip_bots.test_lib import BotTestCase, read_bot_fixture_data +from zulip_bots.test_lib import BotTestCase, StubBotHandler, read_bot_fixture_data import simple_salesforce from simple_salesforce.exceptions import SalesforceAuthenticationFailed from contextlib import contextmanager @@ -174,11 +174,8 @@ class TestSalesforceBot(BotTestCase): 'Usage: find contact [arguments]') def test_bad_auth(self) -> None: - with self.assertLogs(level='ERROR') as log, \ - patch('builtins.quit'): + with self.assertRaises(StubBotHandler.BotQuitException): self._test_initialize(auth_success=False) - self.assertIn( - 'ERROR:root:Failed to log in to Salesforce. 403 auth failed', log.output) def test_callback(self) -> None: self._test('test_one_result', 'echo hello', 'hello')