mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 00:18:12 +00:00
bots: Add complete test-coverage for bot_lib.py file.
Also, add error handling for get_bot_handler instead of throwing an assertion error.
This commit is contained in:
committed by
Tim Abbott
parent
1ae02cce97
commit
1deb58b178
@@ -26,9 +26,10 @@ from zulip_bots.lib import RateLimit
|
||||
def get_bot_handler(service_name):
|
||||
# type: (str) -> Any
|
||||
|
||||
# Assert that this service is present in EMBEDDED_BOTS.
|
||||
assert any(service_name == embedded_bot_service.name for embedded_bot_service in EMBEDDED_BOTS)
|
||||
|
||||
# Check that this service is present in EMBEDDED_BOTS, add exception handling.
|
||||
is_present_in_registry = any(service_name == embedded_bot_service.name for embedded_bot_service in EMBEDDED_BOTS)
|
||||
if not is_present_in_registry:
|
||||
return None
|
||||
bot_module_name = 'zulip_bots.bots.%s.%s' % (service_name, service_name)
|
||||
bot_module = importlib.import_module(bot_module_name) # type: Any
|
||||
return bot_module.handler_class()
|
||||
|
||||
Reference in New Issue
Block a user