Skip to content

Commit

Permalink
Remove AppBackend from User, Systray package
Browse files Browse the repository at this point in the history
Fix reconnecting in AppBackend
Ref #201
  • Loading branch information
algorys committed Sep 28, 2017
1 parent 19d1380 commit 35f35f9
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 65 deletions.
2 changes: 1 addition & 1 deletion alignak_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def run(self): # pragma: no cover

# TrayIcon
self.tray_icon = TrayIcon(QIcon(get_image_path('icon')))
self.tray_icon.build_menu(app_backend, self.dashboard)
self.tray_icon.build_menu(self.dashboard)
self.tray_icon.show()

# Give ALignakApp for AppBackend reconnecting mode
Expand Down
4 changes: 2 additions & 2 deletions alignak_app/core/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def get(self, endpoint, params=None, projection=None, all_items=False):
self.connected = False
if self.app:
if not self.app.reconnect_mode:
self.app.reconnecting.emit(self, str(e))
self.app.reconnecting.emit(str(e))
return request

return request
Expand Down Expand Up @@ -233,7 +233,7 @@ def patch(self, endpoint, data, headers):
logger.warning('Application checks the connection with the Backend...')
self.connected = False
if not self.app.reconnect_mode:
self.app.reconnecting.emit(self, str(e))
self.app.reconnecting.emit(str(e))
return False

if request['_status'] == 'OK':
Expand Down
12 changes: 4 additions & 8 deletions alignak_app/systray/tray_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@ def __init__(self, icon, parent=None):
self.synthesis = None
self.user = None

def build_menu(self, app_backend, dashboard):
def build_menu(self, dashboard):
"""
Initialize and create each action of menu.
:param app_backend: AppBackend object
:type app_backend: alignak_app.core.backend.AppBackend
:param dashboard: Dashboard QWidget
:type dashboard: alignak_app.dashboard.app_dashboard.Dashboard
"""
Expand All @@ -77,7 +75,7 @@ def build_menu(self, app_backend, dashboard):
self.create_synthesis_action()
self.create_dashboard_action(dashboard)
self.create_status_action()
self.create_user_action(app_backend)
self.create_user_action()
self.menu.addSeparator()

self.create_hosts_actions()
Expand Down Expand Up @@ -285,20 +283,18 @@ def create_status_action(self):

logger.info('Create Status Action')

def create_user_action(self, app_backend):
def create_user_action(self):
"""
Create User object who manage UserProfile QWidget
:param app_backend: AppBackend data
:type app_backend: AppBackend
"""

self.qaction_factory.create(
'user',
_('View my profile'),
self
)
self.user = UserManager(app_backend)
self.user = UserManager()

self.qaction_factory.get('user').triggered.connect(self.user.show_user_widget)

Expand Down
3 changes: 1 addition & 2 deletions alignak_app/user/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ class PasswordDialog(QDialog):
Class who create PasswordDialog QDialog
"""

def __init__(self, app_backend, parent=None):
def __init__(self, parent=None):
super(PasswordDialog, self).__init__(parent)
self.setWindowTitle('User Password')
self.setWindowFlags(Qt.FramelessWindowHint)
self.setStyleSheet(get_css())
self.setWindowIcon(QIcon(get_image_path('icon')))
self.setFixedSize(300, 300)
# Fields
self.app_backend = app_backend
self.pass_edit = None
self.confirm_edit = None
self.help_label = None
Expand Down
5 changes: 2 additions & 3 deletions alignak_app/user/user_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class UserManager(object):
User manage the UserProfile QWidget creation
"""

def __init__(self, app_backend):
self.app_backend = app_backend
def __init__(self, ):
self.user_widget = None

def create_user_profile(self):
Expand All @@ -55,7 +54,7 @@ def create_user_profile(self):
self.user_widget.deleteLater()
self.user_widget = None

self.user_widget = UserProfile(self.app_backend)
self.user_widget = UserProfile()
self.user_widget.initialize()

if old_pos:
Expand Down
18 changes: 9 additions & 9 deletions alignak_app/user/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from PyQt5.QtWidgets import QWidget, QPushButton, QCheckBox # pylint: disable=no-name-in-module

from alignak_app.core.utils import get_image_path, get_css
from alignak_app.core.backend import app_backend
from alignak_app.user.password import PasswordDialog
from alignak_app.widgets.app_widget import AppQWidget
from alignak_app.widgets.banner import send_banner
Expand All @@ -45,11 +46,10 @@ class UserProfile(QWidget):

update_profile = pyqtSignal(name='userprofile')

def __init__(self, app_backend, parent=None):
def __init__(self, parent=None):
super(UserProfile, self).__init__(parent)
self.setStyleSheet(get_css())
# Fields
self.app_backend = app_backend
self.user = {}
self.app_widget = None
self.host_notif_state = None
Expand Down Expand Up @@ -124,7 +124,7 @@ def get_user_data(self):
'service_notification_options',
]

self.user = self.app_backend.get_user(projection)
self.user = app_backend.get_user(projection)

if not self.user:
for key in projection:
Expand Down Expand Up @@ -244,7 +244,7 @@ def get_realm_name(self):
'alias'
]

realm = self.app_backend.get(endpoint, projection=projection)
realm = app_backend.get(endpoint, projection=projection)

if realm:
if realm['alias']:
Expand Down Expand Up @@ -347,7 +347,7 @@ def button_clicked(self):
self.notes_edit.show()
self.notes_edit.setFocus()
elif "password" in btn.objectName():
pass_dialog = PasswordDialog(self.app_backend)
pass_dialog = PasswordDialog()
pass_dialog.initialize()

if pass_dialog.exec_() == QDialog.Accepted:
Expand All @@ -357,7 +357,7 @@ def button_clicked(self):
headers = {'If-Match': self.user['_etag']}
endpoint = '/'.join(['user', self.user['_id']])

patched = self.app_backend.patch(endpoint, data, headers)
patched = app_backend.patch(endpoint, data, headers)

if patched:
message = _("Your password has been updated !")
Expand All @@ -379,7 +379,7 @@ def patch_notes(self):
headers = {'If-Match': self.user['_etag']}
endpoint = '/'.join(['user', self.user['_id']])

patched = self.app_backend.patch(endpoint, data, headers)
patched = app_backend.patch(endpoint, data, headers)

if patched:
name = self.user['alias'] if self.user['alias'] else self.user['name']
Expand Down Expand Up @@ -549,7 +549,7 @@ def enable_notifications(self): # pragma: no cover
headers = {'If-Match': self.user['_etag']}
endpoint = '/'.join(['user', self.user['_id']])

patched = self.app_backend.patch(endpoint, data, headers)
patched = app_backend.patch(endpoint, data, headers)

if patched:
enabled = 'enabled' if notification_enabled else 'disabled'
Expand Down Expand Up @@ -643,7 +643,7 @@ def get_period_name(self, uuid):

endpoint = '/'.join(['timeperiod', uuid])

period = self.app_backend.get(endpoint, projection=projection)
period = app_backend.get(endpoint, projection=projection)

if period:
if 'alias' in period:
Expand Down
10 changes: 5 additions & 5 deletions test/test_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

class TestAppNotifier(unittest2.TestCase):
"""
This file test the AppNotifier class.
TODO This file test the AppNotifier class.
"""

init_config()
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_other_objects_do_not_modify_notifier(self):
self.assertIsNotNone(under_test.dashboard)
self.assertFalse(under_test.changes)

tray_icon.build_menu(self.backend, dashboard)
tray_icon.build_menu(dashboard)

self.assertIsNotNone(under_test.tray_icon)
self.assertIsNotNone(under_test.app_backend)
Expand All @@ -87,7 +87,7 @@ def test_check_data(self):

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

# Start notifier
under_test.set_interval()
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_states_change(self):
dashboard.initialize()

tray_icon = TrayIcon(self.icon)
tray_icon.build_menu(self.backend, dashboard)
tray_icon.build_menu(dashboard)

# Initialize Notifier
under_test = AppNotifier()
Expand All @@ -129,7 +129,7 @@ def test_states_change(self):
self.assertIsNone(under_test.old_synthesis)

def test_diff_last_state(self):
"""Diff Last Backend SState"""
"""Diff Last Backend State"""

self.backend = AppBackend()
self.backend.login()
Expand Down
8 changes: 3 additions & 5 deletions test/test_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class TestUserManager(unittest2.TestCase):
"""
This file test the PasswordDialog class.
TODO This file test the PasswordDialog class.
"""

init_config()
Expand All @@ -52,24 +52,22 @@ def setUpClass(cls):
def test_initialize(self):
"""Initialize PasswordDialog"""

under_test = PasswordDialog(self.app_backend)
under_test = PasswordDialog()

self.assertTrue(under_test.app_backend)
self.assertIsNone(under_test.pass_edit)
self.assertIsNone(under_test.confirm_edit)
self.assertIsNone(under_test.help_label)

under_test.initialize()

self.assertTrue(under_test.app_backend)
self.assertIsNotNone(under_test.pass_edit)
self.assertIsNotNone(under_test.confirm_edit)
self.assertIsNotNone(under_test.help_label)

def test_center(self):
"""Center PasswordDialog"""

under_test = PasswordDialog(self.app_backend)
under_test = PasswordDialog()

old_pos_test = under_test.pos()

Expand Down
6 changes: 3 additions & 3 deletions test/test_tray_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

class TestTrayIcon(unittest2.TestCase):
"""
This file test the TrayIcon class.
TODO This file test the TrayIcon class.
"""

init_config()
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_build_menu(self):
self.assertIsNone(under_test.alignak_status)
self.assertIsNotNone(under_test.qaction_factory)

under_test.build_menu(self.backend, dashboard_test)
under_test.build_menu(dashboard_test)

# Assert actions are added in Menu
self.assertTrue(under_test.menu.actions())
Expand All @@ -138,7 +138,7 @@ def test_update_menus_actions(self):
under_test = TrayIcon(TestTrayIcon.icon)

dashboard_test = Dashboard()
under_test.build_menu(self.backend, dashboard_test)
under_test.build_menu(dashboard_test)

self.assertEqual('Hosts UP, Wait...',
under_test.qaction_factory.get('hosts_up').text())
Expand Down
12 changes: 4 additions & 8 deletions test/test_user_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class TestUserManager(unittest2.TestCase):
"""
This file test the UserManager class.
TODO This file test the UserManager class.
"""

init_config()
Expand All @@ -52,25 +52,21 @@ def setUpClass(cls):
def test_create_user_profile(self):
"""Create UserProfile QWidget"""

under_test = UserManager(self.app_backend)
under_test = UserManager()

self.assertFalse(under_test.user_widget)
self.assertTrue(under_test.app_backend)

under_test.create_user_profile()

self.assertTrue(under_test.user_widget)
self.assertTrue(under_test.app_backend)

def test_show_user_widget(self):
"""Show User QWidget"""

under_test = UserManager(self.app_backend)
under_test = UserManager()

self.assertFalse(under_test.user_widget)
self.assertTrue(under_test.app_backend)

under_test.show_user_widget()

self.assertTrue(under_test.user_widget)
self.assertTrue(under_test.app_backend)
self.assertTrue(under_test.user_widget)
Loading

0 comments on commit 35f35f9

Please sign in to comment.