def test_state_listener(self, mock_add, mock_get, \ mock_start, mock_create, mock_get_children): """ test state_listener """ mock_get_children.return_value = ["test#test"] mock_start.return_value = None mock_get.return_value = "127.0.0.1:666" mock_add.return_value = None def startfunc(): """ mock func """ return "start" def stopfunc(): """ mock func """ return "stop" ham = ha_master.HAMaster(startfunc, stopfunc) ham.state_listener(kazoo.client.KazooState.LOST) ham.state_listener(kazoo.client.KazooState.SUSPENDED) ham.state_listener(kazoo.client.KazooState.CONNECTED) ham.state_listener("UNKNOW")
def test_choose_master4(self, mock_add, mock_get, \ mock_start, mock_create, mock_get_children): """ test choose_master """ mock_get_children.return_value = ["test#test"] mock_start.return_value = None mock_get.return_value = "127.0.0.1:666" mock_add.return_value = None def startfunc(): """ mock func """ return "start" def stopfunc(): """ mock func """ return "stop" ham = ha_master.HAMaster(startfunc, stopfunc) ham.is_leader = True ham.choose_master()
def test_init(self, mock_add, mock_get, mock_start): """ test HAMaster init """ mock_start.return_value = None mock_get.return_value = "127.0.0.1:666" mock_add.return_value = None def startfunc(): """ mock func """ return "start" def stopfunc(): """ mock func """ return "stop" ham = ha_master.HAMaster(startfunc, stopfunc)
def test_create_instance(self, mock_add, mock_get, mock_start, mock_create): """ test create_instance """ mock_start.return_value = None mock_get.return_value = "127.0.0.1:666" mock_add.return_value = None def startfunc(): """ mock func """ return "start" def stopfunc(): """ mock func """ return "stop" ham = ha_master.HAMaster(startfunc, stopfunc) ham.create_instance()
def test_event_watcher(self, mock_add, mock_get, \ mock_start, mock_create, mock_get_children): """ test event_watcher """ mock_get_children.return_value = ["test#test"] mock_start.return_value = None mock_get.return_value = "127.0.0.1:666" mock_add.return_value = None def startfunc(): """ mock func """ return "start" def stopfunc(): """ mock func """ return "stop" ham = ha_master.HAMaster(startfunc, stopfunc) class Event(object): """ mock Event """ def __init__(self, value): self.state = value self.type = value e = Event("CONNECTED") ham.event_watcher(e) e = Event("UNKNOW") ham.event_watcher(e)