diff --git a/zerver/lib/bot_lib.py b/zerver/lib/bot_lib.py index 6e42d2597c..80ec0ad2be 100644 --- a/zerver/lib/bot_lib.py +++ b/zerver/lib/bot_lib.py @@ -11,7 +11,7 @@ from zerver.lib.actions import internal_send_private_message, \ from zerver.models import UserProfile, get_user from zerver.lib.bot_storage import get_bot_storage, set_bot_storage, \ is_key_in_bot_storage, get_bot_storage_size, remove_bot_storage -from zerver.lib.bot_config import get_bot_config +from zerver.lib.bot_config import get_bot_config, ConfigError from zerver.lib.integrations import EMBEDDED_BOTS import configparser @@ -105,5 +105,11 @@ class EmbeddedBotHandler: sender_email=message['sender_email'], )) - def get_config_info(self) -> Dict[Text, Text]: - return get_bot_config(self.user_profile) + # The bot_name argument exists only to comply with ExternalBotHandler.get_config_info(). + def get_config_info(self, bot_name: str, optional: bool=False) -> Dict[Text, Text]: + try: + return get_bot_config(self.user_profile) + except ConfigError: + if optional: + return dict() + raise diff --git a/zerver/tests/test_service_bot_system.py b/zerver/tests/test_service_bot_system.py index 9d6735ae04..20de454cff 100644 --- a/zerver/tests/test_service_bot_system.py +++ b/zerver/tests/test_service_bot_system.py @@ -282,16 +282,18 @@ class TestServiceBotConfigHandler(ZulipTestCase): with self.assertRaises(ConfigError): self.bot_handler.get_config_info('foo') + self.assertEqual(self.bot_handler.get_config_info('foo', optional=True), dict()) + config_dict = {"entry 1": "value 1", "entry 2": "value 2"} for key, value in config_dict.items(): set_bot_config(self.bot_profile, key, value) - self.assertEqual(self.bot_handler.get_config_info(), config_dict) + self.assertEqual(self.bot_handler.get_config_info('foo'), config_dict) config_update = {"entry 2": "new value", "entry 3": "value 3"} for key, value in config_update.items(): set_bot_config(self.bot_profile, key, value) config_dict.update(config_update) - self.assertEqual(self.bot_handler.get_config_info(), config_dict) + self.assertEqual(self.bot_handler.get_config_info('foo'), config_dict) @override_settings(BOT_CONFIG_SIZE_LIMIT=100) def test_config_entry_limit(self) -> None: