def test_send_messages(mock_gsd, mock_bc, app): mock_sender_one = mock.Mock() mock_sender_two = mock.Mock() mock_connection = mock.Mock() mock_connection.create_sender.side_effect = [ mock_sender_one, mock_sender_two ] mock_bc.return_value = mock_connection msg_one = proton.Message('{"han": "solo"}') msg_two = proton.Message('{"star": "wars"}') envelopes = [ messaging.Envelope('topic://VirtualTopic.eng.star_wars', msg_one), messaging.Envelope('topic://VirtualTopic.eng.star_wars2', msg_one), messaging.Envelope('topic://VirtualTopic.eng.star_wars', msg_two), ] messaging.send_messages(envelopes) mock_bc.assert_called_once_with(urls=['amqps://message-broker:5671'], timeout=30, ssl_domain=mock_gsd.return_value) # Verify that even though three messages were sent, only two senders were created since only # two unique addresses were used assert mock_connection.create_sender.call_count == 2 # Ensure the order is respected mock_connection.create_sender.assert_has_calls(( mock.call('topic://VirtualTopic.eng.star_wars'), mock.call('topic://VirtualTopic.eng.star_wars2'), )) assert mock_sender_one.send.call_count == 2 mock_sender_one.send.assert_has_calls( (mock.call(msg_one, timeout=30), mock.call(msg_two, timeout=30))) mock_sender_two.send.assert_called_once_with(msg_one, timeout=30) mock_connection.close.assert_called_once_with()
def test_send_messages_nonfatal(mock_gsd, mock_bc, app): mock_bc.side_effect = proton.Timeout # Verfies that an infrastructure issue is a nonfatal error. If this raises an exception, # the test will fail. messaging.send_messages( [messaging.Envelope('topic://VirtualTopic.eng.star_wars', '{"han": "solo"}')] )