Skip to content

Commit

Permalink
Add counter when host are spied, add Unit Tests
Browse files Browse the repository at this point in the history
Ref #256
  • Loading branch information
algorys committed Mar 10, 2018
1 parent 1b73362 commit 0244247
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
17 changes: 16 additions & 1 deletion alignak_app/qobjects/events/spy.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def dropEvent(self, event):
self.takeItem(row)
self.item_dropped.emit(event.source().currentItem())

self.parent().update_parent_spytab()


class SpyQWidget(QWidget):
"""
Expand Down Expand Up @@ -181,10 +183,23 @@ def send_spy_events(self):

def remove_event(self):
"""
Remove item when user double click on an item
Remove item when user double click on an item, update parent tab text
"""

item = self.spy_list_widget.currentItem()
self.spy_list_widget.spied_hosts.remove(item.host)
self.spy_list_widget.takeItem(self.spy_list_widget.currentRow())

self.update_parent_spytab()

def update_parent_spytab(self):
"""
Update the parent spy tab text
"""

if self.parent():
self.parent().parent().setTabText(
2, "Spied Hosts (%d)" % self.spy_list_widget.count()
)
9 changes: 9 additions & 0 deletions alignak_app/qobjects/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def spy_host(self):
QIcon(settings.get_image(self.spy_icons[False]))
)
self.spy_button.setText(self.spy_text[False])
self.update_panel_spytab()
else:
self.spy_button.setEnabled(True)
self.spy_button.setIcon(
Expand All @@ -192,6 +193,14 @@ def spy_host(self):
self.spy_button.style().unpolish(self.spy_button)
self.spy_button.style().polish(self.spy_button)

def update_panel_spytab(self):
"""
Update text of the psy panel tab
"""

self.tab_widget.setTabText(2, "Spied Hosts (%d)" % self.spy_widget.spy_list_widget.count())

def create_line_search(self, hostnames_list=None):
"""
Add all hosts to QLineEdit and set QCompleter
Expand Down
59 changes: 58 additions & 1 deletion test/test_spy_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

from PyQt5.Qt import QApplication

from alignak_app.backend.datamanager import data_manager
from alignak_app.items.host import Host

from alignak_app.qobjects.events.spy import SpyQWidget, SpyQListWidget
from alignak_app.qobjects.events.item import EventItem
from alignak_app.qobjects.events.events import init_event_widget
Expand Down Expand Up @@ -83,4 +86,58 @@ def test_remove_event(self):
under_test.remove_event()

# Event is no more here
self.assertIsNone(under_test.spy_list_widget.item(1))
self.assertIsNone(under_test.spy_list_widget.item(1))

def test_send_spy_events(self):
"""Send Spy Events"""

under_test = SpyQWidget()
under_test.initialize()

# Hint item is here
self.assertEqual(1, under_test.spy_list_widget.count())
self.assertFalse(under_test.spied_to_send)

# Filling database
host_test = Host()
host_test.create(
'spy1',
{
'_id': 'spy1',
'ls_downtimed': False,
'ls_acknowledged': False,
'active_checks_enabled': True,
'passive_checks_enabled': True,
'ls_state': 'DOWN'
},
'hostname'
)
host_test_2 = Host()
host_test_2.create(
'spy2',
{
'_id': 'spy2',
'ls_downtimed': False,
'ls_acknowledged': False,
'active_checks_enabled': True,
'passive_checks_enabled': True,
'ls_state': 'DOWN'
},
'hostname'
)
data_manager.update_database('host', [host_test, host_test_2])

under_test.spy_list_widget.add_spy_host('spy1')
under_test.spy_list_widget.add_spy_host('spy2')

# Item hint have been removed, host spied added
self.assertEqual(2, under_test.spy_list_widget.count())
self.assertFalse(under_test.spied_to_send)

under_test.send_spy_events()

# Spy event to send has been filled, left only 'spy2'
self.assertEqual(2, under_test.spy_list_widget.count())
self.assertTrue(under_test.spied_to_send)
self.assertEqual(1, len(under_test.spied_to_send))
self.assertTrue('spy2' in under_test.spied_to_send)

0 comments on commit 0244247

Please sign in to comment.