Skip to content

Commit

Permalink
Remove AppBackend from AppNotifier
Browse files Browse the repository at this point in the history
Ref #201
  • Loading branch information
algorys committed Sep 28, 2017
1 parent 52c3254 commit e4f8a0d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
2 changes: 1 addition & 1 deletion alignak_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def run(self): # pragma: no cover

# Start Notifier which will interrogate the backend periodically
self.notifier = AppNotifier()
self.notifier.initialize(app_backend, self.tray_icon, self.dashboard)
self.notifier.initialize(self.tray_icon, self.dashboard)

self.notifier_timer.start(self.notifier.interval)
self.notifier_timer.timeout.connect(self.notifier.check_data)
Expand Down
7 changes: 4 additions & 3 deletions alignak_app/core/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
# along with (AlignakApp). If not, see <http://www.gnu.org/licenses/>.

"""
DataManager TODO
DataManager manage and store the Alignak data provided by BackendQthread
"""


class DataManager(object):
"""
TODO
Class who store Alignak data
"""

def __init__(self):
Expand All @@ -49,7 +49,8 @@ def update_item_type(self, item_type, data):

def get_item(self, item_type, item_id):
"""
TODO
Get the wanted item by "_id"
:param item_type:
:param item_id:
:return:
Expand Down
15 changes: 6 additions & 9 deletions alignak_app/core/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# along with (AlignakApp). If not, see <http://www.gnu.org/licenses/>.

"""
Notifier manage notifications and collect data from app_backend.
Notifier manage notifications and collect data from AppBackend.
"""

import sys
Expand All @@ -31,6 +31,7 @@
from logging import getLogger

from alignak_app.core.utils import get_app_config
from alignak_app.core.backend import app_backend
from alignak_app.widgets.banner import send_banner


Expand All @@ -45,27 +46,23 @@ class AppNotifier(object):
first_start = True

def __init__(self):
self.app_backend = None
self.tray_icon = None
self.dashboard = None
self.changes = False
self.interval = 0
self.old_synthesis = None
self.old_notifications = []

def initialize(self, app_backend, tray_icon, dashboard):
def initialize(self, tray_icon, dashboard):
"""
AppNotifier manage notifications and changes
:param app_backend: AppBackend object
:type app_backend: alignak_app.core.backend.AppBackend
:param tray_icon: TrayIcon object
:type tray_icon: alignak_app.systray.tray_icon.TrayIcon
:param dashboard: Dashboard object
:type dashboard: alignak_app.dashboard.app_dashboard.Dashboard
"""

self.app_backend = app_backend
self.tray_icon = tray_icon
self.dashboard = dashboard

Expand Down Expand Up @@ -133,7 +130,7 @@ def check_data(self):
self.send_notifications()

# Update Synthesis
synthesis = self.app_backend.synthesis_count()
synthesis = app_backend.synthesis_count()

if self.first_start:
# Simulate old state
Expand Down Expand Up @@ -213,7 +210,7 @@ def send_notifications(self):
'sort': '-_updated'
}

notifications = self.app_backend.get('history', params=params)
notifications = app_backend.get('history', params=params)
logger.debug('%s founded: ', str(notifications))

for notif in notifications['_items']:
Expand All @@ -224,7 +221,7 @@ def send_notifications(self):
if 'imported_admin' in user:
user = 'admin'
# If notification is for the current user
if user in self.app_backend.user['username']:
if user in app_backend.user['username']:
# Define all var for message
item_type = 'HOST' if 'HOST' in message_split[0] else 'SERVICE'
host = message_split[1]
Expand Down
21 changes: 6 additions & 15 deletions test/test_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import unittest2

from alignak_app.core.backend import AppBackend
from alignak_app.core.backend import app_backend
from alignak_app.core.notifier import AppNotifier
from alignak_app.core.utils import get_image_path
from alignak_app.core.utils import init_config
Expand All @@ -43,8 +43,7 @@ class TestAppNotifier(unittest2.TestCase):

icon = QIcon(get_image_path('icon'))

backend = AppBackend()
backend.login()
app_backend.login()

@classmethod
def setUpClass(cls):
Expand All @@ -63,17 +62,15 @@ def test_other_objects_do_not_modify_notifier(self):
dashboard.initialize()

under_test = AppNotifier()
under_test.initialize(self.backend, tray_icon, dashboard)
under_test.initialize(tray_icon, dashboard)

self.assertIsNotNone(under_test.tray_icon)
self.assertIsNotNone(under_test.app_backend)
self.assertIsNotNone(under_test.dashboard)
self.assertFalse(under_test.changes)

tray_icon.build_menu(dashboard)

self.assertIsNotNone(under_test.tray_icon)
self.assertIsNotNone(under_test.app_backend)
self.assertIsNotNone(under_test.dashboard)
self.assertFalse(under_test.changes)

Expand All @@ -86,7 +83,7 @@ def test_check_data(self):
dashboard.initialize()

under_test = AppNotifier()
under_test.initialize(self.backend, tray_icon, dashboard)
under_test.initialize(tray_icon, dashboard)
tray_icon.build_menu(dashboard)

# Start notifier
Expand All @@ -109,8 +106,6 @@ def test_check_data(self):

def test_states_change(self):
"""States and Notify Changes"""
self.backend = AppBackend()
self.backend.login()

# TrayIcon and Dashboard for notifier
dashboard = Dashboard()
Expand All @@ -121,7 +116,7 @@ def test_states_change(self):

# Initialize Notifier
under_test = AppNotifier()
under_test.initialize(self.backend, tray_icon, dashboard)
under_test.initialize(tray_icon, dashboard)

# Changes are True, first_start is True
self.assertFalse(under_test.changes)
Expand All @@ -131,23 +126,19 @@ def test_states_change(self):
def test_diff_last_state(self):
"""Diff Last Backend State"""

self.backend = AppBackend()
self.backend.login()

# TrayIcon and Dashboard for notifier
tray_icon_test = TrayIcon(self.icon)
dashboard_test = Dashboard()

notifier_test = AppNotifier()
notifier_test.app_backend = self.backend
notifier_test.tray_icon = tray_icon_test
notifier_test.dashboard = dashboard_test

# Notifier check data to get first synthesys counts
notifier_test.check_data()

# Get synthesis test to test diff between check
synthesis = self.backend.synthesis_count()
synthesis = app_backend.synthesis_count()
under_test = notifier_test.diff_last_states(synthesis)

fields_test = {
Expand Down

0 comments on commit e4f8a0d

Please sign in to comment.