def test_slack_delivery(self, mock_slack): slack_mailer_config = { 'queue_url': 'asq://storageaccount.queue.core.windows.net/queuename', 'slack_token': 'mock_token' } slack_compressed_message = MagicMock() slack_compressed_message.content = base64.b64encode( zlib.compress(ASQ_MESSAGE_SLACK.encode('utf8'))) slack_loaded_message = json.loads(ASQ_MESSAGE_SLACK) mock_slack.return_value\ .get_to_addrs_slack_messages_map.return_value = 'mock_slack_message_map' azure_processor = MailerAzureQueueProcessor(slack_mailer_config, logger) self.assertTrue( azure_processor.process_azure_queue_message( slack_compressed_message)) mock_slack.assert_has_calls([ call().slack_handler(slack_loaded_message, 'mock_slack_message_map') ])
def test_datadog_delivery(self, mock_datadog): datadog_mailer_config = { 'queue_url': 'asq://storageaccount.queue.core.windows.net/queuename', 'datadog_api_key': 'mock_api_key', 'datadog_application_key': 'mock_application_key' } datadog_compressed_message = MagicMock() datadog_compressed_message.content = base64.b64encode( zlib.compress(ASQ_MESSAGE_DATADOG.encode('utf8'))) datadog_loaded_message = json.loads(ASQ_MESSAGE_DATADOG) mock_datadog.return_value\ .get_datadog_message_packages.return_value = 'mock_datadog_message_map' azure_processor = MailerAzureQueueProcessor(datadog_mailer_config, logger) self.assertTrue( azure_processor.process_azure_queue_message( datadog_compressed_message)) mock_datadog.assert_has_calls([ call().deliver_datadog_messages('mock_datadog_message_map', datadog_loaded_message) ])
def test_smtp_delivery(self, mock_smtp): smtp_mailer_config = { 'queue_url': 'asq://storageaccount.queue.core.windows.net/queuename', 'from_address': '*****@*****.**', 'smtp_port': 25, 'smtp_ssl': True, 'smtp_server': 'test_server', 'smtp_username': '******', 'smtp_password': '******' } with patch( 'c7n_mailer.azure_mailer.sendgrid_delivery.SendGridDelivery' '.get_to_addrs_sendgrid_messages_map', return_value={('*****@*****.**', ): self.loaded_message}): azure_processor = MailerAzureQueueProcessor( smtp_mailer_config, logger) self.assertTrue( azure_processor.process_azure_queue_message( self.compressed_message)) mock_smtp.assert_has_calls([ call().send_message(message=self.loaded_message, to_addrs=['*****@*****.**']) ])
def test_process_azure_queue_message_failure(self, mock_get_addr, mock_handler): mock_handler.return_value = False mock_get_addr.return_value = 42 # Run the process messages method azure_processor = MailerAzureQueueProcessor(MAILER_CONFIG_AZURE, logger) self.assertFalse( azure_processor.process_azure_queue_message( self.compressed_message)) # Verify mock calls were correct mock_get_addr.assert_called_with(self.loaded_message) mock_handler.assert_called_with(self.loaded_message, 42)