~ubuntu-branches/ubuntu/quantal/ubuntuone-control-panel/quantal-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2012-06-20 16:42:13 UTC
  • mto: This revision was merged to the branch mainline in revision 50.
  • Revision ID: package-import@ubuntu.com-20120620164213-6z7q5pqc0ydjrp19
Tags: upstream-3.99.0
ImportĀ upstreamĀ versionĀ 3.99.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from __future__ import division
22
22
 
 
23
import operator
 
24
 
23
25
from twisted.internet import defer
24
26
 
25
27
from ubuntuone.controlpanel.gui.qt import preferences as gui
53
55
            gui.backend.SHOW_ALL_NOTIFICATIONS_KEY: notifs == gui.CHECKED,
54
56
            gui.backend.SHARE_AUTOSUBSCRIBE_KEY: share_auto == gui.CHECKED,
55
57
            gui.backend.UDF_AUTOSUBSCRIBE_KEY: udf_auto == gui.CHECKED,
56
 
            gui.backend.DOWNLOAD_KEY: gui.tweak_speed(download_speed),
57
 
            gui.backend.UPLOAD_KEY: gui.tweak_speed(upload_speed),
 
58
            gui.backend.DOWNLOAD_KEY: download_speed * gui.KILOBYTES,
 
59
            gui.backend.UPLOAD_KEY: upload_speed * gui.KILOBYTES,
58
60
        }
59
61
        return result
60
62
 
118
120
        speed = settings[gui.backend.DOWNLOAD_KEY]
119
121
        if speed > 0:
120
122
            speed = settings[gui.backend.DOWNLOAD_KEY] // gui.KILOBYTES
121
 
        download_speed = self.ui.ui.download_speed_spinbox.value()
122
 
        self.assertEqual(speed, download_speed)
 
123
            download_speed = self.ui.ui.download_speed_spinbox.value()
 
124
            self.assertEqual(speed, download_speed)
123
125
        limit_downloads = self.ui.ui.limit_downloads_checkbox.checkState()
124
 
        self.assertEqual(speed > 0, limit_downloads == gui.CHECKED)
 
126
        self.assertEqual(self.ui.ui.download_speed_spinbox.isEnabled(),
 
127
            limit_downloads == gui.CHECKED)
125
128
 
126
129
        speed = settings[gui.backend.UPLOAD_KEY]
127
130
        if speed > 0:
128
131
            speed = settings[gui.backend.UPLOAD_KEY] // gui.KILOBYTES
129
 
        upload_speed = self.ui.ui.upload_speed_spinbox.value()
130
 
        self.assertEqual(speed, upload_speed)
 
132
            upload_speed = self.ui.ui.upload_speed_spinbox.value()
 
133
            self.assertEqual(speed, upload_speed)
131
134
        limit_uploads = self.ui.ui.limit_uploads_checkbox.checkState()
132
 
        self.assertEqual(speed > 0, limit_uploads == gui.CHECKED)
 
135
        self.assertEqual(self.ui.ui.upload_speed_spinbox.isEnabled(),
 
136
            limit_uploads == gui.CHECKED)
133
137
 
134
138
    def test_update_ui_from_backed_info(self):
135
139
        """The ui is correctly updated when the backend info is received."""
151
155
        self.ui.process_info(settings)
152
156
        self._test_update_ui_from_settings_info(settings)
153
157
 
154
 
    def _test_speed_checkbox_value_changed_to_positive(self, speed_spinbox,
155
 
                                                       limit_checkbox):
156
 
        """When the speed is set to a positive value, enable the checkbox."""
157
 
        limit_checkbox.setCheckState(gui.UNCHECKED)
158
 
        speed_spinbox.setValue(33)
159
 
 
160
 
        self.assertEqual(gui.CHECKED, limit_checkbox.checkState())
161
 
 
162
 
    def _test_speed_checkbox_value_changed_to_negative(self, speed_spinbox,
163
 
                                                       limit_checkbox):
164
 
        """When the speed is set to a negative value, disable the checkbox."""
165
 
        limit_checkbox.setCheckState(gui.UNCHECKED)
166
 
        speed_spinbox.setValue(-1)
167
 
 
168
 
        self.assertEqual(gui.UNCHECKED, limit_checkbox.checkState())
169
 
 
170
 
    def _test_speed_checkbox_unchecked(self, speed_spinbox, limit_checkbox):
171
 
        """When the speed checkbox is unchecked, reset speed to -1."""
 
158
    def _test_speed_checkbox_toggled(self, speed_spinbox, limit_checkbox):
 
159
        """The checkbox is checked if and only if the spinbox is enabled."""
172
160
        limit_checkbox.setCheckState(gui.CHECKED)
173
 
        speed_spinbox.setValue(33)
 
161
        self.assertTrue(speed_spinbox.isEnabled())
174
162
        limit_checkbox.setCheckState(gui.UNCHECKED)
175
 
 
176
 
        self.assertEqual(-1, speed_spinbox.value())
177
 
 
178
 
    def test_download_speed_checkbox_value_changed_to_positive(self):
179
 
        """When the download speed is set, enable the checkbox."""
180
 
        self._test_speed_checkbox_value_changed_to_positive(
181
 
            self.ui.ui.download_speed_spinbox,
182
 
            self.ui.ui.limit_downloads_checkbox)
183
 
 
184
 
    def test_download_speed_checkbox_value_changed_to_negative(self):
185
 
        """When the download speed is set, enable the checkbox."""
186
 
        self._test_speed_checkbox_value_changed_to_negative(
187
 
            self.ui.ui.download_speed_spinbox,
188
 
            self.ui.ui.limit_downloads_checkbox)
189
 
 
190
 
    def test_download_speed_checkbox_unchecked(self):
191
 
        """Reset the speed to -1 when the checkbox is disabled."""
192
 
        self._test_speed_checkbox_unchecked(
193
 
            self.ui.ui.download_speed_spinbox,
194
 
            self.ui.ui.limit_downloads_checkbox)
195
 
 
196
 
    def test_upload_speed_checkbox_value_changed_to_positive(self):
197
 
        """When the upload speed is set, enable the checkbox."""
198
 
        self._test_speed_checkbox_value_changed_to_positive(
199
 
            self.ui.ui.upload_speed_spinbox,
200
 
            self.ui.ui.limit_uploads_checkbox)
201
 
 
202
 
    def test_upload_speed_checkbox_value_changed_to_negative(self):
203
 
        """When the upload speed is set, enable the checkbox."""
204
 
        self._test_speed_checkbox_value_changed_to_negative(
205
 
            self.ui.ui.upload_speed_spinbox,
206
 
            self.ui.ui.limit_uploads_checkbox)
207
 
 
208
 
    def test_upload_speed_checkbox_unchecked(self):
209
 
        """Reset the speed to -1 when the checkbox is disabled."""
210
 
        self._test_speed_checkbox_unchecked(
 
163
        self.assertFalse(speed_spinbox.isEnabled())
 
164
 
 
165
    def test_download_speed_checkbox_connections(self):
 
166
        """Check connections for download_speed_checkbox."""
 
167
        self._test_speed_checkbox_toggled(
 
168
            self.ui.ui.download_speed_spinbox,
 
169
            self.ui.ui.limit_downloads_checkbox)
 
170
 
 
171
    def test_upload_speed_checkbox_connections(self):
 
172
        """Check connections for upload_speed_checkbox."""
 
173
        self._test_speed_checkbox_toggled(
211
174
            self.ui.ui.upload_speed_spinbox,
212
175
            self.ui.ui.limit_uploads_checkbox)
213
176
 
286
249
 
287
250
        yield self.ui.ui.restore_defaults_button.click()
288
251
 
289
 
    def test_tweak_speed_negative(self):
290
 
        """Tweak speed properly: if param is negative, return -1."""
291
 
        self.assertEqual(-1, gui.tweak_speed(-5))
292
 
 
293
 
    def test_tweak_speed_zero(self):
294
 
        """Tweak speed properly: if param is zero, return 1."""
295
 
        self.assertEqual(1, gui.tweak_speed(0))
296
 
 
297
 
    def test_tweak_speed_positive(self):
298
 
        """Tweak speed properly: if param is positive, return kilobytes."""
299
 
        self.assertEqual(123456 * gui.KILOBYTES, gui.tweak_speed(123456))
 
252
    def test_resize_event(self):
 
253
        """Check that the QCheckBox widgets receive the proper texts."""
 
254
        wrap_calls = {}
 
255
        self.patch(gui, "force_wordwrap",
 
256
            lambda check, size, text: operator.setitem(
 
257
                wrap_calls, check, (size, text)))
 
258
        self.ui.setFixedWidth(1000)
 
259
        size_bandwidth = (self.ui.ui.bandwidth_settings.width() -
 
260
            self.ui.ui.upload_speed_spinbox.width())
 
261
        padding = 160  # Left and Right Padding
 
262
        size_sync = (self.ui.ui.file_sync_settings.width() - padding)
 
263
        self.ui.show()
 
264
        self.addCleanup(self.ui.hide)
 
265
        self.assertEqual(wrap_calls[self.ui.ui.limit_uploads_checkbox],
 
266
            (size_bandwidth, gui.SETTINGS_LIMIT_UPLOAD))
 
267
        self.assertEqual(wrap_calls[self.ui.ui.limit_downloads_checkbox],
 
268
            (size_bandwidth, gui.SETTINGS_LIMIT_DOWNLOAD))
 
269
        self.assertEqual(wrap_calls[self.ui.ui.autoconnect_checkbox],
 
270
            (size_sync, gui.SETTINGS_AUTO_CONNECT))
 
271
        self.assertEqual(wrap_calls[self.ui.ui.udf_autosubscribe_checkbox],
 
272
            (size_sync, gui.SETTINGS_SYNC_ALL_SHARES))
 
273
        self.assertEqual(wrap_calls[self.ui.ui.share_autosubscribe_checkbox],
 
274
            (size_sync, gui.SETTINGS_SYNC_ALL_FOLDERS))
 
275
        self.assertEqual(
 
276
            wrap_calls[self.ui.ui.show_all_notifications_checkbox],
 
277
            (size_sync, gui.SETTINGS_ALLOW_NOTIFICATIONS))