Make EmbeddedBotHandler.get_config_info comply with ExternalBotHandler.

This commit is contained in:
Robert Hönig 2018-01-07 19:17:25 +01:00
parent 9cc059f4aa
commit ed7208fd6e
2 changed files with 13 additions and 5 deletions

View File

@ -11,7 +11,7 @@ from zerver.lib.actions import internal_send_private_message, \
from zerver.models import UserProfile, get_user from zerver.models import UserProfile, get_user
from zerver.lib.bot_storage import get_bot_storage, set_bot_storage, \ from zerver.lib.bot_storage import get_bot_storage, set_bot_storage, \
is_key_in_bot_storage, get_bot_storage_size, remove_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 from zerver.lib.integrations import EMBEDDED_BOTS
import configparser import configparser
@ -105,5 +105,11 @@ class EmbeddedBotHandler:
sender_email=message['sender_email'], sender_email=message['sender_email'],
)) ))
def get_config_info(self) -> Dict[Text, Text]: # 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) return get_bot_config(self.user_profile)
except ConfigError:
if optional:
return dict()
raise

View File

@ -282,16 +282,18 @@ class TestServiceBotConfigHandler(ZulipTestCase):
with self.assertRaises(ConfigError): with self.assertRaises(ConfigError):
self.bot_handler.get_config_info('foo') 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"} config_dict = {"entry 1": "value 1", "entry 2": "value 2"}
for key, value in config_dict.items(): for key, value in config_dict.items():
set_bot_config(self.bot_profile, key, value) 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"} config_update = {"entry 2": "new value", "entry 3": "value 3"}
for key, value in config_update.items(): for key, value in config_update.items():
set_bot_config(self.bot_profile, key, value) set_bot_config(self.bot_profile, key, value)
config_dict.update(config_update) 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) @override_settings(BOT_CONFIG_SIZE_LIMIT=100)
def test_config_entry_limit(self) -> None: def test_config_entry_limit(self) -> None: