Merge lp:~nataliabidart/ubuntuone-control-panel/stable-3-0-update-2.99.5 into lp:ubuntuone-control-panel/stable-3-0
- stable-3-0-update-2.99.5
- Merge into stable-3-0
Proposed by
Natalia Bidart
Status: | Merged | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Approved by: | Natalia Bidart | ||||||||||||
Approved revision: | 251 | ||||||||||||
Merged at revision: | 250 | ||||||||||||
Proposed branch: | lp:~nataliabidart/ubuntuone-control-panel/stable-3-0-update-2.99.5 | ||||||||||||
Merge into: | lp:ubuntuone-control-panel/stable-3-0 | ||||||||||||
Diff against target: |
508 lines (+248/-40) 11 files modified
data/qt/filesyncstatus.ui (+9/-2) data/qt/images.qrc (+1/-0) ubuntuone/controlpanel/gui/__init__.py (+17/-4) ubuntuone/controlpanel/gui/qt/controlpanel.py (+9/-20) ubuntuone/controlpanel/gui/qt/filesyncstatus.py (+12/-3) ubuntuone/controlpanel/gui/qt/gui.py (+7/-5) ubuntuone/controlpanel/gui/qt/tests/__init__.py (+67/-0) ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py (+2/-4) ubuntuone/controlpanel/gui/qt/tests/test_filesyncstatus.py (+29/-1) ubuntuone/controlpanel/gui/qt/tests/test_start.py (+20/-1) ubuntuone/controlpanel/gui/tests/test_show_quota_warning.py (+75/-0) |
||||||||||||
To merge this branch: | bzr merge lp:~nataliabidart/ubuntuone-control-panel/stable-3-0-update-2.99.5 | ||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Roberto Alsina (community) | Approve | ||
Review via email: mp+94067@code.launchpad.net |
Commit message
- Updating from trunk up to revno 262:
[ Diego Sarmentero <email address hidden> ]
- Control Panel shows quota in red with more accuracy depending on the
free space (LP: #901314).
- The QT UI will make a button inactive while a (re-) connection is
in progress (LP: #878867).
[ Natalia B. Bidart <email address hidden> ]
- Center the main window when openning it (LP: #934173).
Description of the change
To post a comment you must log in.
- 251. By Natalia Bidart
-
Attaching bug numbers.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'data/qt/filesyncstatus.ui' | |||
2 | --- data/qt/filesyncstatus.ui 2011-08-23 16:03:31 +0000 | |||
3 | +++ data/qt/filesyncstatus.ui 2012-02-21 23:16:17 +0000 | |||
4 | @@ -7,7 +7,7 @@ | |||
5 | 7 | <x>0</x> | 7 | <x>0</x> |
6 | 8 | <y>0</y> | 8 | <y>0</y> |
7 | 9 | <width>94</width> | 9 | <width>94</width> |
9 | 10 | <height>49</height> | 10 | <height>52</height> |
10 | 11 | </rect> | 11 | </rect> |
11 | 12 | </property> | 12 | </property> |
12 | 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
13 | @@ -20,7 +20,14 @@ | |||
14 | 20 | <item> | 20 | <item> |
15 | 21 | <layout class="QHBoxLayout" name="horizontalLayout"> | 21 | <layout class="QHBoxLayout" name="horizontalLayout"> |
16 | 22 | <item> | 22 | <item> |
18 | 23 | <widget class="QLabel" name="sync_status_icon"/> | 23 | <widget class="QLabel" name="sync_status_icon"> |
19 | 24 | <property name="sizePolicy"> | ||
20 | 25 | <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> | ||
21 | 26 | <horstretch>0</horstretch> | ||
22 | 27 | <verstretch>0</verstretch> | ||
23 | 28 | </sizepolicy> | ||
24 | 29 | </property> | ||
25 | 30 | </widget> | ||
26 | 24 | </item> | 31 | </item> |
27 | 25 | <item> | 32 | <item> |
28 | 26 | <widget class="QLabel" name="sync_status_label"> | 33 | <widget class="QLabel" name="sync_status_label"> |
29 | 27 | 34 | ||
30 | === modified file 'data/qt/images.qrc' | |||
31 | --- data/qt/images.qrc 2011-09-06 13:43:25 +0000 | |||
32 | +++ data/qt/images.qrc 2012-02-21 23:16:17 +0000 | |||
33 | @@ -6,6 +6,7 @@ | |||
34 | 6 | <file>../sync_status_alert.png</file> | 6 | <file>../sync_status_alert.png</file> |
35 | 7 | <file>../sync_status_sync_done.png</file> | 7 | <file>../sync_status_sync_done.png</file> |
36 | 8 | <file>../sync_status_syncing.png</file> | 8 | <file>../sync_status_syncing.png</file> |
37 | 9 | <file>../sync_status_loading.png</file> | ||
38 | 9 | <file>../folder.png</file> | 10 | <file>../folder.png</file> |
39 | 10 | <file>../computer.png</file> | 11 | <file>../computer.png</file> |
40 | 11 | <file>../phone.png</file> | 12 | <file>../phone.png</file> |
41 | 12 | 13 | ||
42 | === added file 'data/sync_status_loading.png' | |||
43 | 13 | Binary files data/sync_status_loading.png 1970-01-01 00:00:00 +0000 and data/sync_status_loading.png 2012-02-21 23:16:17 +0000 differ | 14 | Binary files data/sync_status_loading.png 1970-01-01 00:00:00 +0000 and data/sync_status_loading.png 2012-02-21 23:16:17 +0000 differ |
44 | === modified file 'ubuntuone/controlpanel/gui/__init__.py' | |||
45 | --- ubuntuone/controlpanel/gui/__init__.py 2012-02-06 15:23:27 +0000 | |||
46 | +++ ubuntuone/controlpanel/gui/__init__.py 2012-02-21 23:16:17 +0000 | |||
47 | @@ -1,9 +1,6 @@ | |||
48 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
49 | 2 | 2 | ||
54 | 3 | # Authors: Natalia B Bidart <natalia.bidart@canonical.com> | 3 | # Copyright 2011-2012 Canonical Ltd. |
51 | 4 | # Authors: Alejandro J. Cura <alecu@canonical.com> | ||
52 | 5 | # | ||
53 | 6 | # Copyright 2011 Canonical Ltd. | ||
55 | 7 | # | 4 | # |
56 | 8 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
57 | 9 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
58 | @@ -29,10 +26,14 @@ | |||
59 | 29 | 26 | ||
60 | 30 | ERROR_COLOR = u'red' | 27 | ERROR_COLOR = u'red' |
61 | 31 | KILOBYTES = 1024 | 28 | KILOBYTES = 1024 |
62 | 29 | FREE_ACCOUNT_SIZE = (KILOBYTES ** 3) * 5 # 5 gigs | ||
63 | 32 | NO_OP = lambda *a, **kw: None | 30 | NO_OP = lambda *a, **kw: None |
64 | 33 | # http://design.canonical.com/the-toolkit/ubuntu-logo-and-circle-of-friends/ | 31 | # http://design.canonical.com/the-toolkit/ubuntu-logo-and-circle-of-friends/ |
65 | 34 | ORANGE = u'#DD4814' | 32 | ORANGE = u'#DD4814' |
66 | 35 | QUOTA_THRESHOLD = 0.95 | 33 | QUOTA_THRESHOLD = 0.95 |
67 | 34 | QUOTA_THRESHOLD_ACCOUNTS = { | ||
68 | 35 | 'free': FREE_ACCOUNT_SIZE * 0.1, # 10% of the free account size | ||
69 | 36 | 'pay': (KILOBYTES ** 3) * 3} # 3 gigs | ||
70 | 36 | SHARES_MIN_SIZE_FULL = 1048576 | 37 | SHARES_MIN_SIZE_FULL = 1048576 |
71 | 37 | SUCCESS_COLOR = u'green' | 38 | SUCCESS_COLOR = u'green' |
72 | 38 | 39 | ||
73 | @@ -153,6 +154,7 @@ | |||
74 | 153 | NO_FOLDERS = _('No folders to show.') | 154 | NO_FOLDERS = _('No folders to show.') |
75 | 154 | NO_PAIRING_RECORD = _('There is no Ubuntu One pairing record.') | 155 | NO_PAIRING_RECORD = _('There is no Ubuntu One pairing record.') |
76 | 155 | PERCENTAGE_LABEL = _('%(percentage)s used') | 156 | PERCENTAGE_LABEL = _('%(percentage)s used') |
77 | 157 | PLEASE_WAIT = _('Please wait') | ||
78 | 156 | QUOTA_LABEL = _('Using %(used)s of %(total)s (%(percentage).0f%%)') | 158 | QUOTA_LABEL = _('Using %(used)s of %(total)s (%(percentage).0f%%)') |
79 | 157 | USAGE_LABEL = _('%(used)s of %(total)s') | 159 | USAGE_LABEL = _('%(used)s of %(total)s') |
80 | 158 | SERVICES_BUTTON_TOOLTIP = _('Manage the sync services') | 160 | SERVICES_BUTTON_TOOLTIP = _('Manage the sync services') |
81 | @@ -184,3 +186,14 @@ | |||
82 | 184 | str_bytes = str_bytes.rstrip('0') | 186 | str_bytes = str_bytes.rstrip('0') |
83 | 185 | str_bytes = str_bytes.rstrip('.') | 187 | str_bytes = str_bytes.rstrip('.') |
84 | 186 | return '%s %s' % (str_bytes, units[unit]) | 188 | return '%s %s' % (str_bytes, units[unit]) |
85 | 189 | |||
86 | 190 | |||
87 | 191 | def show_quota_warning(int_bytes_used, int_bytes_total): | ||
88 | 192 | """Return True if the user should be warn about the remaining quota.""" | ||
89 | 193 | available = (int_bytes_total - int_bytes_used) | ||
90 | 194 | free_threshold = (int_bytes_total == FREE_ACCOUNT_SIZE and | ||
91 | 195 | available <= QUOTA_THRESHOLD_ACCOUNTS['free']) | ||
92 | 196 | payed_threshold = (int_bytes_total > FREE_ACCOUNT_SIZE and | ||
93 | 197 | available <= QUOTA_THRESHOLD_ACCOUNTS['pay']) | ||
94 | 198 | |||
95 | 199 | return free_threshold or payed_threshold | ||
96 | 187 | 200 | ||
97 | === modified file 'ubuntuone/controlpanel/gui/qt/controlpanel.py' | |||
98 | --- ubuntuone/controlpanel/gui/qt/controlpanel.py 2011-09-23 15:05:27 +0000 | |||
99 | +++ ubuntuone/controlpanel/gui/qt/controlpanel.py 2012-02-21 23:16:17 +0000 | |||
100 | @@ -1,9 +1,6 @@ | |||
101 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
102 | 2 | 2 | ||
107 | 3 | # Authors: Alejandro J. Cura <alecu@canonical.com> | 3 | # Copyright 2012 Canonical Ltd. |
104 | 4 | # Authors: Natalia B Bidart <natalia.bidart@canonical.com> | ||
105 | 5 | # | ||
106 | 6 | # Copyright 2011 Canonical Ltd. | ||
108 | 7 | # | 4 | # |
109 | 8 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
110 | 9 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
111 | @@ -28,12 +25,12 @@ | |||
112 | 28 | from ubuntuone.controlpanel.logger import setup_logging, log_call | 25 | from ubuntuone.controlpanel.logger import setup_logging, log_call |
113 | 29 | from ubuntuone.controlpanel.gui import ( | 26 | from ubuntuone.controlpanel.gui import ( |
114 | 30 | humanize, | 27 | humanize, |
115 | 28 | show_quota_warning, | ||
116 | 31 | EDIT_SERVICES_LINK, | 29 | EDIT_SERVICES_LINK, |
117 | 32 | FACEBOOK_LINK, | 30 | FACEBOOK_LINK, |
118 | 33 | GET_SUPPORT_LINK, | 31 | GET_SUPPORT_LINK, |
119 | 34 | GREETING, | 32 | GREETING, |
120 | 35 | PERCENTAGE_LABEL, | 33 | PERCENTAGE_LABEL, |
121 | 36 | QUOTA_THRESHOLD, | ||
122 | 37 | TWITTER_LINK, | 34 | TWITTER_LINK, |
123 | 38 | USAGE_LABEL, | 35 | USAGE_LABEL, |
124 | 39 | ) | 36 | ) |
125 | @@ -105,27 +102,19 @@ | |||
126 | 105 | total = int(info['quota_total']) | 102 | total = int(info['quota_total']) |
127 | 106 | percentage_value = ((used / total) * 100) | 103 | percentage_value = ((used / total) * 100) |
128 | 107 | percentage = {'percentage': PERCENTAGE_STYLE % percentage_value} | 104 | percentage = {'percentage': PERCENTAGE_STYLE % percentage_value} |
129 | 105 | show_warning = show_quota_warning(used, total) | ||
130 | 108 | data = {'used': humanize(used), 'total': humanize(total)} | 106 | data = {'used': humanize(used), 'total': humanize(total)} |
131 | 109 | self.ui.percentage_usage_label.setText(PERCENTAGE_LABEL % percentage) | 107 | self.ui.percentage_usage_label.setText(PERCENTAGE_LABEL % percentage) |
132 | 110 | self.ui.quota_usage_label.setText(USAGE_LABEL % data) | 108 | self.ui.quota_usage_label.setText(USAGE_LABEL % data) |
134 | 111 | self._update_quota({'percentage': percentage_value}) | 109 | self._update_quota(show_warning) |
135 | 112 | 110 | ||
136 | 113 | @log_call(logger.debug) | 111 | @log_call(logger.debug) |
138 | 114 | def _update_quota(self, data=None): | 112 | def _update_quota(self, show_warning=False): |
139 | 115 | """Update the quota info.""" | 113 | """Update the quota info.""" |
153 | 116 | fraction = 0.0 | 114 | logger.debug('ManagementPanel: show warning in quota %r.', |
154 | 117 | if data is not None: | 115 | show_warning) |
155 | 118 | fraction = data.get('percentage', 0.0) / 100 | 116 | self.ui.percentage_usage_label.setProperty("OverQuota", show_warning) |
156 | 119 | if fraction > 0 and fraction < 0.05: | 117 | self.ui.quota_usage_label.setProperty("OverQuota", show_warning) |
144 | 120 | fraction = 0.05 | ||
145 | 121 | else: | ||
146 | 122 | fraction = round(fraction, 2) | ||
147 | 123 | |||
148 | 124 | logger.debug('ManagementPanel: updating quota to %r.', fraction) | ||
149 | 125 | self.ui.percentage_usage_label.setProperty("OverQuota", | ||
150 | 126 | fraction >= QUOTA_THRESHOLD) | ||
151 | 127 | self.ui.quota_usage_label.setProperty("OverQuota", | ||
152 | 128 | fraction >= QUOTA_THRESHOLD) | ||
157 | 129 | self.ui.percentage_usage_label.style().unpolish( | 118 | self.ui.percentage_usage_label.style().unpolish( |
158 | 130 | self.ui.percentage_usage_label) | 119 | self.ui.percentage_usage_label) |
159 | 131 | self.ui.percentage_usage_label.style().polish( | 120 | self.ui.percentage_usage_label.style().polish( |
160 | 132 | 121 | ||
161 | === modified file 'ubuntuone/controlpanel/gui/qt/filesyncstatus.py' | |||
162 | --- ubuntuone/controlpanel/gui/qt/filesyncstatus.py 2011-09-02 17:59:39 +0000 | |||
163 | +++ ubuntuone/controlpanel/gui/qt/filesyncstatus.py 2012-02-21 23:16:17 +0000 | |||
164 | @@ -1,8 +1,6 @@ | |||
165 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
166 | 2 | |||
167 | 3 | # Authors: Natalia B Bidart <natalia.bidart@canonical.com> | ||
168 | 4 | # | 2 | # |
170 | 5 | # Copyright 2011 Canonical Ltd. | 3 | # Copyright 2011-2012 Canonical Ltd. |
171 | 6 | # | 4 | # |
172 | 7 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
173 | 8 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
174 | @@ -44,6 +42,8 @@ | |||
175 | 44 | FILE_SYNC_STOP_TOOLTIP, | 42 | FILE_SYNC_STOP_TOOLTIP, |
176 | 45 | FILE_SYNC_STOPPED, | 43 | FILE_SYNC_STOPPED, |
177 | 46 | FILE_SYNC_SYNCING, | 44 | FILE_SYNC_SYNCING, |
178 | 45 | LOADING, | ||
179 | 46 | PLEASE_WAIT, | ||
180 | 47 | ) | 47 | ) |
181 | 48 | from ubuntuone.controlpanel.gui.qt import pixmap_from_name | 48 | from ubuntuone.controlpanel.gui.qt import pixmap_from_name |
182 | 49 | from ubuntuone.controlpanel.gui.qt.ui import filesyncstatus_ui | 49 | from ubuntuone.controlpanel.gui.qt.ui import filesyncstatus_ui |
183 | @@ -186,6 +186,15 @@ | |||
184 | 186 | """Button was clicked, act accordingly to the label.""" | 186 | """Button was clicked, act accordingly to the label.""" |
185 | 187 | self.ui.sync_status_button.setEnabled(False) | 187 | self.ui.sync_status_button.setEnabled(False) |
186 | 188 | if self._backend_method is not None: | 188 | if self._backend_method is not None: |
187 | 189 | self.ui.sync_status_label.setText(LOADING) | ||
188 | 190 | self.ui.sync_status_button.setText(PLEASE_WAIT) | ||
189 | 191 | pixmap = pixmap_from_name('sync_status_loading') | ||
190 | 192 | self.ui.sync_status_icon.setPixmap(pixmap) | ||
191 | 193 | self.ui.sync_status_button.setProperty("secondary", True) | ||
192 | 194 | self.ui.sync_status_button.style().unpolish( | ||
193 | 195 | self.ui.sync_status_button) | ||
194 | 196 | self.ui.sync_status_button.style().polish( | ||
195 | 197 | self.ui.sync_status_button) | ||
196 | 189 | self._backend_method() | 198 | self._backend_method() |
197 | 190 | else: | 199 | else: |
198 | 191 | logger.error('on_sync_status_button_clicked: backend method is ' | 200 | logger.error('on_sync_status_button_clicked: backend method is ' |
199 | 192 | 201 | ||
200 | === modified file 'ubuntuone/controlpanel/gui/qt/gui.py' | |||
201 | --- ubuntuone/controlpanel/gui/qt/gui.py 2012-02-07 13:54:46 +0000 | |||
202 | +++ ubuntuone/controlpanel/gui/qt/gui.py 2012-02-21 23:16:17 +0000 | |||
203 | @@ -1,8 +1,6 @@ | |||
204 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
205 | 2 | |||
206 | 3 | # Authors: Alejandro J. Cura <alecu@canonical.com> | ||
207 | 4 | # | 2 | # |
209 | 5 | # Copyright 2011 Canonical Ltd. | 3 | # Copyright 2011-2012 Canonical Ltd. |
210 | 6 | # | 4 | # |
211 | 7 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
212 | 8 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
213 | @@ -18,8 +16,7 @@ | |||
214 | 18 | 16 | ||
215 | 19 | """The user interface for the control panel for Ubuntu One.""" | 17 | """The user interface for the control panel for Ubuntu One.""" |
216 | 20 | 18 | ||
219 | 21 | 19 | from PyQt4 import QtGui, QtCore | |
218 | 22 | from PyQt4 import QtGui | ||
220 | 23 | 20 | ||
221 | 24 | from ubuntuone.controlpanel.gui.qt.systray import TrayIcon | 21 | from ubuntuone.controlpanel.gui.qt.systray import TrayIcon |
222 | 25 | from ubuntuone.controlpanel.gui.qt.ui import mainwindow_ui | 22 | from ubuntuone.controlpanel.gui.qt.ui import mainwindow_ui |
223 | @@ -60,6 +57,11 @@ | |||
224 | 60 | window = MainWindow() | 57 | window = MainWindow() |
225 | 61 | else: | 58 | else: |
226 | 62 | window = MainWindow(close_callback=close_callback) | 59 | window = MainWindow(close_callback=close_callback) |
227 | 60 | app = QtGui.QApplication.instance() | ||
228 | 61 | style = QtGui.QStyle.alignedRect( | ||
229 | 62 | QtCore.Qt.LeftToRight, QtCore.Qt.AlignCenter, | ||
230 | 63 | window.size(), app.desktop().availableGeometry()) | ||
231 | 64 | window.setGeometry(style) | ||
232 | 63 | window.show() | 65 | window.show() |
233 | 64 | else: | 66 | else: |
234 | 65 | window = None | 67 | window = None |
235 | 66 | 68 | ||
236 | === modified file 'ubuntuone/controlpanel/gui/qt/tests/__init__.py' | |||
237 | --- ubuntuone/controlpanel/gui/qt/tests/__init__.py 2012-02-06 15:23:27 +0000 | |||
238 | +++ ubuntuone/controlpanel/gui/qt/tests/__init__.py 2012-02-21 23:16:17 +0000 | |||
239 | @@ -233,6 +233,73 @@ | |||
240 | 233 | # pylint: enable=C0103 | 233 | # pylint: enable=C0103 |
241 | 234 | 234 | ||
242 | 235 | 235 | ||
243 | 236 | class FakePageUiStyle(object): | ||
244 | 237 | """Fake the page.""" | ||
245 | 238 | |||
246 | 239 | def __init__(self): | ||
247 | 240 | self.ui = self | ||
248 | 241 | self.properties = {} | ||
249 | 242 | super(FakePageUiStyle, self).__init__() | ||
250 | 243 | |||
251 | 244 | def wizard(self): | ||
252 | 245 | """Use itself as a fake wizard, too.""" | ||
253 | 246 | return self | ||
254 | 247 | |||
255 | 248 | def text(self): | ||
256 | 249 | """Return text.""" | ||
257 | 250 | return self.properties.get('text', '') | ||
258 | 251 | |||
259 | 252 | # setText, setEnabled are inherited | ||
260 | 253 | # pylint: disable=C0103 | ||
261 | 254 | def setText(self, text): | ||
262 | 255 | """Save text.""" | ||
263 | 256 | self.properties['text'] = text | ||
264 | 257 | |||
265 | 258 | def setEnabled(self, value): | ||
266 | 259 | """Fake setEnabled.""" | ||
267 | 260 | self.properties['enabled'] = value | ||
268 | 261 | |||
269 | 262 | def enabled(self): | ||
270 | 263 | """Fake enabled.""" | ||
271 | 264 | return self.properties.get('enabled', False) | ||
272 | 265 | |||
273 | 266 | def isEnabled(self): | ||
274 | 267 | """Fake isEnabled.""" | ||
275 | 268 | return self.properties.get('enabled', False) | ||
276 | 269 | |||
277 | 270 | def setProperty(self, key, val): | ||
278 | 271 | """Fake setProperty to restyle some widget.""" | ||
279 | 272 | self.properties[key] = val | ||
280 | 273 | |||
281 | 274 | def property(self, key): | ||
282 | 275 | """Fake property from widget style.""" | ||
283 | 276 | return self.properties.get(key, False) | ||
284 | 277 | |||
285 | 278 | def setDefault(self, val): | ||
286 | 279 | """Fake button setDefault.""" | ||
287 | 280 | self.properties['default'] = val | ||
288 | 281 | |||
289 | 282 | def style(self): | ||
290 | 283 | """Fake style.""" | ||
291 | 284 | return self | ||
292 | 285 | |||
293 | 286 | def unpolish(self, *args): | ||
294 | 287 | """Fake unpolish.""" | ||
295 | 288 | self.properties['unpolish'] = len(args) > 0 | ||
296 | 289 | |||
297 | 290 | def polish(self, *args): | ||
298 | 291 | """Fake polish.""" | ||
299 | 292 | self.properties['polish'] = len(args) > 0 | ||
300 | 293 | |||
301 | 294 | def setVisible(self, val): | ||
302 | 295 | """Fake setVisible from Qt.""" | ||
303 | 296 | self.properties['visible'] = val | ||
304 | 297 | |||
305 | 298 | def isVisible(self): | ||
306 | 299 | """Fake isVisible from Qt.""" | ||
307 | 300 | return self.properties['visible'] | ||
308 | 301 | |||
309 | 302 | |||
310 | 236 | class BaseTestCase(TestCase): | 303 | class BaseTestCase(TestCase): |
311 | 237 | """Base Test Case.""" | 304 | """Base Test Case.""" |
312 | 238 | 305 | ||
313 | 239 | 306 | ||
314 | === modified file 'ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py' | |||
315 | --- ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py 2011-09-12 20:17:37 +0000 | |||
316 | +++ ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py 2012-02-21 23:16:17 +0000 | |||
317 | @@ -126,9 +126,8 @@ | |||
318 | 126 | 126 | ||
319 | 127 | def test_update_over_quota(self): | 127 | def test_update_over_quota(self): |
320 | 128 | """Check the labels state when the user exceed the quota.""" | 128 | """Check the labels state when the user exceed the quota.""" |
321 | 129 | percentage_value = 100 | ||
322 | 130 | # pylint: disable=W0212 | 129 | # pylint: disable=W0212 |
324 | 131 | self.ui._update_quota({'percentage': percentage_value}) | 130 | self.ui._update_quota(True) |
325 | 132 | # pylint: enable=W0212 | 131 | # pylint: enable=W0212 |
326 | 133 | 132 | ||
327 | 134 | self.assertTrue( | 133 | self.assertTrue( |
328 | @@ -138,9 +137,8 @@ | |||
329 | 138 | 137 | ||
330 | 139 | def test_update_quota_in_range(self): | 138 | def test_update_quota_in_range(self): |
331 | 140 | """Check the labels state when the quota is under the threshold.""" | 139 | """Check the labels state when the quota is under the threshold.""" |
332 | 141 | percentage_value = 50 | ||
333 | 142 | # pylint: disable=W0212 | 140 | # pylint: disable=W0212 |
335 | 143 | self.ui._update_quota({'percentage': percentage_value}) | 141 | self.ui._update_quota(False) |
336 | 144 | # pylint: enable=W0212 | 142 | # pylint: enable=W0212 |
337 | 145 | 143 | ||
338 | 146 | self.assertFalse( | 144 | self.assertFalse( |
339 | 147 | 145 | ||
340 | === modified file 'ubuntuone/controlpanel/gui/qt/tests/test_filesyncstatus.py' | |||
341 | --- ubuntuone/controlpanel/gui/qt/tests/test_filesyncstatus.py 2011-10-28 08:19:20 +0000 | |||
342 | +++ ubuntuone/controlpanel/gui/qt/tests/test_filesyncstatus.py 2012-02-21 23:16:17 +0000 | |||
343 | @@ -21,7 +21,14 @@ | |||
344 | 21 | from twisted.internet import defer | 21 | from twisted.internet import defer |
345 | 22 | 22 | ||
346 | 23 | from ubuntuone.controlpanel.gui.qt import filesyncstatus as gui | 23 | from ubuntuone.controlpanel.gui.qt import filesyncstatus as gui |
348 | 24 | from ubuntuone.controlpanel.gui.qt.tests import BaseTestCase | 24 | from ubuntuone.controlpanel.gui.qt.tests import ( |
349 | 25 | BaseTestCase, | ||
350 | 26 | FakePageUiStyle, | ||
351 | 27 | ) | ||
352 | 28 | from ubuntuone.controlpanel.gui import ( | ||
353 | 29 | LOADING, | ||
354 | 30 | PLEASE_WAIT, | ||
355 | 31 | ) | ||
356 | 25 | 32 | ||
357 | 26 | backend = gui.backend # pylint: disable=C0103 | 33 | backend = gui.backend # pylint: disable=C0103 |
358 | 27 | 34 | ||
359 | @@ -171,3 +178,24 @@ | |||
360 | 171 | action=gui.FILE_SYNC_RESTART, | 178 | action=gui.FILE_SYNC_RESTART, |
361 | 172 | callback='restart_files', | 179 | callback='restart_files', |
362 | 173 | tooltip=gui.FILE_SYNC_RESTART_TOOLTIP) | 180 | tooltip=gui.FILE_SYNC_RESTART_TOOLTIP) |
363 | 181 | |||
364 | 182 | def test_on_sync_status_button_clicked(self): | ||
365 | 183 | """Check the labels and icon when the button is pressed.""" | ||
366 | 184 | # Ensure the _backend_method is not None to execute the first | ||
367 | 185 | # part of the If. | ||
368 | 186 | self.ui._backend_method = lambda: 'Not None' | ||
369 | 187 | self.patch(self.ui.ui, "sync_status_button", FakePageUiStyle()) | ||
370 | 188 | # Simulate the click event | ||
371 | 189 | self.ui.on_sync_status_button_clicked() | ||
372 | 190 | self.assertFalse(self.ui.ui.sync_status_button.isEnabled()) | ||
373 | 191 | self.assertTrue(self.ui.ui.sync_status_button.property("secondary")) | ||
374 | 192 | actual_text = self.ui.ui.sync_status_label.text() | ||
375 | 193 | self.assertEqual(actual_text, LOADING) | ||
376 | 194 | self.assertEqual(self.ui.ui.sync_status_button.text(), PLEASE_WAIT) | ||
377 | 195 | actual_icon = self.ui.ui.sync_status_icon.pixmap() | ||
378 | 196 | expected_icon = gui.pixmap_from_name('sync_status_loading') | ||
379 | 197 | self.assertEqualPixmaps(expected_icon, actual_icon) | ||
380 | 198 | self.assertTrue( | ||
381 | 199 | self.ui.ui.sync_status_button.properties.get('unpolish', True)) | ||
382 | 200 | self.assertTrue( | ||
383 | 201 | self.ui.ui.sync_status_button.properties.get('polish', True)) | ||
384 | 174 | 202 | ||
385 | === modified file 'ubuntuone/controlpanel/gui/qt/tests/test_start.py' | |||
386 | --- ubuntuone/controlpanel/gui/qt/tests/test_start.py 2012-02-07 13:54:46 +0000 | |||
387 | +++ ubuntuone/controlpanel/gui/qt/tests/test_start.py 2012-02-21 23:16:17 +0000 | |||
388 | @@ -28,9 +28,12 @@ | |||
389 | 28 | 28 | ||
390 | 29 | """A fake thing.""" | 29 | """A fake thing.""" |
391 | 30 | 30 | ||
392 | 31 | shown = False | ||
393 | 32 | size = lambda *a: gui.QtCore.QSize(123456, 654321) | ||
394 | 33 | style = None | ||
395 | 34 | |||
396 | 31 | def __init__(self): | 35 | def __init__(self): |
397 | 32 | self.args = [] | 36 | self.args = [] |
398 | 33 | self.shown = False | ||
399 | 34 | 37 | ||
400 | 35 | def __call__(self, *args, **kwargs): | 38 | def __call__(self, *args, **kwargs): |
401 | 36 | self.args.append((args, kwargs)) | 39 | self.args.append((args, kwargs)) |
402 | @@ -40,6 +43,13 @@ | |||
403 | 40 | """Show.""" | 43 | """Show.""" |
404 | 41 | self.shown = True | 44 | self.shown = True |
405 | 42 | 45 | ||
406 | 46 | # Invalid name "setGeometry" | ||
407 | 47 | # pylint: disable=C0103 | ||
408 | 48 | |||
409 | 49 | def setGeometry(self, style): | ||
410 | 50 | """Save the new geometry.""" | ||
411 | 51 | self.style = style | ||
412 | 52 | |||
413 | 43 | 53 | ||
414 | 44 | class StartTestCase(TestCase): | 54 | class StartTestCase(TestCase): |
415 | 45 | """Test the qt control panel.""" | 55 | """Test the qt control panel.""" |
416 | @@ -87,3 +97,12 @@ | |||
417 | 87 | kwargs = {'close_callback': self.close_cb, 'window': None} | 97 | kwargs = {'close_callback': self.close_cb, 'window': None} |
418 | 88 | self.assertEqual(self.tray_icon.args, [((), kwargs)]) | 98 | self.assertEqual(self.tray_icon.args, [((), kwargs)]) |
419 | 89 | self.assertEqual(self.main_window.args, []) | 99 | self.assertEqual(self.main_window.args, []) |
420 | 100 | |||
421 | 101 | def test_center_window(self): | ||
422 | 102 | """The main window should be centered.""" | ||
423 | 103 | gui.start(close_callback=self.close_cb) | ||
424 | 104 | app = gui.QtGui.QApplication.instance() | ||
425 | 105 | expected = gui.QtGui.QStyle.alignedRect(gui.QtCore.Qt.LeftToRight, | ||
426 | 106 | gui.QtCore.Qt.AlignCenter, self.main_window.size(), | ||
427 | 107 | app.desktop().availableGeometry()) | ||
428 | 108 | self.assertEqual(self.main_window.style, expected) | ||
429 | 90 | 109 | ||
430 | === added file 'ubuntuone/controlpanel/gui/tests/test_show_quota_warning.py' | |||
431 | --- ubuntuone/controlpanel/gui/tests/test_show_quota_warning.py 1970-01-01 00:00:00 +0000 | |||
432 | +++ ubuntuone/controlpanel/gui/tests/test_show_quota_warning.py 2012-02-21 23:16:17 +0000 | |||
433 | @@ -0,0 +1,75 @@ | |||
434 | 1 | # -*- coding: utf-8 -*- | ||
435 | 2 | |||
436 | 3 | # Copyright 2012 Canonical Ltd. | ||
437 | 4 | # | ||
438 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
439 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
440 | 7 | # by the Free Software Foundation. | ||
441 | 8 | # | ||
442 | 9 | # This program is distributed in the hope that it will be useful, but | ||
443 | 10 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
444 | 11 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
445 | 12 | # PURPOSE. See the GNU General Public License for more details. | ||
446 | 13 | # | ||
447 | 14 | # You should have received a copy of the GNU General Public License along | ||
448 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
449 | 16 | |||
450 | 17 | """Tests for the show_quota_warning function.""" | ||
451 | 18 | |||
452 | 19 | from ubuntuone.controlpanel.tests import TestCase | ||
453 | 20 | from ubuntuone.controlpanel.gui import show_quota_warning | ||
454 | 21 | |||
455 | 22 | |||
456 | 23 | GB5 = 5368709120 # 5 Gb | ||
457 | 24 | GB25 = 26843545600 # 25 Gb | ||
458 | 25 | |||
459 | 26 | |||
460 | 27 | class QuotaWarningTestCase(TestCase): | ||
461 | 28 | |||
462 | 29 | """Test cases for the humanize function.""" | ||
463 | 30 | |||
464 | 31 | def test_quota_warning_with_used_0_free_account(self): | ||
465 | 32 | """Check the return value for show_quota_warning with 0 bytes used.""" | ||
466 | 33 | self.assertFalse(show_quota_warning(0, GB5)) | ||
467 | 34 | |||
468 | 35 | def test_quota_warning_with_free_account_used_medium(self): | ||
469 | 36 | """Check the return value for show_quota_warning with 2.5 gb used.""" | ||
470 | 37 | used = 2.5 * (1024 ** 3) # 2.5 Gb | ||
471 | 38 | self.assertFalse(show_quota_warning(used, GB5)) | ||
472 | 39 | |||
473 | 40 | def test_quota_warning_with_free_account_used_almost_full(self): | ||
474 | 41 | """Check the return value for show_quota_warning with 4.5 gb used.""" | ||
475 | 42 | # For free accounts the warning should be activate when the user | ||
476 | 43 | # has equal or less than 500 mb remaining | ||
477 | 44 | used = 4.5 * (1024 ** 3) # 4.5 Gb | ||
478 | 45 | self.assertTrue(show_quota_warning(used, GB5)) | ||
479 | 46 | |||
480 | 47 | def test_quota_warning_with_free_account_used_full(self): | ||
481 | 48 | """Check the return value for show_quota_warning with 5 gb used.""" | ||
482 | 49 | # For free accounts the warning should be activate when the user | ||
483 | 50 | # has equal or less than 500 mb remaining | ||
484 | 51 | used = 5.0 * (1024 ** 3) # 5.0 Gb | ||
485 | 52 | self.assertTrue(show_quota_warning(used, GB5)) | ||
486 | 53 | |||
487 | 54 | def test_quota_warning_with_used_0_pay_account(self): | ||
488 | 55 | """Check the return value for show_quota_warning with 0 bytes used.""" | ||
489 | 56 | self.assertFalse(show_quota_warning(0, GB25)) | ||
490 | 57 | |||
491 | 58 | def test_quota_warning_with_pay_account_used_medium(self): | ||
492 | 59 | """Check the return value for show_quota_warning with 12.5 gb used.""" | ||
493 | 60 | used = 12.5 * (1024 ** 3) # 12.5 Gb | ||
494 | 61 | self.assertFalse(show_quota_warning(used, GB25)) | ||
495 | 62 | |||
496 | 63 | def test_quota_warning_with_pay_account_used_almost_full(self): | ||
497 | 64 | """Check the return value for show_quota_warning with 22 gb used.""" | ||
498 | 65 | # For pay accounts the warning should be activate when the user | ||
499 | 66 | # has equal or less than 3 Gb remaining | ||
500 | 67 | used = 22 * (1024 ** 3) # 22 Gb | ||
501 | 68 | self.assertTrue(show_quota_warning(used, GB25)) | ||
502 | 69 | |||
503 | 70 | def test_quota_warning_with_pay_account_used_full(self): | ||
504 | 71 | """Check the return value for show_quota_warning with 25 gb used.""" | ||
505 | 72 | # For free accounts the warning should be activate when the user | ||
506 | 73 | # has equal or less than 3 gb remaining | ||
507 | 74 | used = 25 * (1024 ** 3) # 25 Gb | ||
508 | 75 | self.assertTrue(show_quota_warning(used, GB25)) |
+1