def test_update_exit(self): message = mock.Mock() message.crud = event.UPDATE self.sm.send_message(message) self.sm.state = state.Exit(mock.Mock()) self.sm.update(self.ctx) self.delete_callback.called_once_with()
def test_update_read_stats_args(self): message = mock.Mock() message.crud = event.READ self.sm.send_message(message) self.sm.state = state.ReadStats(mock.Mock()) with mock.patch.object(self.sm.state, 'execute', self.ctx) as execute: execute.return_value = state.Exit(mock.Mock()) self.sm.update(self.ctx) execute.called_once_with(event.POLL, self.instance_mgr_cls.return_value, self.ctx, self.bandwidth_callback)
def test_update_calc_action_args(self): message = mock.Mock() message.crud = event.UPDATE self.sm.send_message(message) with mock.patch.object(self.sm.state, 'execute', self.ctx) as execute: with mock.patch.object(self.sm.state, 'transition', self.ctx) as transition: transition.return_value = state.Exit(mock.Mock()) self.sm.update(self.ctx) execute.called_once_with(event.POLL, self.instance_mgr_cls.return_value, self.ctx, self.sm._queue) self.delete_callback.called_once_with()
def test_update_exception_during_excute(self): message = mock.Mock() message.crud = 'fake' self.sm.send_message(message) fake_state = mock.Mock() fake_state.execute.side_effect = Exception fake_state.transition.return_value = state.Exit(mock.Mock()) self.sm.action = 'fake' self.sm.state = fake_state with mock.patch.object(self.sm.driver, 'log') as log: self.sm.update(self.ctx) log.exception.assert_called_once_with(mock.ANY, fake_state, 'fake') fake_state.assert_has_calls([ mock.call.execute('fake', self.ctx), mock.call.transition('fake', self.ctx) ])