# Path: monasca_notification/notification.py
# class Notification(object):
#     def __init__(self, id, type, name, address, period, retry_count, alarm):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def to_json(self):
# 
# Path: monasca_notification/plugins/email_notifier.py
# CONF = cfg.CONF
# EMAIL_SINGLE_HOST_BASE = u'''On host "{hostname}" for target "{target_host}" {message}
# 
# Alarm "{alarm_name}" transitioned to the {state} state at {timestamp} UTC
# alarm_id: {alarm_id}
# 
# Lifecycle state: {lifecycle_state}
# Link: {link}
# Link to Grafana: {grafana_url}
# 
# With dimensions:
# {metric_dimensions}'''
# EMAIL_MULTIPLE_HOST_BASE = u'''On host "{hostname}" {message}
# 
# Alarm "{alarm_name}" transitioned to the {state} state at {timestamp} UTC
# alarm_id: {alarm_id}
# 
# Lifecycle state: {lifecycle_state}
# Link: {link}
# Link to Grafana: {grafana_url}
# 
# With dimensions:
# {metric_dimensions}'''
# EMAIL_NO_HOST_BASE = u'''On multiple hosts {message}
# 
# Alarm "{alarm_name}" transitioned to the {state} state at {timestamp} UTC
# Alarm_id: {alarm_id}
# 
# Lifecycle state: {lifecycle_state}
# Link: {link}
# Link to Grafana: {grafana_url}
# 
# With dimensions
# {metric_dimensions}'''
# class EmailNotifier(abstract_notifier.AbstractNotifier):
#     def __init__(self, log):
#     def config(self, config=None):
#     def statsd_name(self):
#     def send_notification(self, notification):
#     def _sendmail(self, notification, msg):
#     def _email_error(self, notification):
#     def _smtp_connect(self):
#     def _create_msg(self, hostname, notification, targethost=None):
#     def _get_link_url(self, metric, timestamp_ms):
# def _format_dimensions(notification):
# def register_opts(conf):
# def list_opts():
# 
# Path: monasca_notification/processors/notification_processor.py
# class NotificationProcessor(object):
#     def __init__(self):
#     def _remaining_plugin_types(self):
#     def insert_configured_plugins(self):
#     def send(self, notifications):
# 
# Path: tests/base.py
# class DisableStatsdFixture(fixtures.Fixture):
# class ConfigFixture(oo_cfg.Config):
# class BaseTestCase(oslotest_base.BaseTestCase):
# class PluginTestCase(BaseTestCase):
#     def setUp(self):
#     def __init__(self):
#     def setUp(self):
#     def _clean_config_loaded_flag():
#     def setUp(self):
#     def conf_override(**kw):
#     def conf_default(**kw):
#     def setUp(self, register_opts=None):


import time
from unittest import mock
from monasca_notification import notification as m_notification
from monasca_notification.plugins import email_notifier
from monasca_notification.processors import notification_processor as np
from tests import base
        email_notifier.register_opts(base.config.CONF)

        self.conf_default(group='email_notifier', server='my.smtp.server',
                          port=25, user=None, password=None,
                          timeout=60, from_addr='hpcs.mon@hp.com')
        self.conf_default(group='mysql', ssl=None, host='localhost',
                          port='3306', user='mysql_user', db='dbname',
                          passwd='mysql_passwd')
        self.conf_default(group='statsd', host='localhost', port=8125)

        self.conf_default(group='notification_types', enabled=[])

    # ------------------------------------------------------------------------
    # Test helper functions
    # ------------------------------------------------------------------------
    @mock.patch('pymysql.connect')
    @mock.patch('monasca_notification.common.utils.monascastatsd')
    @mock.patch('monasca_notification.plugins.email_notifier.smtplib')
    @mock.patch('monasca_notification.processors.notification_processor.notifiers.log')
    def _start_processor(self, notifications, mock_log, mock_smtp, mock_statsd, mock_pymsql):
        """Start the processor with the proper mocks
        """
        # Since the log runs in another thread I can mock it directly,
        # instead change the methods to put to a queue
        mock_log.warn = self.trap.append
        mock_log.error = self.trap.append

        mock_smtp.SMTP = self._smtpStub

        np.NotificationProcessor.insert_configured_plugins = mock.Mock()

# Path: monasca_notification/notification.py
# class Notification(object):
#     def __init__(self, id, type, name, address, period, retry_count, alarm):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def to_json(self):
# 
# Path: monasca_notification/plugins/email_notifier.py
# CONF = cfg.CONF
# EMAIL_SINGLE_HOST_BASE = u'''On host "{hostname}" for target "{target_host}" {message}
# 
# Alarm "{alarm_name}" transitioned to the {state} state at {timestamp} UTC
# alarm_id: {alarm_id}
# 
# Lifecycle state: {lifecycle_state}
# Link: {link}
# Link to Grafana: {grafana_url}
# 
# With dimensions:
# {metric_dimensions}'''
# EMAIL_MULTIPLE_HOST_BASE = u'''On host "{hostname}" {message}
# 
# Alarm "{alarm_name}" transitioned to the {state} state at {timestamp} UTC
# alarm_id: {alarm_id}
# 
# Lifecycle state: {lifecycle_state}
# Link: {link}
# Link to Grafana: {grafana_url}
# 
# With dimensions:
# {metric_dimensions}'''
# EMAIL_NO_HOST_BASE = u'''On multiple hosts {message}
# 
# Alarm "{alarm_name}" transitioned to the {state} state at {timestamp} UTC
# Alarm_id: {alarm_id}
# 
# Lifecycle state: {lifecycle_state}
# Link: {link}
# Link to Grafana: {grafana_url}
# 
# With dimensions
# {metric_dimensions}'''
# class EmailNotifier(abstract_notifier.AbstractNotifier):
#     def __init__(self, log):
#     def config(self, config=None):
#     def statsd_name(self):
#     def send_notification(self, notification):
#     def _sendmail(self, notification, msg):
#     def _email_error(self, notification):
#     def _smtp_connect(self):
#     def _create_msg(self, hostname, notification, targethost=None):
#     def _get_link_url(self, metric, timestamp_ms):
# def _format_dimensions(notification):
# def register_opts(conf):
# def list_opts():
# 
# Path: monasca_notification/processors/notification_processor.py
# class NotificationProcessor(object):
#     def __init__(self):
#     def _remaining_plugin_types(self):
#     def insert_configured_plugins(self):
#     def send(self, notifications):
# 
# Path: tests/base.py
# class DisableStatsdFixture(fixtures.Fixture):
# class ConfigFixture(oo_cfg.Config):
# class BaseTestCase(oslotest_base.BaseTestCase):
# class PluginTestCase(BaseTestCase):
#     def setUp(self):
#     def __init__(self):
#     def setUp(self):
#     def _clean_config_loaded_flag():
#     def setUp(self):
#     def conf_override(**kw):
#     def conf_default(**kw):
#     def setUp(self, register_opts=None):


# Path: tests/test_notification_processor.py
import time
from unittest import mock
from monasca_notification import notification as m_notification
from monasca_notification.plugins import email_notifier
from monasca_notification.processors import notification_processor as np
from tests import base

        email_notifier.register_opts(base.config.CONF)

        self.conf_default(group='email_notifier', server='my.smtp.server',
                          port=25, user=None, password=None,
                          timeout=60, from_addr='hpcs.mon@hp.com')
        self.conf_default(group='mysql', ssl=None, host='localhost',
                          port='3306', user='mysql_user', db='dbname',
                          passwd='mysql_passwd')
        self.conf_default(group='statsd', host='localhost', port=8125)

        self.conf_default(group='notification_types', enabled=[])

    # ------------------------------------------------------------------------
    # Test helper functions
    # ------------------------------------------------------------------------
    @mock.patch('pymysql.connect')
    @mock.patch('monasca_notification.common.utils.monascastatsd')
    @mock.patch('monasca_notification.plugins.email_notifier.smtplib')
    @mock.patch('monasca_notification.processors.notification_processor.notifiers.log')
    def _start_processor(self, notifications, mock_log, mock_smtp, mock_statsd, mock_pymsql):
        """Start the processor with the proper mocks
        """
        # Since the log runs in another thread I can mock it directly,
        # instead change the methods to put to a queue
        mock_log.warn = self.trap.append
        mock_log.error = self.trap.append

        mock_smtp.SMTP = self._smtpStub

        np.NotificationProcessor.insert_configured_plugins = mock.Mock()

        processor = np.NotificationProcessor()