# Path: alignak_app/qobjects/events/item.py
# class EventItem(QListWidgetItem):
#     """
#         Class who create an event QListWidgetItem
#     """
# 
#     def __init__(self):
#         super(EventItem, self).__init__()
#         self.timer = None
#         self.host = None
# 
#     def initialize(self, event_type, msg, timer=False, host=None):
#         """
#         Initialize QListWidgetItem
# 
#         :param event_type: the type of event: OK, DOWN, ACK, ...
#         :type event_type: str
#         :param msg: message of event
#         :type msg: str
#         :param timer: timer to hide event at end of time
#         :type timer: bool
#         :param host: _id of host. Only necessary if "be_spied" is True
#         :type host: None | str
#         """
# 
#         self.host = host
#         if host:
#             self.setData(Qt.UserRole, host)
# 
#         if timer:
#             self.timer = QTimer()
# 
#         self.setData(Qt.DisplayRole, "%s" % msg)
#         msg_to_send = '%s. (Send at %s)' % (msg, get_current_time())
#         self.setToolTip(msg_to_send)
# 
#         self.setData(
#             Qt.DecorationRole, QIcon(settings.get_image(self.get_icon(event_type)))
#         )
# 
#     def close_item(self):  # pragma: no cover
#         """
#         Hide items when timer is finished
# 
#         """
# 
#         self.setHidden(True)
# 
#     @staticmethod
#     def get_icon(event_type):
#         """
#         Return name of icon event
# 
#         :param event_type: type of event
#         :type event_type: str
#         :return: name of icon
#         :rtype: str
#         """
# 
#         available_icons = {
#             'event_ok': ['OK', 'UP'],
#             'event_info': ['UNKNOWN', 'INFO', 'TODO'],
#             'event_warn': ['WARNING', 'UNREACHABLE', 'WARN'],
#             'event_alert': ['DOWN', 'CRITICAL', 'ALERT'],
#             'acknowledge': ['ACK'],
#             'downtime': ['DOWNTIME', 'DOWNTIMESTART (DOWN)'],
#             'spy': ['SPY']
#         }
# 
#         for key, _ in available_icons.items():
#             if event_type in available_icons[key]:
#                 return key
# 
#         return 'error'
# 
#     @staticmethod
#     def get_event_type(data):
#         """
#         Return event type depending of data content
# 
#         :param data: data of backend item
#         :type data: dict
#         :return: event type for item
#         :rtype: str
#         """
# 
#         event_type = ''
#         if data['ls_acknowledged']:
#             event_type = 'ACK'
#         if data['ls_downtimed']:
#             event_type = 'DOWNTIME'
# 
#         if not event_type:
#             event_type = data['ls_state']
# 
#         return event_type


import sys
import unittest2
from PyQt5.Qt import QApplication, QListWidgetItem, Qt
from alignak_app.qobjects.events.item import EventItem
        """Get Event Item Icon"""

        # Not found = error
        under_test = EventItem.get_icon(None)
        self.assertEqual('error', under_test)

        # Found not equal to error
        under_test = EventItem.get_icon('UNREACHABLE')
        self.assertNotEqual('error', under_test)

    def test_get_event_type(self):
        """Get Event Type"""

        data_test = {
            'ls_state': 'OK',
            'ls_acknowledged': False,
            'ls_downtimed': False,
        }

        # Return state if not ack or downtimed
        under_test = EventItem.get_event_type(data_test)
        self.assertEqual('OK', under_test)

        # Return "ACK" if acknowledged
        data_test['ls_acknowledged'] = True
        under_test = EventItem.get_event_type(data_test)
        self.assertEqual('ACK', under_test)

        # Return "DOWNTIME" if downtimed
        data_test['ls_downtimed'] = True

# Path: alignak_app/qobjects/events/item.py
# class EventItem(QListWidgetItem):
#     """
#         Class who create an event QListWidgetItem
#     """
# 
#     def __init__(self):
#         super(EventItem, self).__init__()
#         self.timer = None
#         self.host = None
# 
#     def initialize(self, event_type, msg, timer=False, host=None):
#         """
#         Initialize QListWidgetItem
# 
#         :param event_type: the type of event: OK, DOWN, ACK, ...
#         :type event_type: str
#         :param msg: message of event
#         :type msg: str
#         :param timer: timer to hide event at end of time
#         :type timer: bool
#         :param host: _id of host. Only necessary if "be_spied" is True
#         :type host: None | str
#         """
# 
#         self.host = host
#         if host:
#             self.setData(Qt.UserRole, host)
# 
#         if timer:
#             self.timer = QTimer()
# 
#         self.setData(Qt.DisplayRole, "%s" % msg)
#         msg_to_send = '%s. (Send at %s)' % (msg, get_current_time())
#         self.setToolTip(msg_to_send)
# 
#         self.setData(
#             Qt.DecorationRole, QIcon(settings.get_image(self.get_icon(event_type)))
#         )
# 
#     def close_item(self):  # pragma: no cover
#         """
#         Hide items when timer is finished
# 
#         """
# 
#         self.setHidden(True)
# 
#     @staticmethod
#     def get_icon(event_type):
#         """
#         Return name of icon event
# 
#         :param event_type: type of event
#         :type event_type: str
#         :return: name of icon
#         :rtype: str
#         """
# 
#         available_icons = {
#             'event_ok': ['OK', 'UP'],
#             'event_info': ['UNKNOWN', 'INFO', 'TODO'],
#             'event_warn': ['WARNING', 'UNREACHABLE', 'WARN'],
#             'event_alert': ['DOWN', 'CRITICAL', 'ALERT'],
#             'acknowledge': ['ACK'],
#             'downtime': ['DOWNTIME', 'DOWNTIMESTART (DOWN)'],
#             'spy': ['SPY']
#         }
# 
#         for key, _ in available_icons.items():
#             if event_type in available_icons[key]:
#                 return key
# 
#         return 'error'
# 
#     @staticmethod
#     def get_event_type(data):
#         """
#         Return event type depending of data content
# 
#         :param data: data of backend item
#         :type data: dict
#         :return: event type for item
#         :rtype: str
#         """
# 
#         event_type = ''
#         if data['ls_acknowledged']:
#             event_type = 'ACK'
#         if data['ls_downtimed']:
#             event_type = 'DOWNTIME'
# 
#         if not event_type:
#             event_type = data['ls_state']
# 
#         return event_type


# Path: test/test_event_item.py
import sys
import unittest2
from PyQt5.Qt import QApplication, QListWidgetItem, Qt
from alignak_app.qobjects.events.item import EventItem

        """Get Event Item Icon"""

        # Not found = error
        under_test = EventItem.get_icon(None)
        self.assertEqual('error', under_test)

        # Found not equal to error
        under_test = EventItem.get_icon('UNREACHABLE')
        self.assertNotEqual('error', under_test)

    def test_get_event_type(self):
        """Get Event Type"""

        data_test = {
            'ls_state': 'OK',
            'ls_acknowledged': False,
            'ls_downtimed': False,
        }

        # Return state if not ack or downtimed
        under_test = EventItem.get_event_type(data_test)
        self.assertEqual('OK', under_test)

        # Return "ACK" if acknowledged
        data_test['ls_acknowledged'] = True
        under_test = EventItem.get_event_type(data_test)
        self.assertEqual('ACK', under_test)

        # Return "DOWNTIME" if downtimed
        data_test['ls_downtimed'] = True

        under_test = EventItem.get_event_type(data_test)