Refactor: Make StateHandler() function independent.

This refactor makes the nested class 'StateHandler' in the
file /contrib_bots/bot_lib.py independent class. It previously
was nested in 'run_message_handler_for_bot' function.

This is done to write a cleaner test file for contrib_bots using
mock library.
This commit is contained in:
Abhijeet Kaur 2017-05-22 08:35:07 +05:30 committed by Tim Abbott
parent a8b825388d
commit 63efed5c73

View file

@ -71,14 +71,7 @@ class BotHandlerApi(object):
content=response, content=response,
)) ))
def run_message_handler_for_bot(lib_module, quiet, config_file): class StateHandler(object):
# Make sure you set up your ~/.zuliprc
client = Client(config_file=config_file)
restricted_client = BotHandlerApi(client)
message_handler = lib_module.handler_class()
class StateHandler(object):
def __init__(self): def __init__(self):
self.state = None self.state = None
@ -88,6 +81,13 @@ def run_message_handler_for_bot(lib_module, quiet, config_file):
def get_state(self): def get_state(self):
return self.state return self.state
def run_message_handler_for_bot(lib_module, quiet, config_file):
# Make sure you set up your ~/.zuliprc
client = Client(config_file=config_file)
restricted_client = BotHandlerApi(client)
message_handler = lib_module.handler_class()
state_handler = StateHandler() state_handler = StateHandler()
if not quiet: if not quiet: