def test_should_call_when_lower_vote_received(self): receiver = Mock(Receiver) fsm = Mock() fsm.vote = 42 receiver.states = {'id123': fsm} lower_vote_event = {'id': 'vote', 'tracking_id': 'id123', 'payload': 5} Receiver.onEvent(receiver, 'target', lower_vote_event) fsm.call.assert_called_with()
def test_should_fold_when_higher_vote_received(self): receiver = Mock(Receiver) fsm = Mock() fsm.vote = 5 receiver.states = {'id123': fsm} higher_vote_event = {'id': 'vote', 'tracking_id': 'id123', 'payload': 42 } Receiver.onEvent(receiver, 'target', higher_vote_event) fsm.fold.assert_called_with()
def test_should_call_when_lower_vote_received(self): receiver = Mock(Receiver) fsm = Mock() fsm.vote = 42 receiver.states = {'id123': fsm} lower_vote_event = {'id': 'vote', 'tracking_id': 'id123', 'payload': 5 } Receiver.onEvent(receiver, 'target', lower_vote_event) fsm.call.assert_called_with()
def test_should_handle_request(self, mock_event_class): mock_receiver = Mock(Receiver) mock_receiver.states = {None: Mock()} mock_event = Mock(Event) mock_event.is_a_vote = False mock_event_class.return_value = mock_event Receiver.onEvent(mock_receiver, 'target', { 'id': 'request', 'cmd': 'command', 'args': 'args'}) self.assertEqual( call('target', {'id': 'request', 'cmd': 'command', 'args': 'args'}), mock_event_class.call_args) self.assertEqual( call(mock_event), mock_receiver.handle_request.call_args)
def test_should_fold_when_higher_vote_received(self): receiver = Mock(Receiver) fsm = Mock() fsm.vote = 5 receiver.states = {'id123': fsm} higher_vote_event = { 'id': 'vote', 'tracking_id': 'id123', 'payload': 42 } Receiver.onEvent(receiver, 'target', higher_vote_event) fsm.fold.assert_called_with()
def test_should_publish_event_about_failed_request_when_handle_request_fails(self, mock_log, mock_event_class): mock_receiver = Mock(Receiver) mock_receiver.handle_request.side_effect = ReceiverException( 'It failed!') mock_receiver.states = {'some-id': Mock()} mock_event = Mock(Event) mock_event.is_a_vote = False mock_event.tracking_id = 'some-id' mock_event_class.return_value = mock_event Receiver.onEvent(mock_receiver, 'target', { 'id': 'request', 'cmd': 'command', 'args': 'args'}) self.assertEqual( call('target', {'id': 'request', 'cmd': 'command', 'args': 'args'}), mock_event_class.call_args) self.assertEqual( call(mock_event, 'It failed!'), mock_receiver.publish_failed.call_args)