def test_receive_message_execute_failure(self, process, broker_details, get_message_backend): """Exercise all exception code paths within receive_message""" def gen(): yield MagicMock() process.side_effect = CommandMessageExecuteFailure manager = CommandMessageManager() manager._backend = MagicMock() manager._backend.receive_messages.return_value = gen() manager.receive_messages()
def test_send_message(self): """Validate that send_message composes dict with `type` and `body` keys for backend""" command = MagicMock(type='test') command.to_json.return_value = 'body_content' manager = CommandMessageManager() send_messages = MagicMock() backend = MagicMock(send_messages=send_messages) manager._backend = backend manager.send_messages([command]) send_messages.assert_called_with([{ 'type': 'test', 'body': 'body_content' }])
def test_receive_message(self): """Validate the receive_message calls _process_message with each result""" mocks = [MagicMock() for _ in range(10)] def gen(): for mock in mocks: yield mock manager = CommandMessageManager() manager._backend = MagicMock() process_message = manager._process_message = MagicMock() manager._backend.receive_messages = MagicMock(return_value=gen()) manager.receive_messages() calls = [call(x) for x in mocks] process_message.assert_has_calls(calls) self.assertEquals(process_message.call_count, 10)