Merge lp:~nataliabidart/ubuntuone-control-panel/folders-tweaks into lp:ubuntuone-control-panel

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 88
Merged at revision: 86
Proposed branch: lp:~nataliabidart/ubuntuone-control-panel/folders-tweaks
Merge into: lp:ubuntuone-control-panel
Diff against target: 1340 lines (+656/-575)
4 files modified
ubuntuone/controlpanel/gtk/gui.py (+16/-5)
ubuntuone/controlpanel/gtk/tests/__init__.py (+17/-6)
ubuntuone/controlpanel/gtk/tests/test_gui.py (+35/-564)
ubuntuone/controlpanel/gtk/tests/test_gui_basic.py (+588/-0)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-control-panel/folders-tweaks
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Martin Albisetti (community) ui Approve
Review via email: mp+51765@code.launchpad.net

Commit message

- Needed to split test_gui in two files due to lint warning 'too many lines in module'.
- Cleanly show the specilal folder of purchased music (LP: #720650).
- 'User' icon for cloud folders list is now 'avatar-default' (LP: #706034).

To post a comment you must log in.
Revision history for this message
Martin Albisetti (beuno) :
review: Approve (ui)
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ubuntuone/controlpanel/gtk/gui.py'
--- ubuntuone/controlpanel/gtk/gui.py 2011-02-28 23:24:53 +0000
+++ ubuntuone/controlpanel/gtk/gui.py 2011-03-01 15:44:47 +0000
@@ -397,12 +397,15 @@
397 CONFIRM_MERGE = _('The contents of your cloud folder will be merged with '397 CONFIRM_MERGE = _('The contents of your cloud folder will be merged with '
398 'your local folder "%(folder_path)s" when subscribing.\n'398 'your local folder "%(folder_path)s" when subscribing.\n'
399 'Do you want to subscribe to this cloud folder?')399 'Do you want to subscribe to this cloud folder?')
400 MUSIC_DISPLAY_NAME = _('Purchased Music')
401 MUSIC_REAL_PATH = '~/.ubuntuone/Purchased from Ubuntu One'
400402
401 MAX_COLS = 8403 MAX_COLS = 8
402404
403 CONTACT_ICON_NAME = 'system-users'405 CONTACT_ICON_NAME = 'avatar-default'
404 FOLDER_ICON_NAME = 'folder'406 FOLDER_ICON_NAME = 'folder'
405 SHARE_ICON_NAME = 'folder-remote'407 SHARE_ICON_NAME = 'folder-remote'
408 MUSIC_ICON_NAME = 'audio-x-generic'
406 ROW_HEADER = '<span font_size="large"><b>%s</b></span> ' \409 ROW_HEADER = '<span font_size="large"><b>%s</b></span> ' \
407 '<span foreground="grey">%s</span>'410 '<span foreground="grey">%s</span>'
408 ROOT = '%s - <span foreground="%s" font_size="small">%s</span>'411 ROOT = '%s - <span foreground="%s" font_size="small">%s</span>'
@@ -436,7 +439,14 @@
436 def _process_path(self, path):439 def _process_path(self, path):
437 """Trim 'path' so the '~' is removed."""440 """Trim 'path' so the '~' is removed."""
438 home = os.path.expanduser('~')441 home = os.path.expanduser('~')
439 return path.replace(os.path.join(home, ''), '')442 music_path = os.path.expanduser(self.MUSIC_REAL_PATH)
443
444 if path == music_path:
445 result = self.MUSIC_DISPLAY_NAME
446 else:
447 result = path.replace(os.path.join(home, ''), '')
448
449 return result
440450
441 def on_volumes_info_ready(self, info):451 def on_volumes_info_ready(self, info):
442 """Backend notifies of volumes info."""452 """Backend notifies of volumes info."""
@@ -454,13 +464,10 @@
454464
455 if name:465 if name:
456 name = name + "'s"466 name = name + "'s"
457 icon_name = self.SHARE_ICON_NAME
458
459 # we already added user folders, let's add an empty row467 # we already added user folders, let's add an empty row
460 treeiter = self.volumes_store.append(None, self._empty_row)468 treeiter = self.volumes_store.append(None, self._empty_row)
461 else:469 else:
462 name = self.MY_FOLDERS470 name = self.MY_FOLDERS
463 icon_name = self.FOLDER_ICON_NAME
464471
465 free_bytes_args = {'free_space': self.humanize(int(free_bytes))}472 free_bytes_args = {'free_space': self.humanize(int(free_bytes))}
466 row = (self.ROW_HEADER % (name, self.FREE_SPACE % free_bytes_args),473 row = (self.ROW_HEADER % (name, self.FREE_SPACE % free_bytes_args),
@@ -472,6 +479,7 @@
472 for volume in volumes:479 for volume in volumes:
473 sensitive = True480 sensitive = True
474 name = self._process_path(volume[u'path'])481 name = self._process_path(volume[u'path'])
482 icon_name = self.FOLDER_ICON_NAME
475483
476 is_root = volume[u'type'] == backend.ControlBackend.ROOT_TYPE484 is_root = volume[u'type'] == backend.ControlBackend.ROOT_TYPE
477 is_share = volume[u'type'] == backend.ControlBackend.SHARE_TYPE485 is_share = volume[u'type'] == backend.ControlBackend.SHARE_TYPE
@@ -481,6 +489,9 @@
481 name = self.ROOT % (name, ORANGE, self.ALWAYS_SUBSCRIBED)489 name = self.ROOT % (name, ORANGE, self.ALWAYS_SUBSCRIBED)
482 elif is_share:490 elif is_share:
483 name = volume[u'name']491 name = volume[u'name']
492 icon_name = self.SHARE_ICON_NAME
493 elif name == self.MUSIC_DISPLAY_NAME:
494 icon_name = self.MUSIC_ICON_NAME
484495
485 row = (name, bool(volume[u'subscribed']), icon_name, True,496 row = (name, bool(volume[u'subscribed']), icon_name, True,
486 sensitive, gtk.ICON_SIZE_MENU, volume['volume_id'],497 sensitive, gtk.ICON_SIZE_MENU, volume['volume_id'],
487498
=== modified file 'ubuntuone/controlpanel/gtk/tests/__init__.py'
--- ubuntuone/controlpanel/gtk/tests/__init__.py 2011-02-28 19:53:50 +0000
+++ ubuntuone/controlpanel/gtk/tests/__init__.py 2011-03-01 15:44:47 +0000
@@ -24,6 +24,7 @@
2424
25from ubuntuone.devtools.handlers import MementoHandler25from ubuntuone.devtools.handlers import MementoHandler
2626
27from ubuntuone.controlpanel.backend import ControlBackend
27from ubuntuone.controlpanel.gtk import gui28from ubuntuone.controlpanel.gtk import gui
28from ubuntuone.controlpanel.gtk.tests.test_package_manager import (29from ubuntuone.controlpanel.gtk.tests.test_package_manager import (
29 FakedTransaction)30 FakedTransaction)
@@ -41,26 +42,36 @@
4142
42ROOT = {43ROOT = {
43 u'volume_id': '', u'path': '/home/tester/My Ubuntu',44 u'volume_id': '', u'path': '/home/tester/My Ubuntu',
44 u'subscribed': 'True', u'type': u'ROOT',45 u'subscribed': 'True', u'type': ControlBackend.ROOT_TYPE,
46}
47
48MUSIC_FOLDER = {
49 u'volume_id': u'58236', u'subscribed': u'True',
50 u'type': ControlBackend.FOLDER_TYPE,
51 u'path': u'/home/tester/.ubuntuone/Purchased from Ubuntu One',
52 u'suggested_path': u'~/.ubuntuone/Purchased from Ubuntu One',
45}53}
4654
47FAKE_FOLDERS_INFO = [55FAKE_FOLDERS_INFO = [
48 {u'volume_id': u'0', u'path': u'/home/tester/foo',56 {u'volume_id': u'0', u'path': u'/home/tester/foo',
49 u'suggested_path': u'~/foo', u'subscribed': u'', u'type': u'UDF'},57 u'suggested_path': u'~/foo', u'subscribed': u'',
58 u'type': ControlBackend.FOLDER_TYPE},
50 {u'volume_id': u'1', u'path': u'/home/tester/bar',59 {u'volume_id': u'1', u'path': u'/home/tester/bar',
51 u'suggested_path': u'~/bar', u'subscribed': u'True', u'type': u'UDF'},60 u'suggested_path': u'~/bar', u'subscribed': u'True',
61 u'type': ControlBackend.FOLDER_TYPE},
52 {u'volume_id': u'2', u'path': u'/home/tester/baz',62 {u'volume_id': u'2', u'path': u'/home/tester/baz',
53 u'suggested_path': u'~/baz', u'subscribed': u'True', u'type': u'UDF'},63 u'suggested_path': u'~/baz', u'subscribed': u'True',
64 u'type': ControlBackend.FOLDER_TYPE},
54]65]
5566
56FAKE_SHARES_INFO = [67FAKE_SHARES_INFO = [
57 {u'volume_id': u'1234', u'name': u'do',68 {u'volume_id': u'1234', u'name': u'do',
58 u'path': u'/home/tester/.local/share/ubuntuone/shares/do from Other User',69 u'path': u'/home/tester/.local/share/ubuntuone/shares/do from Other User',
59 u'subscribed': u'', u'type': u'SHARE'},70 u'subscribed': u'', u'type': ControlBackend.SHARE_TYPE},
6071
61 {u'volume_id': u'5678', u'name': u're',72 {u'volume_id': u'5678', u'name': u're',
62 u'path': u'/home/tester/.local/share/ubuntuone/shares/re from Other User',73 u'path': u'/home/tester/.local/share/ubuntuone/shares/re from Other User',
63 u'subscribed': u'True', u'type': u'SHARE'},74 u'subscribed': u'True', u'type': ControlBackend.SHARE_TYPE},
64]75]
6576
66FAKE_VOLUMES_INFO = [77FAKE_VOLUMES_INFO = [
6778
=== modified file 'ubuntuone/controlpanel/gtk/tests/test_gui.py'
--- ubuntuone/controlpanel/gtk/tests/test_gui.py 2011-02-28 23:24:53 +0000
+++ ubuntuone/controlpanel/gtk/tests/test_gui.py 2011-03-01 15:44:47 +0000
@@ -23,577 +23,19 @@
23from ubuntuone.controlpanel.gtk import gui23from ubuntuone.controlpanel.gtk import gui
24from ubuntuone.controlpanel.gtk.tests import (FAKE_ACCOUNT_INFO,24from ubuntuone.controlpanel.gtk.tests import (FAKE_ACCOUNT_INFO,
25 FAKE_DEVICE_INFO, FAKE_DEVICES_INFO, FAKE_FOLDERS_INFO,25 FAKE_DEVICE_INFO, FAKE_DEVICES_INFO, FAKE_FOLDERS_INFO,
26 FAKE_VOLUMES_INFO, FAKE_REPLICATIONS_INFO, ROOT, USER_HOME,26 FAKE_VOLUMES_INFO, FAKE_REPLICATIONS_INFO,
27 BaseTestCase, FakedSSOBackend, FakedConfirmDialog,27 MUSIC_FOLDER, ROOT, USER_HOME,
28 FakedConfirmDialog,
29)
30from ubuntuone.controlpanel.gtk.tests.test_gui_basic import (
31 ControlPanelMixinTestCase,
28)32)
29from ubuntuone.controlpanel.gtk.tests.test_package_manager import (33from ubuntuone.controlpanel.gtk.tests.test_package_manager import (
30 SUCCESS, FAILURE)34 SUCCESS, FAILURE)
31from ubuntuone.controlpanel.tests import TOKEN
3235
3336
34# Attribute 'yyy' defined outside __init__, access to a protected member37# Attribute 'yyy' defined outside __init__, access to a protected member
35# pylint: disable=W0201, W021238# pylint: disable=W0201, W0212
36# Too many lines in module
37# pylint: disable=C0302
38
39
40class ControlPanelMixinTestCase(BaseTestCase):
41 """The test suite for the control panel widget."""
42
43 klass = gui.ControlPanelMixin
44 ui_filename = None
45
46 def test_is_a_control_panel_mixin(self):
47 """Inherits from ControlPanelMixin."""
48 self.assertIsInstance(self.ui, gui.ControlPanelMixin)
49
50 def test_ui_can_be_created(self):
51 """UI main class exists and can be created."""
52 self.assertTrue(self.ui is not None)
53
54
55class ControlPanelWindowTestCase(BaseTestCase):
56 """The test suite for the control panel window."""
57
58 klass = gui.ControlPanelWindow
59
60 def test_is_a_window(self):
61 """Inherits from gtk.Window."""
62 self.assertIsInstance(self.ui, gui.gtk.Window)
63
64 def test_startup_visibility(self):
65 """The widget is visible at startup."""
66 self.assertTrue(self.ui.get_visible(), 'must be visible at startup.')
67
68 def test_main_start_gtk_main_loop(self):
69 """The GTK main loop is started when calling main()."""
70 self.patch(gui.gtk, 'main', self._set_called)
71 self.ui.main()
72 self.assertEqual(self._called, ((), {}), 'gtk.main was called.')
73
74 def test_closing_stops_the_main_lopp(self):
75 """The GTK main loop is stopped when closing the window."""
76 self.patch(gui.gtk, 'main_quit', self._set_called)
77 self.ui.emit('delete-event', None)
78 self.assertEqual(self._called, ((), {}), 'gtk.main_quit was called.')
79
80 def test_title_is_correct(self):
81 """The window title is correct."""
82 expected = self.ui.TITLE % {'app_name': gui.U1_APP_NAME}
83 self.assertEqual(self.ui.get_title(), expected)
84
85 def test_control_panel_is_the_only_child(self):
86 """The control panel is the window's content."""
87 children = self.ui.get_children()
88 self.assertEqual(1, len(children))
89
90 control_panel = self.ui.get_children()[0]
91 self.assertTrue(control_panel is self.ui.control_panel)
92 self.assertIsInstance(self.ui.control_panel, gui.ControlPanel)
93 self.assertTrue(self.ui.control_panel.get_visible())
94
95 def test_main_window_is_passed_to_child(self):
96 """The child gets the main_window."""
97 self.assertEqual(self.ui.control_panel.main_window, self.ui)
98
99 def test_icon_name_is_correct(self):
100 """The icon name is correct."""
101 self.assertEqual(self.ui.get_icon_name(), 'ubuntuone')
102
103 def test_max_size(self):
104 """Max size is not bigger than 736x525 (LP: #645526, LP: #683164)."""
105 self.assertTrue(self.ui.get_size_request() <= (736, 525))
106
107
108class ControlPanelWindowParamsTestCase(ControlPanelWindowTestCase):
109 """The test suite for the control panel window when passing params."""
110
111 kwargs = {'switch_to': 'devices'}
112
113 def test_switch_to(self):
114 """Can pass a 'switch_to' parameter to start on a particular tab."""
115 actual = self.ui.control_panel.management.notebook.get_current_page()
116 self.assertEqual(actual, self.ui.control_panel.management.DEVICES_PAGE)
117
118
119class ControlPanelWindowParamsNoneTestCase(ControlPanelWindowTestCase):
120 """The suite for the control panel window when passing None params."""
121
122 kwargs = {'switch_to': None}
123
124 def test_switch_to(self):
125 """Can pass a 'switch_to' being None. Should default to dashboard."""
126 actual = self.ui.control_panel.management.notebook.get_current_page()
127 expected = self.ui.control_panel.management.DASHBOARD_PAGE
128 self.assertEqual(actual, expected)
129
130
131class ControlPanelWindowInvalidParamsTestCase(ControlPanelWindowTestCase):
132 """The suite for the control panel window when passing invalid params."""
133
134 kwargs = {'switch_to': 'yadda-yadda'}
135
136 def test_switch_to(self):
137 """Can pass an invalid 'switch_to'. Should default to dashboard."""
138 actual = self.ui.control_panel.management.notebook.get_current_page()
139 expected = self.ui.control_panel.management.DASHBOARD_PAGE
140 self.assertEqual(actual, expected)
141
142
143class ControlPanelTestCase(BaseTestCase):
144 """The test suite for the control panel itself."""
145
146 klass = gui.ControlPanel
147 kwargs = {'main_window': object()}
148
149 def assert_current_tab_correct(self, expected_tab):
150 """Check that the wiget 'expected_tab' is the current page."""
151 actual = self.ui.get_nth_page(self.ui.get_current_page())
152 self.assertTrue(expected_tab is actual)
153
154 def test_is_a_notebook(self):
155 """Inherits from gtk.VBox."""
156 self.assertIsInstance(self.ui, gui.gtk.Notebook)
157
158 def test_startup_visibility(self):
159 """The widget is visible at startup."""
160 self.assertTrue(self.ui.get_visible(),
161 'must be visible at startup.')
162
163 def test_startup_props(self):
164 """The tabs and border are not shown."""
165 self.assertFalse(self.ui.get_show_border(), 'must not show border.')
166 self.assertFalse(self.ui.get_show_tabs(), 'must not show tabs.')
167
168 def test_overview_is_shown_at_startup(self):
169 """The overview is shown at startup."""
170 self.assertIsInstance(self.ui.overview, gui.OverviewPanel)
171 self.assert_current_tab_correct(self.ui.overview)
172
173 def test_main_window_is_passed_to_child(self):
174 """The child gets the main_window."""
175 self.assertEqual(self.ui.overview.main_window,
176 self.kwargs['main_window'])
177
178 def test_on_show_management_panel(self):
179 """A ManagementPanel is shown when the callback is executed."""
180 self.ui.on_show_management_panel()
181 self.assert_current_tab_correct(self.ui.management)
182
183 def test_on_show_management_panel_is_idempotent(self):
184 """Only one ManagementPanel is shown."""
185 self.ui.on_show_management_panel()
186 self.ui.on_show_management_panel()
187
188 self.assert_current_tab_correct(self.ui.management)
189
190 def test_credentials_found_shows_dashboard_management_panel(self):
191 """On 'credentials-found' signal, the management panel is shown.
192
193 If first signal parameter is False, visible tab should be dashboard.
194
195 """
196 self.patch(self.ui.management, 'load', self._set_called)
197 self.ui.overview.emit('credentials-found', False, object())
198
199 self.assert_current_tab_correct(self.ui.management)
200 self.assertEqual(self.ui.management.notebook.get_current_page(),
201 self.ui.management.DASHBOARD_PAGE)
202 self.assertEqual(self._called, ((), {}))
203
204 def test_credentials_found_shows_volumes_management_panel(self):
205 """On 'credentials-found' signal, the management panel is shown.
206
207 If first signal parameter is True, visible tab should be volumes.
208
209 """
210 a_token = object()
211 self.ui.overview.emit('credentials-found', True, a_token)
212
213 self.assert_current_tab_correct(self.ui.management)
214 self.assertEqual(self.ui.management.notebook.get_current_page(),
215 self.ui.management.VOLUMES_PAGE)
216
217 def test_local_device_removed_shows_overview_panel(self):
218 """On 'local-device-removed' signal, the overview panel is shown."""
219 self.ui.overview.emit('credentials-found', True, object())
220 self.ui.management.emit('local-device-removed')
221
222 self.assert_current_tab_correct(self.ui.overview)
223
224
225class UbuntuOneBinTestCase(BaseTestCase):
226 """The test suite for a Ubuntu One panel."""
227
228 klass = gui.UbuntuOneBin
229 kwargs = {'title': 'Something old, something new and something blue.'}
230
231 def test_is_a_vbox(self):
232 """Inherits from proper gtk widget."""
233 self.assertIsInstance(self.ui, gui.gtk.VBox)
234
235 def test_startup_visibility(self):
236 """The widget is visible at startup."""
237 self.assertTrue(self.ui.get_visible(),
238 'must be visible at startup.')
239 for child in self.ui.get_children():
240 self.assertTrue(child.get_visible())
241
242 def test_title_is_a_panel_title(self):
243 """Title is the correct widget."""
244 self.assertIsInstance(self.ui.title, gui.PanelTitle)
245 self.assertIn(self.ui.title, self.ui.get_children())
246
247 def test_title_markup_is_correct(self):
248 """The title markup is correctly set when passed as argument."""
249 self.assertEqual(self.ui.title.label.get_text(), self.kwargs['title'])
250
251 def test_title_is_correct(self):
252 """The title markup is correctly set when defined at class level."""
253 ui = self.klass() # no title given
254 self.assertEqual(ui.title.label.get_text(), '')
255
256 def test_message_is_a_label_loading(self):
257 """Message is the correct widget."""
258 self.assertIsInstance(self.ui.message, gui.LabelLoading)
259 self.assertIn(self.ui.message, self.ui.get_children())
260
261 def test_on_success(self):
262 """Callback to stop the Loading and clear messages."""
263 self.ui.on_success()
264 self.assertEqual(self.ui.message.get_label(), '')
265 self.assertFalse(self.ui.message.active)
266
267 def test_on_success_with_message(self):
268 """Callback to stop the Loading and show a info message."""
269 msg = 'WOW! <i>this rocks</i>'
270 self.ui.on_success(message=msg)
271 self.assertEqual(self.ui.message.get_label(), msg)
272 self.assertFalse(self.ui.message.active)
273
274 def test_on_error(self):
275 """Callback to stop the Loading and clear messages."""
276 self.ui.on_error()
277 self.assert_warning_correct(self.ui.message, gui.VALUE_ERROR)
278 self.assertFalse(self.ui.message.active)
279
280 def test_on_error_with_message(self):
281 """Callback to stop the Loading and show a info message."""
282 msg = 'WOW! <i>this does not rock</i> :-/'
283 self.ui.on_error(message=msg)
284 self.assert_warning_correct(self.ui.message, msg)
285 self.assertFalse(self.ui.message.active)
286
287 def test_is_processing(self):
288 """The flag 'is_processing' is False on start."""
289 self.assertFalse(self.ui.is_processing)
290 self.assertTrue(self.ui.is_sensitive())
291
292 def test_set_is_processing(self):
293 """When setting 'is_processing', the spinner is shown."""
294 self.ui.is_processing = False
295 self.ui.is_processing = True
296
297 self.assertTrue(self.ui.message.get_visible())
298 self.assertTrue(self.ui.message.active)
299 self.assertFalse(self.ui.is_sensitive())
300
301 def test_unset_is_processing(self):
302 """When unsetting 'is_processing', the spinner is not shown."""
303 self.ui.is_processing = True
304 self.ui.is_processing = False
305
306 self.assertTrue(self.ui.message.get_visible())
307 self.assertFalse(self.ui.message.active)
308 self.assertTrue(self.ui.is_sensitive())
309
310
311class OverwiewPanelTestCase(ControlPanelMixinTestCase):
312 """The test suite for the overview panel."""
313
314 klass = gui.OverviewPanel
315 kwargs = {'main_window': gui.gtk.Window()}
316 ui_filename = 'overview.ui'
317
318 def test_is_a_greyable_bin(self):
319 """Inherits from GreyableBin."""
320 self.assertIsInstance(self.ui, gui.GreyableBin)
321
322 def test_inner_widget_is_packed(self):
323 """The 'itself' vbox is packed into the widget."""
324 self.assertIn(self.ui.itself, self.ui.get_children())
325
326 def test_join_now_is_default(self):
327 """The 'join_now' button is the default widget."""
328 self.assertTrue(self.ui.join_now_button.get_property('can-default'))
329
330 def test_sso_backend(self):
331 """Has a correct SSO backend."""
332 self.assertIsInstance(self.ui.sso_backend, FakedSSOBackend)
333
334 def test_sso_backend_signals(self):
335 """The proper signals are connected to the backend."""
336 self.assertEqual(self.ui.sso_backend._signals['CredentialsFound'],
337 [self.ui.on_credentials_found])
338 self.assertEqual(self.ui.sso_backend._signals['CredentialsNotFound'],
339 [self.ui.on_credentials_not_found])
340 self.assertEqual(self.ui.sso_backend._signals['CredentialsError'],
341 [self.ui.on_credentials_error])
342 self.assertEqual(self.ui.sso_backend._signals['AuthorizationDenied'],
343 [self.ui.on_authorization_denied])
344
345
346class OverwiewNetworkStatePanelTestCase(OverwiewPanelTestCase):
347 """The test suite for the overview panel regarding network state."""
348
349 def test_network_state_is_created(self):
350 """The network state is created."""
351 self.assertIsInstance(self.ui.network_manager_state,
352 gui.networkstate.NetworkManagerState)
353 self.assertEqual(self.ui.network_manager_state._kwargs['result_cb'],
354 self.ui.on_network_state_changed)
355
356 def test_network_state_is_queried_at_startup(self):
357 """The network state is asked to the NetworkManagerState."""
358 self.assertTrue('find_online_state' in
359 self.ui.network_manager_state._called)
360
361 def test_state_online(self):
362 """Network connection is online."""
363 self.ui.on_network_state_changed(gui.networkstate.ONLINE)
364 # all green, no warning
365 self.assertEqual(self.ui.warning_label.get_text(), '')
366 self.assertTrue(self.ui.get_sensitive())
367
368 def test_state_offline(self):
369 """Network connection is offline."""
370 self.ui.on_network_state_changed(gui.networkstate.OFFLINE)
371 msg = self.ui.NETWORK_OFFLINE % {'app_name': gui.U1_APP_NAME}
372
373 self.assert_warning_correct(self.ui.warning_label, msg)
374 self.assertFalse(self.ui.get_sensitive())
375
376 def test_state_unknown(self):
377 """Network connection is unknown."""
378 self.ui.on_network_state_changed(gui.networkstate.UNKNOWN)
379
380 self.assert_warning_correct(self.ui.warning_label,
381 self.ui.NETWORK_UNKNOWN)
382 self.assertFalse(self.ui.get_sensitive())
383
384
385class OverwiewPanelOnlineTestCase(OverwiewPanelTestCase):
386 """The test suite for the overview panel."""
387
388 def setUp(self):
389 super(OverwiewPanelOnlineTestCase, self).setUp()
390 self.ui.on_network_state_changed(gui.networkstate.ONLINE)
391
392 def test_find_credentials_is_called(self):
393 """Credentials are asked to SSO backend."""
394 self.assertFalse(self.ui._credentials_are_new)
395 self.assert_backend_called('find_credentials', (gui.U1_APP_NAME, {}),
396 backend=self.ui.sso_backend)
397
398 def test_on_credentials_found(self):
399 """Callback 'on_credentials_found' is correct."""
400 self.ui.connect('credentials-found', self._set_called)
401
402 self.ui.on_credentials_found(gui.U1_APP_NAME, TOKEN)
403
404 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
405 # assume credentials were in local keyring
406 self.assertEqual(self._called, ((self.ui, False, TOKEN), {}))
407
408 def test_on_credentials_found_when_creds_are_not_new(self):
409 """Callback 'on_credentials_found' distinguish if creds are new."""
410 self.ui.connect('credentials-found', self._set_called)
411
412 # credentials weren't in the system
413 self.ui.on_credentials_not_found(gui.U1_APP_NAME)
414 # now they are!
415 self.ui.on_credentials_found(gui.U1_APP_NAME, TOKEN)
416
417 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
418 # assume credentials were not in local keyring
419 self.assertEqual(self._called, ((self.ui, True, TOKEN), {}))
420
421 def test_on_credentials_not_found(self):
422 """Callback 'on_credentials_not_found' is correct."""
423 self.ui.on_credentials_not_found(gui.U1_APP_NAME)
424 self.assertTrue(self.ui.get_visible())
425 self.assertTrue(self.ui._credentials_are_new)
426
427 def test_on_credentials_error(self):
428 """Callback 'on_credentials_error' is correct."""
429 self.ui.on_credentials_error(gui.U1_APP_NAME, {})
430 self.assertTrue(self.ui.get_visible())
431 self.assert_warning_correct(self.ui.warning_label,
432 self.ui.CREDENTIALS_ERROR)
433
434 def test_on_authorization_denied(self):
435 """Callback 'on_authorization_denied' is correct."""
436 self.ui.on_authorization_denied(gui.U1_APP_NAME)
437 self.assertTrue(self.ui.get_visible())
438 self.assert_warning_correct(self.ui.warning_label,
439 self.ui.AUTHORIZATION_DENIED)
440
441
442class OverwiewPanelAppNameMismatchTestCase(OverwiewPanelTestCase):
443 """The test suite for the overview panel when the app_name won't match."""
444
445 NOT_U1_APP = 'Not ' + gui.U1_APP_NAME
446
447 def test_filter_by_app_name(self):
448 """The filter_by_app_name decorator is correct."""
449 f = gui.filter_by_app_name(self._set_called)
450 f(self.ui, self.NOT_U1_APP)
451 self.assertFalse(self._called)
452 self.assertTrue(self.memento.check_info('ignoring', self.NOT_U1_APP))
453
454 args = ('test', object())
455 kwargs = {'really': 'AWESOME'}
456 f(self.ui, gui.U1_APP_NAME, *args, **kwargs)
457 self.assertEqual(self._called,
458 ((self.ui, gui.U1_APP_NAME,) + args, kwargs))
459
460 def test_on_credentials_found(self):
461 """Callback 'on_credentials_found' is not executed."""
462 self.assert_function_decorated(gui.filter_by_app_name,
463 self.ui.on_credentials_found)
464
465 def test_on_credentials_not_found(self):
466 """Callback 'on_credentials_not_found' is not executed."""
467 self.assert_function_decorated(gui.filter_by_app_name,
468 self.ui.on_credentials_not_found)
469
470 def test_on_credentials_error(self):
471 """Callback 'on_credentials_error' is not executed."""
472 self.assert_function_decorated(gui.filter_by_app_name,
473 self.ui.on_credentials_error)
474
475 def test_on_authorization_denied(self):
476 """Callback 'on_authorization_denied' is not executed."""
477 self.assert_function_decorated(gui.filter_by_app_name,
478 self.ui.on_authorization_denied)
479
480
481class OverwiewPanelNoCredsTestCase(OverwiewPanelTestCase):
482 """The test suite for the overview panel when no credentials are found."""
483
484 def setUp(self):
485 super(OverwiewPanelNoCredsTestCase, self).setUp()
486 self.ui.on_credentials_not_found(gui.U1_APP_NAME)
487
488 def test_startup_visibility(self):
489 """The widget is visible at startup."""
490 self.assertTrue(self.ui.get_visible(),
491 'must be visible at startup if credentials not found.')
492
493 def test_warning_label_is_hidden(self):
494 """The warning label is not shown by default."""
495 self.assertEqual(self.ui.warning_label.get_text(), '')
496
497 def test_image_is_correct(self):
498 """There is an image attribute and is correct."""
499 self.assert_image_equal(self.ui.image, 'overview.png')
500
501 def test_join_now_is_default_widget(self):
502 """The join now button is the default widget."""
503 self.assertTrue(self.ui.join_now_button.get_property('can_default'))
504
505 def test_join_now_button_clicked(self):
506 """Test the 'join now' button callback."""
507 self.kwargs['main_window'].show() # ensure parent window is realized
508 self.addCleanup(self.kwargs['main_window'].hide)
509
510 self.ui.join_now_button.clicked()
511
512 window_id = self.kwargs['main_window'].window.xid
513 args = (gui.U1_APP_NAME,
514 {gui.TC_URL_KEY: gui.U1_TC_URL,
515 gui.HELP_TEXT_KEY: gui.U1_DESCRIPTION,
516 gui.WINDOW_ID_KEY: str(window_id),
517 gui.PING_URL_KEY: gui.U1_PING_URL})
518 self.assert_backend_called('register', args,
519 backend=self.ui.sso_backend)
520
521 def test_connect_button_clicked(self):
522 """Test the 'join now' button callback."""
523 self.kwargs['main_window'].show() # ensure parent window is realized
524 self.addCleanup(self.kwargs['main_window'].hide)
525
526 self.ui.connect_button.clicked()
527
528 window_id = self.kwargs['main_window'].window.xid
529 args = (gui.U1_APP_NAME,
530 {gui.TC_URL_KEY: gui.U1_TC_URL,
531 gui.HELP_TEXT_KEY: gui.U1_DESCRIPTION,
532 gui.WINDOW_ID_KEY: str(window_id),
533 gui.PING_URL_KEY: gui.U1_PING_URL})
534 self.assert_backend_called('login', args,
535 backend=self.ui.sso_backend)
536
537 def test_join_now_button_clicked_set_greyed(self):
538 """Clicking on 'join_now' self is greyed."""
539 self.ui.join_now_button.clicked()
540 self.assertTrue(self.ui.get_property('greyed'), 'Must be greyed.')
541
542 def test_join_now_button_clicked_removes_warning(self):
543 """Clicking on 'join_now' the warnings are removed."""
544 self.ui.on_authorization_denied(gui.U1_APP_NAME) # show warning
545 self.ui.join_now_button.clicked()
546
547 self.assertEqual(self.ui.warning_label.get_text(), '')
548
549 def test_connect_button_clicked_set_greyed(self):
550 """Clicking on 'connect' self is greyed."""
551 self.ui.connect_button.clicked()
552 self.assertTrue(self.ui.get_property('greyed'), 'Must be greyed.')
553
554 def test_connect_button_clicked_removes_warning(self):
555 """Clicking on 'connect' the warnings are removed."""
556 self.ui.on_authorization_denied(gui.U1_APP_NAME) # show warning
557 self.ui.connect_button.clicked()
558
559 self.assertEqual(self.ui.warning_label.get_text(), '')
560
561 def test_on_credentials_not_found_unset_greyed(self):
562 """Callback 'on_credentials_not_found' unsets the 'greyed' prop."""
563 self.ui.connect_button.clicked()
564 self.ui.on_credentials_not_found(gui.U1_APP_NAME)
565
566 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
567
568 def test_on_credentials_error_unset_greyed(self):
569 """Callback 'on_credentials_error' unsets the 'greyed' prop."""
570 self.ui.connect_button.clicked()
571 self.ui.on_credentials_error(gui.U1_APP_NAME, {})
572
573 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
574
575 def test_on_authorization_denied_unset_greyed(self):
576 """Callback 'on_authorization_denied' unsets the 'greyed' prop."""
577 self.ui.connect_button.clicked()
578 self.ui.on_authorization_denied(gui.U1_APP_NAME)
579
580 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
581
582 def test_buttons_disabled_when_greyed(self):
583 """Buttons should be disabled when widget is greyed."""
584 self.ui.set_sensitive(True)
585 self.ui.set_property('greyed', True)
586
587 self.assertFalse(self.ui.join_now_button.is_sensitive())
588 self.assertFalse(self.ui.connect_button.is_sensitive())
589
590 def test_buttons_enabled_when_not_greyed(self):
591 """Buttons should be enabled when widget is not greyed."""
592 self.ui.set_sensitive(False)
593 self.ui.set_property('greyed', False)
594
595 self.assertTrue(self.ui.join_now_button.is_sensitive())
596 self.assertTrue(self.ui.connect_button.is_sensitive())
59739
59840
599class DashboardTestCase(ControlPanelMixinTestCase):41class DashboardTestCase(ControlPanelMixinTestCase):
@@ -842,6 +284,35 @@
842 self.assertEqual(self._called,284 self.assertEqual(self._called,
843 ((None, gui.FILE_URI_PREFIX + ROOT['path']), {}))285 ((None, gui.FILE_URI_PREFIX + ROOT['path']), {}))
844286
287 def test_on_volumes_info_ready_with_music_folder(self):
288 """The volumes info is processed when ready."""
289 info = [(u'', u'147852369', [ROOT] + [MUSIC_FOLDER])]
290
291 self.ui.on_volumes_info_ready(info)
292
293 treeiter = self.ui.volumes_store.get_iter_root()
294 row = self.ui.volumes_store.get(treeiter, *xrange(self.ui.MAX_COLS))
295
296 # walk 'Mine' folders children
297 treeiter = self.ui.volumes_store.iter_children(treeiter)
298
299 # grab next row since first one is root
300 treeiter = self.ui.volumes_store.iter_next(treeiter)
301 row = self.ui.volumes_store.get(treeiter, *xrange(self.ui.MAX_COLS))
302
303 volume = MUSIC_FOLDER
304 expected_path = volume['path'].replace(USER_HOME, '~')
305 expected_path = expected_path.replace(self.ui.MUSIC_REAL_PATH,
306 self.ui.MUSIC_DISPLAY_NAME)
307 self.assertEqual(row[0], expected_path)
308 self.assertEqual(row[1], bool(volume['subscribed']))
309 self.assertEqual(row[2], self.ui.MUSIC_ICON_NAME)
310 self.assertTrue(row[3], 'toggle should be shown on child!')
311 self.assertTrue(row[4], 'toggle should be sensitive')
312 self.assertEqual(row[5], gui.gtk.ICON_SIZE_MENU)
313 self.assertEqual(row[6], volume['volume_id'])
314 self.assertEqual(row[7], volume['path'])
315
845316
846class VolumesSubscriptionTestCase(VolumesTestCase):317class VolumesSubscriptionTestCase(VolumesTestCase):
847 """The test suite for the volumes panel."""318 """The test suite for the volumes panel."""
848319
=== added file 'ubuntuone/controlpanel/gtk/tests/test_gui_basic.py'
--- ubuntuone/controlpanel/gtk/tests/test_gui_basic.py 1970-01-01 00:00:00 +0000
+++ ubuntuone/controlpanel/gtk/tests/test_gui_basic.py 2011-03-01 15:44:47 +0000
@@ -0,0 +1,588 @@
1# -*- coding: utf-8 -*-
2
3# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
4#
5# Copyright 2010 Canonical Ltd.
6#
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.
10#
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.
15#
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/>.
18
19"""The test suite for the control panel user interface (basics)."""
20
21from __future__ import division
22
23from ubuntuone.controlpanel.gtk import gui
24from ubuntuone.controlpanel.gtk.tests import BaseTestCase, FakedSSOBackend
25from ubuntuone.controlpanel.tests import TOKEN
26
27
28# Attribute 'yyy' defined outside __init__, access to a protected member
29# pylint: disable=W0201, W0212
30
31
32class ControlPanelMixinTestCase(BaseTestCase):
33 """The test suite for the control panel widget."""
34
35 klass = gui.ControlPanelMixin
36 ui_filename = None
37
38 def test_is_a_control_panel_mixin(self):
39 """Inherits from ControlPanelMixin."""
40 self.assertIsInstance(self.ui, gui.ControlPanelMixin)
41
42 def test_ui_can_be_created(self):
43 """UI main class exists and can be created."""
44 self.assertTrue(self.ui is not None)
45
46
47class ControlPanelWindowTestCase(BaseTestCase):
48 """The test suite for the control panel window."""
49
50 klass = gui.ControlPanelWindow
51
52 def test_is_a_window(self):
53 """Inherits from gtk.Window."""
54 self.assertIsInstance(self.ui, gui.gtk.Window)
55
56 def test_startup_visibility(self):
57 """The widget is visible at startup."""
58 self.assertTrue(self.ui.get_visible(), 'must be visible at startup.')
59
60 def test_main_start_gtk_main_loop(self):
61 """The GTK main loop is started when calling main()."""
62 self.patch(gui.gtk, 'main', self._set_called)
63 self.ui.main()
64 self.assertEqual(self._called, ((), {}), 'gtk.main was called.')
65
66 def test_closing_stops_the_main_lopp(self):
67 """The GTK main loop is stopped when closing the window."""
68 self.patch(gui.gtk, 'main_quit', self._set_called)
69 self.ui.emit('delete-event', None)
70 self.assertEqual(self._called, ((), {}), 'gtk.main_quit was called.')
71
72 def test_title_is_correct(self):
73 """The window title is correct."""
74 expected = self.ui.TITLE % {'app_name': gui.U1_APP_NAME}
75 self.assertEqual(self.ui.get_title(), expected)
76
77 def test_control_panel_is_the_only_child(self):
78 """The control panel is the window's content."""
79 children = self.ui.get_children()
80 self.assertEqual(1, len(children))
81
82 control_panel = self.ui.get_children()[0]
83 self.assertTrue(control_panel is self.ui.control_panel)
84 self.assertIsInstance(self.ui.control_panel, gui.ControlPanel)
85 self.assertTrue(self.ui.control_panel.get_visible())
86
87 def test_main_window_is_passed_to_child(self):
88 """The child gets the main_window."""
89 self.assertEqual(self.ui.control_panel.main_window, self.ui)
90
91 def test_icon_name_is_correct(self):
92 """The icon name is correct."""
93 self.assertEqual(self.ui.get_icon_name(), 'ubuntuone')
94
95 def test_max_size(self):
96 """Max size is not bigger than 736x525 (LP: #645526, LP: #683164)."""
97 self.assertTrue(self.ui.get_size_request() <= (736, 525))
98
99
100class ControlPanelWindowParamsTestCase(ControlPanelWindowTestCase):
101 """The test suite for the control panel window when passing params."""
102
103 kwargs = {'switch_to': 'devices'}
104
105 def test_switch_to(self):
106 """Can pass a 'switch_to' parameter to start on a particular tab."""
107 actual = self.ui.control_panel.management.notebook.get_current_page()
108 self.assertEqual(actual, self.ui.control_panel.management.DEVICES_PAGE)
109
110
111class ControlPanelWindowParamsNoneTestCase(ControlPanelWindowTestCase):
112 """The suite for the control panel window when passing None params."""
113
114 kwargs = {'switch_to': None}
115
116 def test_switch_to(self):
117 """Can pass a 'switch_to' being None. Should default to dashboard."""
118 actual = self.ui.control_panel.management.notebook.get_current_page()
119 expected = self.ui.control_panel.management.DASHBOARD_PAGE
120 self.assertEqual(actual, expected)
121
122
123class ControlPanelWindowInvalidParamsTestCase(ControlPanelWindowTestCase):
124 """The suite for the control panel window when passing invalid params."""
125
126 kwargs = {'switch_to': 'yadda-yadda'}
127
128 def test_switch_to(self):
129 """Can pass an invalid 'switch_to'. Should default to dashboard."""
130 actual = self.ui.control_panel.management.notebook.get_current_page()
131 expected = self.ui.control_panel.management.DASHBOARD_PAGE
132 self.assertEqual(actual, expected)
133
134
135class ControlPanelTestCase(BaseTestCase):
136 """The test suite for the control panel itself."""
137
138 klass = gui.ControlPanel
139 kwargs = {'main_window': object()}
140
141 def assert_current_tab_correct(self, expected_tab):
142 """Check that the wiget 'expected_tab' is the current page."""
143 actual = self.ui.get_nth_page(self.ui.get_current_page())
144 self.assertTrue(expected_tab is actual)
145
146 def test_is_a_notebook(self):
147 """Inherits from gtk.VBox."""
148 self.assertIsInstance(self.ui, gui.gtk.Notebook)
149
150 def test_startup_visibility(self):
151 """The widget is visible at startup."""
152 self.assertTrue(self.ui.get_visible(),
153 'must be visible at startup.')
154
155 def test_startup_props(self):
156 """The tabs and border are not shown."""
157 self.assertFalse(self.ui.get_show_border(), 'must not show border.')
158 self.assertFalse(self.ui.get_show_tabs(), 'must not show tabs.')
159
160 def test_overview_is_shown_at_startup(self):
161 """The overview is shown at startup."""
162 self.assertIsInstance(self.ui.overview, gui.OverviewPanel)
163 self.assert_current_tab_correct(self.ui.overview)
164
165 def test_main_window_is_passed_to_child(self):
166 """The child gets the main_window."""
167 self.assertEqual(self.ui.overview.main_window,
168 self.kwargs['main_window'])
169
170 def test_on_show_management_panel(self):
171 """A ManagementPanel is shown when the callback is executed."""
172 self.ui.on_show_management_panel()
173 self.assert_current_tab_correct(self.ui.management)
174
175 def test_on_show_management_panel_is_idempotent(self):
176 """Only one ManagementPanel is shown."""
177 self.ui.on_show_management_panel()
178 self.ui.on_show_management_panel()
179
180 self.assert_current_tab_correct(self.ui.management)
181
182 def test_credentials_found_shows_dashboard_management_panel(self):
183 """On 'credentials-found' signal, the management panel is shown.
184
185 If first signal parameter is False, visible tab should be dashboard.
186
187 """
188 self.patch(self.ui.management, 'load', self._set_called)
189 self.ui.overview.emit('credentials-found', False, object())
190
191 self.assert_current_tab_correct(self.ui.management)
192 self.assertEqual(self.ui.management.notebook.get_current_page(),
193 self.ui.management.DASHBOARD_PAGE)
194 self.assertEqual(self._called, ((), {}))
195
196 def test_credentials_found_shows_volumes_management_panel(self):
197 """On 'credentials-found' signal, the management panel is shown.
198
199 If first signal parameter is True, visible tab should be volumes.
200
201 """
202 a_token = object()
203 self.ui.overview.emit('credentials-found', True, a_token)
204
205 self.assert_current_tab_correct(self.ui.management)
206 self.assertEqual(self.ui.management.notebook.get_current_page(),
207 self.ui.management.VOLUMES_PAGE)
208
209 def test_local_device_removed_shows_overview_panel(self):
210 """On 'local-device-removed' signal, the overview panel is shown."""
211 self.ui.overview.emit('credentials-found', True, object())
212 self.ui.management.emit('local-device-removed')
213
214 self.assert_current_tab_correct(self.ui.overview)
215
216
217class UbuntuOneBinTestCase(BaseTestCase):
218 """The test suite for a Ubuntu One panel."""
219
220 klass = gui.UbuntuOneBin
221 kwargs = {'title': 'Something old, something new and something blue.'}
222
223 def test_is_a_vbox(self):
224 """Inherits from proper gtk widget."""
225 self.assertIsInstance(self.ui, gui.gtk.VBox)
226
227 def test_startup_visibility(self):
228 """The widget is visible at startup."""
229 self.assertTrue(self.ui.get_visible(),
230 'must be visible at startup.')
231 for child in self.ui.get_children():
232 self.assertTrue(child.get_visible())
233
234 def test_title_is_a_panel_title(self):
235 """Title is the correct widget."""
236 self.assertIsInstance(self.ui.title, gui.PanelTitle)
237 self.assertIn(self.ui.title, self.ui.get_children())
238
239 def test_title_markup_is_correct(self):
240 """The title markup is correctly set when passed as argument."""
241 self.assertEqual(self.ui.title.label.get_text(), self.kwargs['title'])
242
243 def test_title_is_correct(self):
244 """The title markup is correctly set when defined at class level."""
245 ui = self.klass() # no title given
246 self.assertEqual(ui.title.label.get_text(), '')
247
248 def test_message_is_a_label_loading(self):
249 """Message is the correct widget."""
250 self.assertIsInstance(self.ui.message, gui.LabelLoading)
251 self.assertIn(self.ui.message, self.ui.get_children())
252
253 def test_on_success(self):
254 """Callback to stop the Loading and clear messages."""
255 self.ui.on_success()
256 self.assertEqual(self.ui.message.get_label(), '')
257 self.assertFalse(self.ui.message.active)
258
259 def test_on_success_with_message(self):
260 """Callback to stop the Loading and show a info message."""
261 msg = 'WOW! <i>this rocks</i>'
262 self.ui.on_success(message=msg)
263 self.assertEqual(self.ui.message.get_label(), msg)
264 self.assertFalse(self.ui.message.active)
265
266 def test_on_error(self):
267 """Callback to stop the Loading and clear messages."""
268 self.ui.on_error()
269 self.assert_warning_correct(self.ui.message, gui.VALUE_ERROR)
270 self.assertFalse(self.ui.message.active)
271
272 def test_on_error_with_message(self):
273 """Callback to stop the Loading and show a info message."""
274 msg = 'WOW! <i>this does not rock</i> :-/'
275 self.ui.on_error(message=msg)
276 self.assert_warning_correct(self.ui.message, msg)
277 self.assertFalse(self.ui.message.active)
278
279 def test_is_processing(self):
280 """The flag 'is_processing' is False on start."""
281 self.assertFalse(self.ui.is_processing)
282 self.assertTrue(self.ui.is_sensitive())
283
284 def test_set_is_processing(self):
285 """When setting 'is_processing', the spinner is shown."""
286 self.ui.is_processing = False
287 self.ui.is_processing = True
288
289 self.assertTrue(self.ui.message.get_visible())
290 self.assertTrue(self.ui.message.active)
291 self.assertFalse(self.ui.is_sensitive())
292
293 def test_unset_is_processing(self):
294 """When unsetting 'is_processing', the spinner is not shown."""
295 self.ui.is_processing = True
296 self.ui.is_processing = False
297
298 self.assertTrue(self.ui.message.get_visible())
299 self.assertFalse(self.ui.message.active)
300 self.assertTrue(self.ui.is_sensitive())
301
302
303class OverwiewPanelTestCase(ControlPanelMixinTestCase):
304 """The test suite for the overview panel."""
305
306 klass = gui.OverviewPanel
307 kwargs = {'main_window': gui.gtk.Window()}
308 ui_filename = 'overview.ui'
309
310 def test_is_a_greyable_bin(self):
311 """Inherits from GreyableBin."""
312 self.assertIsInstance(self.ui, gui.GreyableBin)
313
314 def test_inner_widget_is_packed(self):
315 """The 'itself' vbox is packed into the widget."""
316 self.assertIn(self.ui.itself, self.ui.get_children())
317
318 def test_join_now_is_default(self):
319 """The 'join_now' button is the default widget."""
320 self.assertTrue(self.ui.join_now_button.get_property('can-default'))
321
322 def test_sso_backend(self):
323 """Has a correct SSO backend."""
324 self.assertIsInstance(self.ui.sso_backend, FakedSSOBackend)
325
326 def test_sso_backend_signals(self):
327 """The proper signals are connected to the backend."""
328 self.assertEqual(self.ui.sso_backend._signals['CredentialsFound'],
329 [self.ui.on_credentials_found])
330 self.assertEqual(self.ui.sso_backend._signals['CredentialsNotFound'],
331 [self.ui.on_credentials_not_found])
332 self.assertEqual(self.ui.sso_backend._signals['CredentialsError'],
333 [self.ui.on_credentials_error])
334 self.assertEqual(self.ui.sso_backend._signals['AuthorizationDenied'],
335 [self.ui.on_authorization_denied])
336
337
338class OverwiewNetworkStatePanelTestCase(OverwiewPanelTestCase):
339 """The test suite for the overview panel regarding network state."""
340
341 def test_network_state_is_created(self):
342 """The network state is created."""
343 self.assertIsInstance(self.ui.network_manager_state,
344 gui.networkstate.NetworkManagerState)
345 self.assertEqual(self.ui.network_manager_state._kwargs['result_cb'],
346 self.ui.on_network_state_changed)
347
348 def test_network_state_is_queried_at_startup(self):
349 """The network state is asked to the NetworkManagerState."""
350 self.assertTrue('find_online_state' in
351 self.ui.network_manager_state._called)
352
353 def test_state_online(self):
354 """Network connection is online."""
355 self.ui.on_network_state_changed(gui.networkstate.ONLINE)
356 # all green, no warning
357 self.assertEqual(self.ui.warning_label.get_text(), '')
358 self.assertTrue(self.ui.get_sensitive())
359
360 def test_state_offline(self):
361 """Network connection is offline."""
362 self.ui.on_network_state_changed(gui.networkstate.OFFLINE)
363 msg = self.ui.NETWORK_OFFLINE % {'app_name': gui.U1_APP_NAME}
364
365 self.assert_warning_correct(self.ui.warning_label, msg)
366 self.assertFalse(self.ui.get_sensitive())
367
368 def test_state_unknown(self):
369 """Network connection is unknown."""
370 self.ui.on_network_state_changed(gui.networkstate.UNKNOWN)
371
372 self.assert_warning_correct(self.ui.warning_label,
373 self.ui.NETWORK_UNKNOWN)
374 self.assertFalse(self.ui.get_sensitive())
375
376
377class OverwiewPanelOnlineTestCase(OverwiewPanelTestCase):
378 """The test suite for the overview panel."""
379
380 def setUp(self):
381 super(OverwiewPanelOnlineTestCase, self).setUp()
382 self.ui.on_network_state_changed(gui.networkstate.ONLINE)
383
384 def test_find_credentials_is_called(self):
385 """Credentials are asked to SSO backend."""
386 self.assertFalse(self.ui._credentials_are_new)
387 self.assert_backend_called('find_credentials', (gui.U1_APP_NAME, {}),
388 backend=self.ui.sso_backend)
389
390 def test_on_credentials_found(self):
391 """Callback 'on_credentials_found' is correct."""
392 self.ui.connect('credentials-found', self._set_called)
393
394 self.ui.on_credentials_found(gui.U1_APP_NAME, TOKEN)
395
396 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
397 # assume credentials were in local keyring
398 self.assertEqual(self._called, ((self.ui, False, TOKEN), {}))
399
400 def test_on_credentials_found_when_creds_are_not_new(self):
401 """Callback 'on_credentials_found' distinguish if creds are new."""
402 self.ui.connect('credentials-found', self._set_called)
403
404 # credentials weren't in the system
405 self.ui.on_credentials_not_found(gui.U1_APP_NAME)
406 # now they are!
407 self.ui.on_credentials_found(gui.U1_APP_NAME, TOKEN)
408
409 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
410 # assume credentials were not in local keyring
411 self.assertEqual(self._called, ((self.ui, True, TOKEN), {}))
412
413 def test_on_credentials_not_found(self):
414 """Callback 'on_credentials_not_found' is correct."""
415 self.ui.on_credentials_not_found(gui.U1_APP_NAME)
416 self.assertTrue(self.ui.get_visible())
417 self.assertTrue(self.ui._credentials_are_new)
418
419 def test_on_credentials_error(self):
420 """Callback 'on_credentials_error' is correct."""
421 self.ui.on_credentials_error(gui.U1_APP_NAME, {})
422 self.assertTrue(self.ui.get_visible())
423 self.assert_warning_correct(self.ui.warning_label,
424 self.ui.CREDENTIALS_ERROR)
425
426 def test_on_authorization_denied(self):
427 """Callback 'on_authorization_denied' is correct."""
428 self.ui.on_authorization_denied(gui.U1_APP_NAME)
429 self.assertTrue(self.ui.get_visible())
430 self.assert_warning_correct(self.ui.warning_label,
431 self.ui.AUTHORIZATION_DENIED)
432
433
434class OverwiewPanelAppNameMismatchTestCase(OverwiewPanelTestCase):
435 """The test suite for the overview panel when the app_name won't match."""
436
437 NOT_U1_APP = 'Not ' + gui.U1_APP_NAME
438
439 def test_filter_by_app_name(self):
440 """The filter_by_app_name decorator is correct."""
441 f = gui.filter_by_app_name(self._set_called)
442 f(self.ui, self.NOT_U1_APP)
443 self.assertFalse(self._called)
444 self.assertTrue(self.memento.check_info('ignoring', self.NOT_U1_APP))
445
446 args = ('test', object())
447 kwargs = {'really': 'AWESOME'}
448 f(self.ui, gui.U1_APP_NAME, *args, **kwargs)
449 self.assertEqual(self._called,
450 ((self.ui, gui.U1_APP_NAME,) + args, kwargs))
451
452 def test_on_credentials_found(self):
453 """Callback 'on_credentials_found' is not executed."""
454 self.assert_function_decorated(gui.filter_by_app_name,
455 self.ui.on_credentials_found)
456
457 def test_on_credentials_not_found(self):
458 """Callback 'on_credentials_not_found' is not executed."""
459 self.assert_function_decorated(gui.filter_by_app_name,
460 self.ui.on_credentials_not_found)
461
462 def test_on_credentials_error(self):
463 """Callback 'on_credentials_error' is not executed."""
464 self.assert_function_decorated(gui.filter_by_app_name,
465 self.ui.on_credentials_error)
466
467 def test_on_authorization_denied(self):
468 """Callback 'on_authorization_denied' is not executed."""
469 self.assert_function_decorated(gui.filter_by_app_name,
470 self.ui.on_authorization_denied)
471
472
473class OverwiewPanelNoCredsTestCase(OverwiewPanelTestCase):
474 """The test suite for the overview panel when no credentials are found."""
475
476 def setUp(self):
477 super(OverwiewPanelNoCredsTestCase, self).setUp()
478 self.ui.on_credentials_not_found(gui.U1_APP_NAME)
479
480 def test_startup_visibility(self):
481 """The widget is visible at startup."""
482 self.assertTrue(self.ui.get_visible(),
483 'must be visible at startup if credentials not found.')
484
485 def test_warning_label_is_hidden(self):
486 """The warning label is not shown by default."""
487 self.assertEqual(self.ui.warning_label.get_text(), '')
488
489 def test_image_is_correct(self):
490 """There is an image attribute and is correct."""
491 self.assert_image_equal(self.ui.image, 'overview.png')
492
493 def test_join_now_is_default_widget(self):
494 """The join now button is the default widget."""
495 self.assertTrue(self.ui.join_now_button.get_property('can_default'))
496
497 def test_join_now_button_clicked(self):
498 """Test the 'join now' button callback."""
499 self.kwargs['main_window'].show() # ensure parent window is realized
500 self.addCleanup(self.kwargs['main_window'].hide)
501
502 self.ui.join_now_button.clicked()
503
504 window_id = self.kwargs['main_window'].window.xid
505 args = (gui.U1_APP_NAME,
506 {gui.TC_URL_KEY: gui.U1_TC_URL,
507 gui.HELP_TEXT_KEY: gui.U1_DESCRIPTION,
508 gui.WINDOW_ID_KEY: str(window_id),
509 gui.PING_URL_KEY: gui.U1_PING_URL})
510 self.assert_backend_called('register', args,
511 backend=self.ui.sso_backend)
512
513 def test_connect_button_clicked(self):
514 """Test the 'join now' button callback."""
515 self.kwargs['main_window'].show() # ensure parent window is realized
516 self.addCleanup(self.kwargs['main_window'].hide)
517
518 self.ui.connect_button.clicked()
519
520 window_id = self.kwargs['main_window'].window.xid
521 args = (gui.U1_APP_NAME,
522 {gui.TC_URL_KEY: gui.U1_TC_URL,
523 gui.HELP_TEXT_KEY: gui.U1_DESCRIPTION,
524 gui.WINDOW_ID_KEY: str(window_id),
525 gui.PING_URL_KEY: gui.U1_PING_URL})
526 self.assert_backend_called('login', args,
527 backend=self.ui.sso_backend)
528
529 def test_join_now_button_clicked_set_greyed(self):
530 """Clicking on 'join_now' self is greyed."""
531 self.ui.join_now_button.clicked()
532 self.assertTrue(self.ui.get_property('greyed'), 'Must be greyed.')
533
534 def test_join_now_button_clicked_removes_warning(self):
535 """Clicking on 'join_now' the warnings are removed."""
536 self.ui.on_authorization_denied(gui.U1_APP_NAME) # show warning
537 self.ui.join_now_button.clicked()
538
539 self.assertEqual(self.ui.warning_label.get_text(), '')
540
541 def test_connect_button_clicked_set_greyed(self):
542 """Clicking on 'connect' self is greyed."""
543 self.ui.connect_button.clicked()
544 self.assertTrue(self.ui.get_property('greyed'), 'Must be greyed.')
545
546 def test_connect_button_clicked_removes_warning(self):
547 """Clicking on 'connect' the warnings are removed."""
548 self.ui.on_authorization_denied(gui.U1_APP_NAME) # show warning
549 self.ui.connect_button.clicked()
550
551 self.assertEqual(self.ui.warning_label.get_text(), '')
552
553 def test_on_credentials_not_found_unset_greyed(self):
554 """Callback 'on_credentials_not_found' unsets the 'greyed' prop."""
555 self.ui.connect_button.clicked()
556 self.ui.on_credentials_not_found(gui.U1_APP_NAME)
557
558 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
559
560 def test_on_credentials_error_unset_greyed(self):
561 """Callback 'on_credentials_error' unsets the 'greyed' prop."""
562 self.ui.connect_button.clicked()
563 self.ui.on_credentials_error(gui.U1_APP_NAME, {})
564
565 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
566
567 def test_on_authorization_denied_unset_greyed(self):
568 """Callback 'on_authorization_denied' unsets the 'greyed' prop."""
569 self.ui.connect_button.clicked()
570 self.ui.on_authorization_denied(gui.U1_APP_NAME)
571
572 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
573
574 def test_buttons_disabled_when_greyed(self):
575 """Buttons should be disabled when widget is greyed."""
576 self.ui.set_sensitive(True)
577 self.ui.set_property('greyed', True)
578
579 self.assertFalse(self.ui.join_now_button.is_sensitive())
580 self.assertFalse(self.ui.connect_button.is_sensitive())
581
582 def test_buttons_enabled_when_not_greyed(self):
583 """Buttons should be enabled when widget is not greyed."""
584 self.ui.set_sensitive(False)
585 self.ui.set_property('greyed', False)
586
587 self.assertTrue(self.ui.join_now_button.is_sensitive())
588 self.assertTrue(self.ui.connect_button.is_sensitive())

Subscribers

People subscribed via source and target branches