Skip to content

Commit

Permalink
Let user choose to display Problems or Synthesis
Browse files Browse the repository at this point in the history
Ref #275, Add Unit Tests for AppQmainWindow
  • Loading branch information
algorys committed Mar 17, 2018
1 parent 0d15e61 commit 38e8d2a
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 6 deletions.
7 changes: 5 additions & 2 deletions alignak_app/qobjects/app_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
++++++++
App Main manage creation of QMainWindow for:
* :class:`Dock <alignak_app.qobjects.dock.dock.DockQWidget>` (Right part)
* :class:`Panel <alignak_app.qobjects.panel.panel.PanelQWidget>` (Left part)
* :class:`Dock <alignak_app.qobjects.dock.DockQWidget>` (Right part)
* :class:`Panel <alignak_app.qobjects.panel.PanelQWidget>` (Left part)
"""

from logging import getLogger
Expand Down Expand Up @@ -96,6 +96,9 @@ def initialize(self):
else:
pass

if settings.get_config('Alignak-app', 'problems', boolean=True):
self.panel_widget.tab_widget.setCurrentIndex(1)

def mousePressEvent(self, event): # pragma: no cover - not testable
""" QWidget.mousePressEvent(QMouseEvent) """

Expand Down
1 change: 1 addition & 0 deletions alignak_app/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Settings(object):

},
'Alignak-app': {
'problems': False,
'requests_interval': 30,
'notification_duration': 30,
'spy_interval': 30,
Expand Down
10 changes: 8 additions & 2 deletions etc/settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ locale = en_US
; Default is "min". Available options are "no", "max", "min".
display = min

; Problems at start
; ------------------------------------------------------------------------------------------
; Defines if "Problems" tab is displayed by default at start
; Default is no. Set to "yes" to display problems by default.
problems = no

; Requests interval
; ------------------------------------------------------------------------------------------
; Define interval of App requests. App make regular requests
Expand All @@ -72,8 +78,8 @@ notification_duration = 30
; Spy checks interval
; ------------------------------------------------------------------------------------------
; Define checks interval in seconds for spied hosts. One host check by interval.
; Default is 60
spy_interval = 60
; Default is 30
spy_interval = 30

; Update dock "Status"
; ------------------------------------------------------------------------------------------
Expand Down
10 changes: 8 additions & 2 deletions test/etc/settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ locale = en_US
; Default is "min". Available options are "no", "max", "min".
display = min

; Problems at start
; ------------------------------------------------------------------------------------------
; Defines if "Problems" tab is displayed by default at start
; Default is no. Set to "yes" to display problems by default.
problems = no

; Requests interval
; ------------------------------------------------------------------------------------------
; Define interval of App requests. App make regular requests
Expand All @@ -72,8 +78,8 @@ notification_duration = 30
; Spy checks interval
; ------------------------------------------------------------------------------------------
; Define checks interval in seconds for spied hosts. One host check by interval.
; Default is 60
spy_interval = 60
; Default is 30
spy_interval = 30

; Update dock "Status"
; ------------------------------------------------------------------------------------------
Expand Down
136 changes: 136 additions & 0 deletions test/test_app_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/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.QtWidgets import QApplication

from alignak_app.backend.datamanager import data_manager
from alignak_app.utils.config import settings

from alignak_app.qobjects.events.events import init_event_widget
from alignak_app.qobjects.app_main import AppQMainWindow


class TestAppQMainWindow(unittest2.TestCase):
"""
This file test methods of AppQMainWindow class.
"""

@classmethod
def setUpClass(cls):
"""Create QApplication"""

try:
cls.app = QApplication(sys.argv)
except:
pass

def test_initialize_app_main_window(self):
"""Initialize AppQMainWindow"""

under_test = AppQMainWindow()

self.assertTrue(under_test.panel_widget)
self.assertTrue(under_test.dock)
self.assertIsNone(under_test.offset)

data_manager.update_database('host', [])
data_manager.update_database('service', [])
init_event_widget()
under_test.initialize()

self.assertTrue(under_test.panel_widget)
self.assertTrue(under_test.dock)
self.assertIsNone(under_test.offset)

def test_app_main_window_display_settings(self):
"""Display AppQMainWindow at Start"""

under_test = AppQMainWindow()
data_manager.update_database('host', [])
data_manager.update_database('service', [])

self.assertFalse(under_test.isVisible())
settings.edit_setting_value('Alignak-app', 'display', 'min')

under_test.initialize()

# AppQMainWindow is visible but not maximized
self.assertEqual('min', settings.get_config('Alignak-app', 'display'))
self.assertTrue(under_test.isVisible())
self.assertFalse(under_test.isMaximized())
under_test.close()

settings.edit_setting_value('Alignak-app', 'display', 'max')

under_test = AppQMainWindow()
under_test.initialize()

# AppQMainWindow is visible and Maximized
self.assertEqual('max', settings.get_config('Alignak-app', 'display'))
self.assertTrue(under_test.isVisible())
self.assertTrue(under_test.isMaximized())
under_test.close()

settings.edit_setting_value('Alignak-app', 'display', 'no')

under_test = AppQMainWindow()
under_test.initialize()

# AppQMainWindow is not visible and not maximized
self.assertEqual('no', settings.get_config('Alignak-app', 'display'))
self.assertFalse(under_test.isVisible())
self.assertFalse(under_test.isMaximized())
under_test.close()

# Restore default setting
settings.edit_setting_value('Alignak-app', 'display', 'min')

def test_default_view_is_problems(self):
"""Display Problems View by Default"""

settings.edit_setting_value('Alignak-app', 'problems', 'no')

under_test = AppQMainWindow()
data_manager.update_database('host', [])
data_manager.update_database('service', [])
init_event_widget()

self.assertEqual(-1, under_test.panel_widget.tab_widget.currentIndex())

under_test.initialize()

self.assertEqual(False, settings.get_config('Alignak-app', 'problems', boolean=True))
self.assertEqual(0, under_test.panel_widget.tab_widget.currentIndex())

# Make "Problems" as default view
settings.edit_setting_value('Alignak-app', 'problems', 'yes')

under_test = AppQMainWindow()
under_test.initialize()

self.assertEqual(True, settings.get_config('Alignak-app', 'problems', boolean=True))
self.assertEqual(1, under_test.panel_widget.tab_widget.currentIndex())

# Reset settings
settings.edit_setting_value('Alignak-app', 'problems', 'no')
1 change: 1 addition & 0 deletions test/test_spy_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def test_remove_event(self):
def test_send_spy_events(self):
"""Send Spy Events"""

init_event_widget()
under_test = SpyQWidget()
under_test.initialize()

Expand Down

0 comments on commit 38e8d2a

Please sign in to comment.