~ubuntu-branches/ubuntu/oneiric/ubuntuone-control-panel/oneiric

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py

* New upstream release:
  [ Alejandro J. Cura <alecu@canonical.com>]
    - Do not throw a webclient error when closing
      (LP: #845105).
  [ Natalia B. Bidart <natalia.bidart@canonical.com> ]
    - Removed all code related to Bookmarks (LP: #850142).
    - Replaces references to "Evolution" by "Thunderbird" (LP: #849494).
  [ Rodney Dawes <rodney.dawes@canonical.com> ]
    - Don't install a .desktop file for control panel
      (part of LP: #838778).
    - Point the indicator/Unity API at the installer .desktop file
      (part of LP: #838778).
    - Set the WMCLASS so Unity will fall back properly
      (part of LP: #838778).
    - Fix a few grammar mistakes (LP: #835093).
    - Don't show the "Get NGB free!" label on "Join now" button at all
      (LP: #819955).
* debian/control:
  - ubuntuone-control-panel-gtk depends now on ubuntuone-installer >= 2.0.0.
  - require ubuntuone-client >= 2.0.0.
  - require ubuntu-sso-client >= 1.4.0.
  - no longer install a .desktop file (will be installed by ubuntuone-installer).

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from twisted.internet import defer
24
24
 
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,
29
 
)
30
 
 
31
 
 
32
 
class ControlPanelTestCase(BaseTestCase):
 
27
    SAMPLE_ACCOUNT_INFO, SAMPLE_NAME, TOKEN,
 
28
)
 
29
from ubuntuone.controlpanel.gui.qt.tests.test_ubuntuonebin import (
 
30
    UbuntuOneBinTestCase,
 
31
)
 
32
 
 
33
 
 
34
class ControlPanelTestCase(UbuntuOneBinTestCase):
33
35
    """Test the qt control panel."""
34
36
 
35
37
    innerclass_ui = gui.controlpanel_ui
39
41
    @defer.inlineCallbacks
40
42
    def setUp(self):
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
43
46
 
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."""
 
50
        def check():
 
51
            """The ui must be is_processing."""
 
52
            self.assertTrue(self.ui.is_processing, 'ui must be processing')
 
53
            return {}
 
54
 
 
55
        self.patch(self.ui.backend, 'get_credentials', check)
 
56
 
 
57
        yield self.ui.load()  # trigger the info request
 
58
        self.assertFalse(self.ui.is_processing, 'ui must not be processing')
 
59
 
 
60
    @defer.inlineCallbacks
 
61
    def test_credentials_are_requested_on_load(self):
 
62
        """The info is requested to the backend."""
 
63
        yield self.ui.load()
 
64
        self.assert_backend_called('get_credentials')
 
65
 
 
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: {})
 
71
        yield self.ui.load()
 
72
 
 
73
        self.assertEqual(self._called, ((), {}))
 
74
 
 
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)
 
80
 
 
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)
 
85
        yield self.ui.load()
 
86
 
 
87
        self.assertEqual(self._called, ((), {}))
 
88
 
 
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()
 
94
 
 
95
        self.assertIs(self.ui.ui.switcher.currentWidget(),
 
96
                      self.ui.ui.management)
 
97
        self.assertEqual(self._called, ((), {}))
48
98
 
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,), {}))
54
106
 
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)
74
126
 
 
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
 
133
 
 
134
        self.assertTrue(
 
135
            self.ui.ui.percentage_usage_label.property("OverQuota").toBool())
 
136
        self.assertTrue(
 
137
            self.ui.ui.quota_usage_label.property("OverQuota").toBool())
 
138
 
 
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
 
145
 
 
146
        self.assertFalse(
 
147
            self.ui.ui.percentage_usage_label.property("OverQuota").toBool())
 
148
        self.assertFalse(
 
149
            self.ui.ui.quota_usage_label.property("OverQuota").toBool())
 
150
 
 
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)
 
155
 
 
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)
 
160
 
 
161
        self.assertEqual(self._called, ((), {}))
 
162
 
 
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))
 
169
 
 
170
        yield self.ui.connect_file_sync()
 
171
 
 
172
        self.assert_backend_called('connect_files')
 
173
 
 
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))
 
180
 
 
181
        yield self.ui.connect_file_sync()
 
182
 
 
183
        # pylint: disable=W0212
 
184
        self.assertNotIn('connect_files', self.ui.backend._called)
 
185
 
75
186
 
76
187
class ExternalLinkButtonsTestCase(ControlPanelTestCase):
77
188
    """The link in the go-to-web buttons are correct."""
78
189
 
79
 
    @defer.inlineCallbacks
80
 
    def setUp(self):
81
 
        self.patch(qt, 'uri_hook', self._set_called)
82
 
        self.patch(gui, 'uri_hook', self._set_called)
83
 
        yield super(ExternalLinkButtonsTestCase, self).setUp()
84
 
 
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)
89
194
 
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)
94
199
 
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,
 
203
                                    gui.TWITTER_LINK)
99
204
 
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,
 
208
                                    gui.FACEBOOK_LINK)