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:
Abhijeet Kaur
2017-07-25 22:33:09 +05:30
committed by Tim Abbott
parent 1ae02cce97
commit 1deb58b178
3 changed files with 21 additions and 4 deletions

View File

@@ -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()