Skip to content

Commit

Permalink
Add Unit Tests for EventItem class
Browse files Browse the repository at this point in the history
Ref #278
  • Loading branch information
algorys committed Mar 22, 2018
1 parent 1422c4a commit 9c81075
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 4 deletions.
3 changes: 1 addition & 2 deletions alignak_app/qobjects/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def send_datamanager_events(self):
host=event['host']
)

# pylint: disable=too-many-arguments
def add_event(self, event_type, msg, timer=False, host=None):
"""
Add event to events list
Expand Down Expand Up @@ -186,7 +185,7 @@ def remove_event(self, item=None):
events_widget = None


def init_event_widget():
def init_event_widget(): # pragma: no cover
"""
Initialize the global EventsQWidget. Used for drag & drop and send events
Expand Down
3 changes: 1 addition & 2 deletions alignak_app/qobjects/events/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def __init__(self):
self.timer = None
self.host = None

# pylint: disable=too-many-arguments
def initialize(self, event_type, msg, timer=False, host=None):
"""
Initialize QListWidgetItem
Expand Down Expand Up @@ -71,7 +70,7 @@ def initialize(self, event_type, msg, timer=False, host=None):
Qt.DecorationRole, QIcon(settings.get_image(self.get_icon(event_type)))
)

def close_item(self):
def close_item(self): # pragma: no cover
"""
Hide items when timer is finished
Expand Down
111 changes: 111 additions & 0 deletions test/test_event_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2015-2018:
# Matthieu Estrada, ttamalfor@gmail.com
#
# This file is part of (AlignakApp).
#
# (AlignakApp) is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# (AlignakApp) is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with (AlignakApp). If not, see <http://www.gnu.org/licenses/>.

import sys

import unittest2
from PyQt5.Qt import QApplication, QListWidgetItem, Qt

from alignak_app.qobjects.events.item import EventItem


class TestEventItem(unittest2.TestCase):
"""
This file test the EventItem class and methods
"""

@classmethod
def setUpClass(cls):
"""Create QApplication"""
try:
cls.app = QApplication(sys.argv)
except:
pass

def test_initialize_event_item(self):
"""Initialize EventItem"""

under_test = EventItem()

# Fields are None
self.assertIsInstance(under_test, QListWidgetItem)
self.assertIsNone(under_test.host)
self.assertIsNone(under_test.timer)

# Qt Data are empty
self.assertIsNone(under_test.data(Qt.DisplayRole))
self.assertIsNone(under_test.data(Qt.UserRole))

under_test.initialize(
'OK',
'message'
)

# Without host parameter, only "Qt.DisplayRole" is filled
self.assertEqual('message', under_test.data(Qt.DisplayRole))
self.assertIsNone(under_test.host)
self.assertIsNone(under_test.timer)
self.assertIsNone(under_test.data(Qt.UserRole))

def test_initialize_event_item_with_timer(self):
"""Initialize EventItem with QTimer"""

under_test = EventItem()

self.assertIsNone(under_test.timer)

under_test.initialize(
'UNKNOWN',
'message',
timer=True
)

self.assertIsNotNone(under_test.timer)

# Timer starts only by EventsQWidget
self.assertFalse(under_test.timer.isActive())

def test_initialize_event_item_with_qt_userrole(self):
"""Initialize EventItem with Qt.UserRole"""

under_test = EventItem()

self.assertIsNone(under_test.data(Qt.UserRole))

under_test.initialize(
'WARNING',
'message',
host='_id1'
)

self.assertIsNotNone(under_test.data(Qt.UserRole))
self.assertEqual('_id1', under_test.data(Qt.UserRole))

def test_get_event_item_icon(self):
"""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)

0 comments on commit 9c81075

Please sign in to comment.