23
23
from twisted.internet import defer
25
from ubuntuone.controlpanel.gui import qt
26
25
from ubuntuone.controlpanel.gui.qt import controlpanel as gui
27
26
from ubuntuone.controlpanel.gui.qt.tests import (
28
BaseTestCase, SAMPLE_ACCOUNT_INFO, SAMPLE_NAME,
32
class ControlPanelTestCase(BaseTestCase):
27
SAMPLE_ACCOUNT_INFO, SAMPLE_NAME, TOKEN,
29
from ubuntuone.controlpanel.gui.qt.tests.test_ubuntuonebin import (
34
class ControlPanelTestCase(UbuntuOneBinTestCase):
33
35
"""Test the qt control panel."""
35
37
innerclass_ui = gui.controlpanel_ui
39
41
@defer.inlineCallbacks
41
43
yield super(ControlPanelTestCase, self).setUp()
44
self.patch(self.ui.ui.folders_tab, 'process_info', lambda info: None)
42
45
self.ui.backend.next_result = SAMPLE_ACCOUNT_INFO
44
def test_backend(self):
45
"""Backend is created."""
46
self.assertIsInstance(self.ui.backend,
47
gui.backend.ControlBackend)
47
@defer.inlineCallbacks
48
def test_is_processing_while_asking_info(self):
49
"""The ui is processing while the contents are loaded."""
51
"""The ui must be is_processing."""
52
self.assertTrue(self.ui.is_processing, 'ui must be processing')
55
self.patch(self.ui.backend, 'get_credentials', check)
57
yield self.ui.load() # trigger the info request
58
self.assertFalse(self.ui.is_processing, 'ui must not be processing')
60
@defer.inlineCallbacks
61
def test_credentials_are_requested_on_load(self):
62
"""The info is requested to the backend."""
64
self.assert_backend_called('get_credentials')
66
@defer.inlineCallbacks
67
def test_on_credentials_not_found_called(self):
68
"""If no credentials, on_credentials_not_found is called."""
69
self.patch(self.ui, 'on_credentials_not_found', self._set_called)
70
self.patch(self.ui.backend, 'get_credentials', lambda: {})
73
self.assertEqual(self._called, ((), {}))
75
def test_on_credentials_not_found(self):
76
"""The signin panel is shown."""
77
self.ui.on_credentials_found()
78
self.ui.on_credentials_not_found()
79
self.assertIs(self.ui.ui.switcher.currentWidget(), self.ui.ui.signin)
81
@defer.inlineCallbacks
82
def test_on_credentials_found_called(self):
83
"""If credentials, on_credentials_not_found is called."""
84
self.patch(self.ui, 'on_credentials_found', self._set_called)
87
self.assertEqual(self._called, ((), {}))
89
def test_on_credentials_found(self):
90
"""The management panel is shown."""
91
self.patch(self.ui, 'connect_file_sync', self._set_called)
92
self.ui.on_credentials_not_found()
93
self.ui.on_credentials_found()
95
self.assertIs(self.ui.ui.switcher.currentWidget(),
96
self.ui.ui.management)
97
self.assertEqual(self._called, ((), {}))
49
99
@defer.inlineCallbacks
50
100
def test_info_is_requested_on_load(self):
51
101
"""The info is requested to the backend."""
102
self.patch(self.ui, 'process_info', self._set_called)
52
103
yield self.ui.load()
53
104
self.assert_backend_called('account_info')
105
self.assertEqual(self._called, ((SAMPLE_ACCOUNT_INFO,), {}))
55
107
def test_process_info(self):
56
108
"""The info is processed when ready."""
72
124
msg = gui.PERCENTAGE_LABEL % percentage_usage
73
125
self.assertEqual(self.ui.ui.percentage_usage_label.text(), msg)
127
def test_update_over_quota(self):
128
"""Check the labels state when the user exceed the quota."""
129
percentage_value = 100
130
# pylint: disable=W0212
131
self.ui._update_quota({'percentage': percentage_value})
132
# pylint: enable=W0212
135
self.ui.ui.percentage_usage_label.property("OverQuota").toBool())
137
self.ui.ui.quota_usage_label.property("OverQuota").toBool())
139
def test_update_quota_in_range(self):
140
"""Check the labels state when the quota is under the threshold."""
141
percentage_value = 50
142
# pylint: disable=W0212
143
self.ui._update_quota({'percentage': percentage_value})
144
# pylint: enable=W0212
147
self.ui.ui.percentage_usage_label.property("OverQuota").toBool())
149
self.ui.ui.quota_usage_label.property("OverQuota").toBool())
151
def test_on_local_device_removed(self):
152
"""On DeviesPanel's localDeviceRemoved, emit credentialsNotFound."""
153
self.ui.ui.devices_tab.localDeviceRemoved.emit()
154
self.assertIs(self.ui.ui.switcher.currentWidget(), self.ui.ui.signin)
156
def test_on_signin_credentials_found(self):
157
"""On SignInPanel's credentialsFound, the management panel is shown."""
158
self.patch(self.ui, 'load', self._set_called)
159
self.ui.ui.signin.credentialsFound.emit(TOKEN)
161
self.assertEqual(self._called, ((), {}))
163
@defer.inlineCallbacks
164
def test_connect_file_sync_with_autoconnect(self):
165
"""Connect is called if autoconnect is enabled."""
166
settings = {gui.AUTOCONNECT_KEY: True}
167
self.patch(self.ui.backend, 'file_sync_settings_info',
168
lambda: defer.succeed(settings))
170
yield self.ui.connect_file_sync()
172
self.assert_backend_called('connect_files')
174
@defer.inlineCallbacks
175
def test_connect_file_sync_without_autoconnect(self):
176
"""Connect is called if autoconnect is disabled."""
177
settings = {gui.AUTOCONNECT_KEY: False}
178
self.patch(self.ui.backend, 'file_sync_settings_info',
179
lambda: defer.succeed(settings))
181
yield self.ui.connect_file_sync()
183
# pylint: disable=W0212
184
self.assertNotIn('connect_files', self.ui.backend._called)
76
187
class ExternalLinkButtonsTestCase(ControlPanelTestCase):
77
188
"""The link in the go-to-web buttons are correct."""
79
@defer.inlineCallbacks
81
self.patch(qt, 'uri_hook', self._set_called)
82
self.patch(gui, 'uri_hook', self._set_called)
83
yield super(ExternalLinkButtonsTestCase, self).setUp()
85
190
def test_get_more_space_button(self):
86
191
"""When clicking the get more GB button, the proper url is opened."""
87
self.ui.ui.get_more_space_button.click()
88
self.assertEqual(self._called, ((gui.EDIT_ACCOUNT_LINK,), {}))
192
self.assert_uri_hook_called(self.ui.ui.get_more_space_button,
193
gui.EDIT_SERVICES_LINK)
90
195
def test_help_button(self):
91
196
"""When clicking the help button, the proper url is opened."""
92
self.ui.ui.help_button.click()
93
self.assertEqual(self._called, ((gui.GET_SUPPORT_LINK,), {}))
197
self.assert_uri_hook_called(self.ui.ui.help_button,
198
gui.GET_SUPPORT_LINK)
95
200
def test_twitter_button(self):
96
201
"""When clicking the twitter button, the proper url is opened."""
97
self.ui.ui.twitter_button.click()
98
self.assertEqual(self._called, ((gui.TWITTER_LINK,), {}))
202
self.assert_uri_hook_called(self.ui.ui.twitter_button,
100
205
def test_facebook_button(self):
101
206
"""When clicking the facebook button, the proper url is opened."""
102
self.ui.ui.facebook_button.click()
103
self.assertEqual(self._called, ((gui.FACEBOOK_LINK,), {}))
207
self.assert_uri_hook_called(self.ui.ui.facebook_button,