Skip to content

Commit

Permalink
Propose to enter credentials, if application fails to connect
Browse files Browse the repository at this point in the history
Ref #206
  • Loading branch information
algorys committed Sep 28, 2017
1 parent f09b007 commit 0533790
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
30 changes: 19 additions & 11 deletions alignak_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ def reconnect_to_backend(self, error): # pragma: no cover
"""
Set AlignakApp in reconnect mode and try to login to Backend
:param app_backend: AppBackend object
:type app_backend: AppBackend
:param error: string error to display in banner
:type error: str
"""
Expand Down Expand Up @@ -155,21 +153,18 @@ def run(self): # pragma: no cover
"""
Start all Alignak-app processes and create AppBackend if connection by config file.
:param app_backend: AppBackend object
:type app_backend: alignak_app.core.backend.AppBackend | None
"""

try:
app_backend.login()
except TypeError:
self.display_error_msg()
app_backend.login()

# Check if connected
if app_backend.connected:
# Send Welcome Banner
send_banner(
'OK',
_('Welcome %s, you are connected to Alignak Backend') % app_backend.user['username']
_('Welcome %s, you are connected to Alignak Backend') %
app_backend.user['username'],
duration=10000
)

if 'token' not in app_backend.user:
Expand Down Expand Up @@ -197,8 +192,21 @@ def run(self): # pragma: no cover
# Connect reconnectingmode for AppBackend
self.reconnecting.connect(self.reconnect_to_backend)
else:
# In case of...
self.display_error_msg()
# In case of data provided in config file fails
send_banner(
'WARN',
_('The application fails to connect with the information provided'
' in the configuration file. Please enter your login details!'),
duration=10000
)
login = AppLogin()
login.create_widget()

if login.exec_() == QDialog.Accepted:
self.run()
else:
logger.info('Alignak-App closes...')
sys.exit(0)

@staticmethod
def display_error_msg(): # pragma: no cover
Expand Down
1 change: 1 addition & 0 deletions test/test_app_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_log_to_backend(self):
under_test.backend.url_endpoint_root,
get_app_config('Alignak', 'backend')
)
self.assertTrue(under_test.connected)
self.assertTrue(under_test.backend.authenticated)
self.assertTrue(connect)

Expand Down

0 comments on commit 0533790

Please sign in to comment.