def __init__(self, resource, inventory_index_id, violations,
                 global_configs, notifier_config, notification_config):
        """Initialization.

        Args:
            resource (str): Violation resource name.
            inventory_index_id (int64): Inventory index id.
            violations (dict): Violations.
            global_configs (dict): Global configurations.
            notifier_config (dict): Notifier configurations.
            notification_config (dict): notifier configurations.

        Raises:
            InvalidInputError: Raised if invalid input is encountered.
        """
        super(EmailViolations,
              self).__init__(resource, inventory_index_id, violations,
                             global_configs, notifier_config,
                             notification_config)
        try:
            if self.notifier_config.get('email_connector'):
                self.connector = email_factory.EmailFactory(
                    self.notifier_config).get_connector()
            # else block below is added for backward compatibility.
            else:
                self.connector = email_factory.EmailFactory(
                    self.notification_config).get_connector()
        except Exception:
            LOGGER.exception('Error occurred to instantiate connector.')
            raise InvalidInputError(self.notifier_config)
 def test_get_connector_correctness_default(self):
     """Test get_connector() correctness."""
     sample_notifier_config = {
         'sender': 'abc',
         'recipient': 'xyz',
         'api_key': 'a0b0c0'
     }
     connector = email_factory.EmailFactory(
         sample_notifier_config).get_connector()
     self.assertTrue(
         isinstance(connector, sendgrid_connector.SendgridConnector))
 def test_get_connector_invalid_input(self):
     """Test get_connector() with invalid input."""
     incomplete_notifier_config = {
         'email_connector': {
             'sender': 'abc',
             'recipient': 'xyz',
             'data_format': 'csv',
             'auth': {
                 'api_key': 'a0b0c0'
             }
         }
     }
     self.assertRaises(
         InvalidInputError,
         email_factory.EmailFactory(
             incomplete_notifier_config).get_connector)
 def test_get_connector_correctness_sendgrid(self):
     """Test get_connector() correctness."""
     sample_notifier_config = {
         'email_connector': {
             'name': 'sendgrid',
             'sender': 'abc',
             'recipient': 'xyz',
             'data_format': 'csv',
             'auth': {
                 'api_key': 'a0b0c0'
             }
         }
     }
     connector = email_factory.EmailFactory(
         sample_notifier_config).get_connector()
     self.assertTrue(
         isinstance(connector, sendgrid_connector.SendgridConnector))
 def test_get_connector_correctness_mailjet(self):
     if not mailjet_connector.MAILJET_ENABLED:
         self.skipTest('Package `mailjet` not installed.')
     """Test get_connector() correctness."""
     sample_notifier_config = {
         'email_connector': {
             'name': 'mailjet',
             'sender': 'abc',
             'recipient': 'xyz',
             'data_format': 'csv',
             'auth': {
                 'api_key': 'a0b0c0',
                 'api_secret': 'z9y9x9'
             },
             'custom': {
                 'campaign': 'forseti'
             }
         }
     }
     connector = email_factory.EmailFactory(
         sample_notifier_config).get_connector()
     self.assertIsInstance(connector, mailjet_connector.MailjetConnector)
 def test_get_connector_empty(self):
     """Test get_connector() when input is not passed."""
     empty_notifier_config = {}
     self.assertRaises(
         InvalidInputError,
         email_factory.EmailFactory(empty_notifier_config).get_connector)