1
# -*- coding: utf-8 -*-
3
# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
5
# Copyright 2010 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
"""The test suite for the control panel user interface (basics)."""
21
from __future__ import division
24
from ubuntuone.controlpanel.gui.gtk import gui
25
from ubuntuone.controlpanel.gui.gtk.tests import BaseTestCase, FakedSSOBackend
26
from ubuntuone.controlpanel.tests import TOKEN
28
from ubuntuone.devtools.testcase import skipIf
30
# Attribute 'yyy' defined outside __init__, access to a protected member
31
# pylint: disable=W0201, W0212
34
class FakeUnity(object):
35
"""Fake Unity module."""
38
class FakeLauncherEntryProps(object):
39
"""A fake Unity.LauncherEntry.props"""
44
THE_FLEP = FakeLauncherEntryProps()
47
class FakeLauncherEntry(object):
48
"""A fake Unity.LauncherEntry"""
51
"""Initialize this fake instance."""
55
def get_for_desktop_id(dotdesktop):
56
"""Find the LauncherEntry for a given dotdesktop."""
57
return FakeLauncherEntry()
60
class FakeControlPanelService(object):
62
def __init__(self, window):
66
def draw_attention(self):
67
"""Draw attention to the control panel."""
68
self.called.append('draw_attention')
70
def switch_to(self, panel):
71
"""Switch to named panel."""
72
self.called.append(('switch_to', panel))
75
class ControlPanelMixinTestCase(BaseTestCase):
76
"""The test suite for the control panel widget."""
78
klass = gui.ControlPanelMixin
81
def test_is_a_control_panel_mixin(self):
82
"""Inherits from ControlPanelMixin."""
83
self.assertIsInstance(self.ui, gui.ControlPanelMixin)
85
def test_ui_can_be_created(self):
86
"""UI main class exists and can be created."""
87
self.assertTrue(self.ui is not None)
90
class ControlPanelWindowTestCase(BaseTestCase):
91
"""The test suite for the control panel window."""
93
klass = gui.ControlPanelWindow
96
self.patch(gui, 'ControlPanelService', FakeControlPanelService)
97
super(ControlPanelWindowTestCase, self).setUp()
99
def test_is_a_window(self):
100
"""Inherits from gtk.Window."""
101
self.assertIsInstance(self.ui, gui.gtk.Window)
103
def test_startup_visibility(self):
104
"""The widget is visible at startup."""
105
self.assertTrue(self.ui.get_visible(), 'was not visible at startup.')
107
def test_main_start_gtk_main_loop(self):
108
"""The GTK main loop is started when calling main()."""
109
self.patch(gui.gtk, 'main', self._set_called)
111
self.assertEqual(self._called, ((), {}), 'gtk.main was not called.')
113
def test_closing_stops_the_main_lopp(self):
114
"""The GTK main loop is stopped when closing the window."""
115
self.patch(gui.gtk, 'main_quit', self._set_called)
116
self.ui.emit('delete-event', None)
118
self._called, ((), {}), 'gtk.main_quit was not called.')
120
def test_title_is_correct(self):
121
"""The window title is correct."""
122
expected = gui.MAIN_WINDOW_TITLE % {'app_name': gui.U1_APP_NAME}
123
self.assertEqual(self.ui.get_title(), expected)
125
def test_control_panel_is_the_only_child(self):
126
"""The control panel is the window's content."""
127
children = self.ui.get_children()
128
self.assertEqual(1, len(children))
130
control_panel = self.ui.get_children()[0]
131
self.assertTrue(control_panel is self.ui.control_panel)
132
self.assertIsInstance(self.ui.control_panel, gui.ControlPanel)
133
self.assertTrue(self.ui.control_panel.get_visible())
135
def test_main_window_is_passed_to_child(self):
136
"""The child gets the main_window."""
137
self.assertEqual(self.ui.control_panel.main_window, self.ui)
139
def test_icon_name_is_correct(self):
140
"""The icon name is correct."""
141
self.assertEqual(self.ui.get_icon_name(), 'ubuntuone')
143
def test_max_size(self):
144
"""Max size is not bigger than 736x525 (LP: #645526, LP: #683164)."""
145
self.assertTrue(self.ui.get_size_request() <= (736, 525))
147
@skipIf(not gui.USE_LIBUNITY, 'Must have Unity installed.')
148
def test_focus_handler(self):
149
"""When the window receives focus, the handler is called."""
150
THE_FLEP.urgent = True
151
self.patch(gui.Unity, "LauncherEntry", FakeLauncherEntry)
152
cp = gui.ControlPanelWindow()
153
cp.emit('focus-in-event', gui.gtk.gdk.Event(gui.gtk.gdk.FOCUS_CHANGE))
155
False, THE_FLEP.urgent, 'remove_urgency should have been called.')
158
class ControlPanelWindowAlertParamTestCase(BaseTestCase):
159
"""The test suite for the control panel window when passing params."""
161
klass = gui.ControlPanelWindow
162
kwargs = {'alert': True}
165
self.patch(gui, 'ControlPanelService', FakeControlPanelService)
166
self.patch(gui.ControlPanelWindow, 'draw_attention', self._set_called)
167
super(ControlPanelWindowAlertParamTestCase, self).setUp()
169
def test_alert(self):
170
"""Can pass a 'alert' parameter to draw attention to the window."""
172
((), {}), self._called, 'draw_attention should have been called.')
175
class ControlPanelWindowParamsTestCase(ControlPanelWindowTestCase):
176
"""The test suite for the control panel window when passing params."""
178
kwargs = {'switch_to': 'devices'}
180
def test_switch_to(self):
181
"""Can pass a 'switch_to' parameter to start on a particular tab."""
182
actual = self.ui.control_panel.management.notebook.get_current_page()
183
self.assertEqual(actual, self.ui.control_panel.management.DEVICES_PAGE)
186
class ControlPanelWindowParamsNoneTestCase(ControlPanelWindowTestCase):
187
"""The suite for the control panel window when passing None params."""
189
kwargs = {'switch_to': None}
191
def test_switch_to(self):
192
"""Can pass a 'switch_to' being None. Should default to dashboard."""
193
actual = self.ui.control_panel.management.notebook.get_current_page()
194
expected = self.ui.control_panel.management.DASHBOARD_PAGE
195
self.assertEqual(actual, expected)
198
class ControlPanelWindowInvalidParamsTestCase(ControlPanelWindowTestCase):
199
"""The suite for the control panel window when passing invalid params."""
201
kwargs = {'switch_to': 'yadda-yadda'}
203
def test_switch_to(self):
204
"""Can pass an invalid 'switch_to'. Should default to dashboard."""
205
actual = self.ui.control_panel.management.notebook.get_current_page()
206
expected = self.ui.control_panel.management.DASHBOARD_PAGE
207
self.assertEqual(actual, expected)
210
class ControlPanelTestCase(BaseTestCase):
211
"""The test suite for the control panel itself."""
213
klass = gui.ControlPanel
214
kwargs = {'main_window': object()}
216
def assert_current_tab_correct(self, expected_tab):
217
"""Check that the wiget 'expected_tab' is the current page."""
218
actual = self.ui.get_nth_page(self.ui.get_current_page())
219
self.assertTrue(expected_tab is actual)
221
def test_is_a_notebook(self):
222
"""Inherits from gtk.VBox."""
223
self.assertIsInstance(self.ui, gui.gtk.Notebook)
225
def test_startup_visibility(self):
226
"""The widget is visible at startup."""
227
self.assertTrue(self.ui.get_visible(),
228
'must be visible at startup.')
230
def test_startup_props(self):
231
"""The tabs and border are not shown."""
232
self.assertFalse(self.ui.get_show_border(), 'must not show border.')
233
self.assertFalse(self.ui.get_show_tabs(), 'must not show tabs.')
235
def test_overview_is_shown_at_startup(self):
236
"""The overview is shown at startup."""
237
self.assertIsInstance(self.ui.overview, gui.OverviewPanel)
238
self.assert_current_tab_correct(self.ui.overview)
240
def test_main_window_is_passed_to_child(self):
241
"""The child gets the main_window."""
242
self.assertEqual(self.ui.overview.main_window,
243
self.kwargs['main_window'])
245
def test_on_show_management_panel(self):
246
"""A ManagementPanel is shown when the callback is executed."""
247
self.patch(self.ui.management, 'load', self._set_called)
248
self.ui.on_show_management_panel()
249
self.assert_current_tab_correct(self.ui.management)
250
self.assertEqual(self._called, ((), {}))
252
def test_on_show_management_panel_is_idempotent(self):
253
"""Only one ManagementPanel is shown."""
254
self.ui.on_show_management_panel()
255
self.ui.on_show_management_panel()
257
self.assert_current_tab_correct(self.ui.management)
259
def test_credentials_found_shows_dashboard_panel(self):
260
"""On 'credentials-found' signal, the management panel is shown.
262
If first signal parameter is False, visible tab should be dashboard.
265
self.patch(self.ui.management, 'load', self._set_called)
266
self.ui.overview.emit('credentials-found', False, object())
268
self.assert_current_tab_correct(self.ui.management)
269
self.assertEqual(self.ui.management.notebook.get_current_page(),
270
self.ui.management.DASHBOARD_PAGE)
271
self.assertEqual(self._called, ((), {}))
273
def test_credentials_found_shows_services_panel(self):
274
"""On 'credentials-found' signal, the management panel is shown.
276
If first signal parameter is True, visible tab should be services.
280
self.ui.overview.emit('credentials-found', True, a_token)
282
self.assert_current_tab_correct(self.ui.management)
283
self.assertEqual(self.ui.management.notebook.get_current_page(),
284
self.ui.management.SERVICES_PAGE)
286
def test_credentials_found_connects_syncdaemon(self):
287
"""On 'credentials-found' signal, ask syncdaemon to connect."""
288
# credentials are new
289
self.ui.overview.emit('credentials-found', True, object())
290
self.assert_backend_called('connect_files', ())
292
def test_local_device_removed_shows_overview_panel(self):
293
"""On 'local-device-removed' signal, the overview panel is shown."""
294
self.ui.overview.emit('credentials-found', True, object())
295
self.ui.management.emit('local-device-removed')
297
self.assert_current_tab_correct(self.ui.overview)
299
def test_unauthorized_shows_overview_panel(self):
300
"""On 'unauthorized' signal, the overview panel is shown."""
301
self.ui.overview.emit('credentials-found', True, object())
302
self.ui.management.emit('unauthorized')
304
self.assert_current_tab_correct(self.ui.overview)
306
def test_backend_is_shutdown_on_close(self):
307
"""When the control panel is closed, the backend is shutdown."""
308
self.ui.emit('destroy')
309
self.assert_backend_called('shutdown', ())
312
class UbuntuOneBinTestCase(BaseTestCase):
313
"""The test suite for a Ubuntu One panel."""
315
klass = gui.UbuntuOneBin
316
kwargs = {'title': 'Something old, something new and something blue.'}
318
def test_is_a_vbox(self):
319
"""Inherits from proper gtk widget."""
320
self.assertIsInstance(self.ui, gui.gtk.VBox)
322
def test_startup_visibility(self):
323
"""The widget is visible at startup."""
324
self.assertTrue(self.ui.get_visible(),
325
'must be visible at startup.')
326
for child in self.ui.get_children():
327
self.assertTrue(child.get_visible())
329
def test_title_is_a_panel_title(self):
330
"""Title is the correct widget."""
331
self.assertIsInstance(self.ui.title, gui.PanelTitle)
332
self.assertIn(self.ui.title, self.ui.get_children())
334
def test_title_markup_is_correct(self):
335
"""The title markup is correctly set when passed as argument."""
336
self.assertEqual(self.ui.title.get_text(), self.kwargs['title'])
338
def test_title_is_correct(self):
339
"""The title markup is correctly set when defined at class level."""
340
ui = self.klass() # no title given
341
self.assertEqual(ui.title.get_text(), '')
343
def test_message_is_a_label_loading(self):
344
"""Message is the correct widget."""
345
self.assertIsInstance(self.ui.message, gui.LabelLoading)
346
self.assertIn(self.ui.message, self.ui.get_children())
348
def test_on_success(self):
349
"""Callback to stop the Loading and clear messages."""
351
self.assertEqual(self.ui.message.get_label(), '')
352
self.assertFalse(self.ui.message.active)
354
def test_on_success_with_message(self):
355
"""Callback to stop the Loading and show a info message."""
356
msg = 'WOW! <i>this rocks</i>'
357
self.ui.on_success(message=msg)
358
self.assertEqual(self.ui.message.get_label(), msg)
359
self.assertFalse(self.ui.message.active)
361
def test_on_error(self):
362
"""Callback to stop the Loading and clear messages."""
364
self.assert_warning_correct(self.ui.message, gui.VALUE_ERROR)
365
self.assertFalse(self.ui.message.active)
367
def test_on_error_with_message(self):
368
"""Callback to stop the Loading and show a info message."""
369
msg = 'WOW! <i>this does not rock</i> :-/'
370
self.ui.on_error(message=msg)
371
self.assert_warning_correct(self.ui.message, msg)
372
self.assertFalse(self.ui.message.active)
374
def test_on_error_with_error_dict(self):
375
"""Callback to stop the Loading and show the error from error_dict."""
376
msg = u'Qué mala suerte! <i>this does not rock</i>'
377
error_dict = {gui.ERROR_TYPE: 'YaddaError', gui.ERROR_MESSAGE: msg}
378
self.ui.on_error(error_dict=error_dict)
380
expected_msg = "%s (%s: %s)" % (gui.VALUE_ERROR, 'YaddaError', msg)
381
self.assert_warning_correct(self.ui.message, expected_msg)
382
self.assertFalse(self.ui.message.active)
384
def test_on_error_with_error_dict_without_error_type(self):
385
"""Callback to stop the Loading and show the error from error_dict."""
387
self.ui.on_error(error_dict=error_dict)
389
expected_msg = "%s (%s)" % (gui.VALUE_ERROR, gui.UNKNOWN_ERROR)
390
self.assert_warning_correct(self.ui.message, expected_msg)
391
self.assertFalse(self.ui.message.active)
393
def test_on_error_with_error_dict_without_error_message(self):
394
"""Callback to stop the Loading and show the error from error_dict."""
395
error_dict = {gui.ERROR_TYPE: 'YaddaError'}
396
self.ui.on_error(error_dict=error_dict)
398
expected_msg = "%s (%s)" % (gui.VALUE_ERROR, 'YaddaError')
399
self.assert_warning_correct(self.ui.message, expected_msg)
400
self.assertFalse(self.ui.message.active)
402
def test_on_error_with_message_and_error_dict(self):
403
"""Callback to stop the Loading and show a info message."""
404
error_dict = {gui.ERROR_TYPE: 'YaddaError', gui.ERROR_MESSAGE: 'test'}
405
msg = 'WOW! <i>this does not rock</i> :-/'
406
self.ui.on_error(message=msg, error_dict=error_dict)
407
self.assert_warning_correct(self.ui.message, msg)
408
self.assertFalse(self.ui.message.active)
410
def test_is_processing(self):
411
"""The flag 'is_processing' is False on start."""
412
self.assertFalse(self.ui.is_processing)
413
self.assertTrue(self.ui.is_sensitive())
415
def test_set_is_processing(self):
416
"""When setting 'is_processing', the spinner is shown."""
417
self.ui.is_processing = False
418
self.ui.is_processing = True
420
self.assertTrue(self.ui.message.get_visible())
421
self.assertTrue(self.ui.message.active)
422
self.assertFalse(self.ui.is_sensitive())
424
def test_unset_is_processing(self):
425
"""When unsetting 'is_processing', the spinner is not shown."""
426
self.ui.is_processing = True
427
self.ui.is_processing = False
429
self.assertTrue(self.ui.message.get_visible())
430
self.assertFalse(self.ui.message.active)
431
self.assertTrue(self.ui.is_sensitive())
434
class OverwiewPanelTestCase(ControlPanelMixinTestCase):
435
"""The test suite for the overview panel."""
437
klass = gui.OverviewPanel
438
kwargs = {'main_window': gui.gtk.Window()}
439
ui_filename = 'overview.ui'
441
def test_is_a_greyable_bin(self):
442
"""Inherits from GreyableBin."""
443
self.assertIsInstance(self.ui, gui.GreyableBin)
445
def test_inner_widget_is_packed(self):
446
"""The 'itself' vbox is packed into the widget."""
447
self.assertIn(self.ui.itself, self.ui.get_children())
449
def test_join_now_is_default(self):
450
"""The 'join_now' button is the default widget."""
451
self.assertTrue(self.ui.join_now_button.get_property('can-default'))
453
def test_sso_backend(self):
454
"""Has a correct SSO backend."""
455
self.assertIsInstance(self.ui.backend, FakedSSOBackend)
457
def test_sso_backend_signals(self):
458
"""The proper signals are connected to the backend."""
459
self.assertEqual(self.ui.backend._signals['CredentialsFound'],
460
[self.ui.on_credentials_found])
461
self.assertEqual(self.ui.backend._signals['CredentialsNotFound'],
462
[self.ui.on_credentials_not_found])
463
self.assertEqual(self.ui.backend._signals['CredentialsError'],
464
[self.ui.on_credentials_error])
465
self.assertEqual(self.ui.backend._signals['AuthorizationDenied'],
466
[self.ui.on_authorization_denied])
469
class OverwiewNetworkStatePanelTestCase(OverwiewPanelTestCase):
470
"""The test suite for the overview panel regarding network state."""
472
def test_network_state_is_created(self):
473
"""The network state is created."""
474
self.assertIsInstance(self.ui.network_manager_state,
475
gui.networkstate.NetworkManagerState)
476
self.assertEqual(self.ui.network_manager_state._kwargs['result_cb'],
477
self.ui.on_network_state_changed)
479
def test_network_state_is_queried_at_startup(self):
480
"""The network state is asked to the NetworkManagerState."""
481
self.assertTrue('find_online_state' in
482
self.ui.network_manager_state._called)
484
def test_state_online(self):
485
"""Network connection is online."""
486
self.ui.on_network_state_changed(gui.networkstate.ONLINE)
487
# all green, no warning
488
self.assertEqual(self.ui.warning_label.get_text(), '')
489
self.assertTrue(self.ui.get_sensitive())
491
def test_state_offline(self):
492
"""Network connection is offline."""
493
self.ui.on_network_state_changed(gui.networkstate.OFFLINE)
494
msg = gui.NETWORK_OFFLINE % {'app_name': gui.U1_APP_NAME}
496
self.assert_warning_correct(self.ui.warning_label, msg)
497
self.assertFalse(self.ui.get_sensitive())
499
def test_state_unknown(self):
500
"""Network connection is unknown. Assume that connection is present."""
501
self.ui.on_network_state_changed(gui.networkstate.UNKNOWN)
503
self.assertEqual(self.ui.warning_label.get_text(), '')
504
self.assertTrue(self.ui.get_sensitive())
507
class OverwiewPanelOnlineTestCase(OverwiewPanelTestCase):
508
"""The test suite for the overview panel."""
511
super(OverwiewPanelOnlineTestCase, self).setUp()
512
self.ui.on_network_state_changed(gui.networkstate.ONLINE)
514
def test_find_credentials_is_called(self):
515
"""Credentials are asked to SSO backend."""
516
self.assertFalse(self.ui._credentials_are_new)
517
self.assert_backend_called('find_credentials', (gui.U1_APP_NAME, {}))
519
def test_on_credentials_found(self):
520
"""Callback 'on_credentials_found' is correct."""
521
self.ui.connect('credentials-found', self._set_called)
523
self.ui.on_credentials_found(gui.U1_APP_NAME, TOKEN)
525
self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
526
# assume credentials were in local keyring
527
self.assertEqual(self._called, ((self.ui, False, TOKEN), {}))
529
def test_on_credentials_found_when_creds_are_not_new(self):
530
"""Callback 'on_credentials_found' distinguish if creds are new."""
531
self.ui.connect('credentials-found', self._set_called)
533
# credentials weren't in the system
534
self.ui.on_credentials_not_found(gui.U1_APP_NAME)
536
self.ui.on_credentials_found(gui.U1_APP_NAME, TOKEN)
538
self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
539
# assume credentials were not in local keyring
540
self.assertEqual(self._called, ((self.ui, True, TOKEN), {}))
542
def test_on_credentials_not_found(self):
543
"""Callback 'on_credentials_not_found' is correct."""
544
self.ui.on_credentials_not_found(gui.U1_APP_NAME)
545
self.assertTrue(self.ui.get_visible())
546
self.assertTrue(self.ui._credentials_are_new)
548
def test_on_credentials_error(self):
549
"""Callback 'on_credentials_error' is correct."""
550
self.ui.on_credentials_error(gui.U1_APP_NAME, {})
551
self.assertTrue(self.ui.get_visible())
552
self.assert_warning_correct(self.ui.warning_label,
553
gui.CREDENTIALS_ERROR)
555
def test_on_authorization_denied(self):
556
"""Callback 'on_authorization_denied' is correct."""
557
self.ui.on_authorization_denied(gui.U1_APP_NAME)
558
self.assertTrue(self.ui.get_visible())
559
self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
560
self.assertEqual(self.ui.warning_label.get_text(), '')
563
class OverwiewPanelAppNameMismatchTestCase(OverwiewPanelTestCase):
564
"""The test suite for the overview panel when the app_name won't match."""
566
NOT_U1_APP = 'Not ' + gui.U1_APP_NAME
568
def test_filter_by_app_name(self):
569
"""The filter_by_app_name decorator is correct."""
570
f = gui.filter_by_app_name(self._set_called)
571
f(self.ui, self.NOT_U1_APP)
572
self.assertFalse(self._called)
573
self.assertTrue(self.memento.check_info('ignoring', self.NOT_U1_APP))
575
args = ('test', object())
576
kwargs = {'really': 'AWESOME'}
577
f(self.ui, gui.U1_APP_NAME, *args, **kwargs)
578
self.assertEqual(self._called,
579
((self.ui, gui.U1_APP_NAME,) + args, kwargs))
581
def test_on_credentials_found(self):
582
"""Callback 'on_credentials_found' is not executed."""
583
self.assert_function_decorated(gui.filter_by_app_name,
584
self.ui.on_credentials_found)
586
def test_on_credentials_not_found(self):
587
"""Callback 'on_credentials_not_found' is not executed."""
588
self.assert_function_decorated(gui.filter_by_app_name,
589
self.ui.on_credentials_not_found)
591
def test_on_credentials_error(self):
592
"""Callback 'on_credentials_error' is not executed."""
593
self.assert_function_decorated(gui.filter_by_app_name,
594
self.ui.on_credentials_error)
596
def test_on_authorization_denied(self):
597
"""Callback 'on_authorization_denied' is not executed."""
598
self.assert_function_decorated(gui.filter_by_app_name,
599
self.ui.on_authorization_denied)
602
class OverwiewPanelNoCredsTestCase(OverwiewPanelTestCase):
603
"""The test suite for the overview panel when no credentials are found."""
606
super(OverwiewPanelNoCredsTestCase, self).setUp()
607
self.ui.on_credentials_not_found(gui.U1_APP_NAME)
609
def test_startup_visibility(self):
610
"""The widget is visible at startup."""
611
self.assertTrue(self.ui.get_visible(),
612
'must be visible at startup if credentials not found.')
614
def test_warning_label_is_hidden(self):
615
"""The warning label is not shown by default."""
616
self.assertEqual(self.ui.warning_label.get_text(), '')
618
def test_image_is_correct(self):
619
"""There is an image attribute and is correct."""
620
self.assert_image_equal(self.ui.banner, 'overview.png')
622
def test_join_now_is_default_widget(self):
623
"""The join now button is the default widget."""
624
self.assertTrue(self.ui.join_now_button.get_property('can_default'))
626
def test_join_now_button_clicked(self):
627
"""Test the 'join now' button callback."""
628
self.kwargs['main_window'].show() # ensure parent window is realized
629
self.addCleanup(self.kwargs['main_window'].hide)
631
self.ui.join_now_button.clicked()
633
window_id = self.kwargs['main_window'].window.xid
634
args = (gui.U1_APP_NAME,
635
{gui.TC_URL_KEY: gui.U1_TC_URL,
636
gui.HELP_TEXT_KEY: gui.U1_DESCRIPTION,
637
gui.WINDOW_ID_KEY: str(window_id),
638
gui.PING_URL_KEY: gui.U1_PING_URL})
639
self.assert_backend_called('register', args)
641
def test_connect_button_clicked(self):
642
"""Test the 'join now' button callback."""
643
self.kwargs['main_window'].show() # ensure parent window is realized
644
self.addCleanup(self.kwargs['main_window'].hide)
646
self.ui.connect_button.clicked()
648
window_id = self.kwargs['main_window'].window.xid
649
args = (gui.U1_APP_NAME,
650
{gui.TC_URL_KEY: gui.U1_TC_URL,
651
gui.HELP_TEXT_KEY: gui.U1_DESCRIPTION,
652
gui.WINDOW_ID_KEY: str(window_id),
653
gui.PING_URL_KEY: gui.U1_PING_URL})
654
self.assert_backend_called('login', args)
656
def test_join_now_button_clicked_set_greyed(self):
657
"""Clicking on 'join_now' self is greyed."""
658
self.ui.join_now_button.clicked()
659
self.assertTrue(self.ui.get_property('greyed'), 'Must be greyed.')
661
def test_join_now_button_clicked_removes_warning(self):
662
"""Clicking on 'join_now' the warnings are removed."""
663
self.ui.on_authorization_denied(gui.U1_APP_NAME) # show warning
664
self.ui.join_now_button.clicked()
666
self.assertEqual(self.ui.warning_label.get_text(), '')
668
def test_connect_button_clicked_set_greyed(self):
669
"""Clicking on 'connect' self is greyed."""
670
self.ui.connect_button.clicked()
671
self.assertTrue(self.ui.get_property('greyed'), 'Must be greyed.')
673
def test_connect_button_clicked_removes_warning(self):
674
"""Clicking on 'connect' the warnings are removed."""
675
self.ui.on_authorization_denied(gui.U1_APP_NAME) # show warning
676
self.ui.connect_button.clicked()
678
self.assertEqual(self.ui.warning_label.get_text(), '')
680
def test_learn_more_button_clicked(self):
681
"""Test the 'learn more' button callback."""
682
self.patch(gui, 'uri_hook', self._set_called)
683
self.ui.learn_more_button.clicked()
685
expected = (self.ui.learn_more_button, gui.LEARN_MORE_LINK)
686
self.assertEqual(self._called, (expected, {}))
688
def test_on_credentials_not_found_unset_greyed(self):
689
"""Callback 'on_credentials_not_found' unsets the 'greyed' prop."""
690
self.ui.connect_button.clicked()
691
self.ui.on_credentials_not_found(gui.U1_APP_NAME)
693
self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
695
def test_on_credentials_error_unset_greyed(self):
696
"""Callback 'on_credentials_error' unsets the 'greyed' prop."""
697
self.ui.connect_button.clicked()
698
self.ui.on_credentials_error(gui.U1_APP_NAME, {})
700
self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
702
def test_on_authorization_denied_unset_greyed(self):
703
"""Callback 'on_authorization_denied' unsets the 'greyed' prop."""
704
self.ui.connect_button.clicked()
705
self.ui.on_authorization_denied(gui.U1_APP_NAME)
707
self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
709
def test_buttons_disabled_when_greyed(self):
710
"""Buttons should be disabled when widget is greyed."""
711
self.ui.set_sensitive(True)
712
self.ui.set_property('greyed', True)
714
self.assertFalse(self.ui.join_now_button.is_sensitive())
715
self.assertFalse(self.ui.connect_button.is_sensitive())
717
def test_buttons_enabled_when_not_greyed(self):
718
"""Buttons should be enabled when widget is not greyed."""
719
self.ui.set_sensitive(False)
720
self.ui.set_property('greyed', False)
722
self.assertTrue(self.ui.join_now_button.is_sensitive())
723
self.assertTrue(self.ui.connect_button.is_sensitive())