Merge lp:~nataliabidart/ubuntuone-control-panel/stable-3-0-update-2.99.5 into lp:ubuntuone-control-panel/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
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).

To post a comment you must log in.
251. By Natalia Bidart

Attaching bug numbers.

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 'data/qt/filesyncstatus.ui'
--- data/qt/filesyncstatus.ui 2011-08-23 16:03:31 +0000
+++ data/qt/filesyncstatus.ui 2012-02-21 23:16:17 +0000
@@ -7,7 +7,7 @@
7 <x>0</x>7 <x>0</x>
8 <y>0</y>8 <y>0</y>
9 <width>94</width>9 <width>94</width>
10 <height>49</height>10 <height>52</height>
11 </rect>11 </rect>
12 </property>12 </property>
13 <property name="windowTitle">13 <property name="windowTitle">
@@ -20,7 +20,14 @@
20 <item>20 <item>
21 <layout class="QHBoxLayout" name="horizontalLayout">21 <layout class="QHBoxLayout" name="horizontalLayout">
22 <item>22 <item>
23 <widget class="QLabel" name="sync_status_icon"/>23 <widget class="QLabel" name="sync_status_icon">
24 <property name="sizePolicy">
25 <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
26 <horstretch>0</horstretch>
27 <verstretch>0</verstretch>
28 </sizepolicy>
29 </property>
30 </widget>
24 </item>31 </item>
25 <item>32 <item>
26 <widget class="QLabel" name="sync_status_label">33 <widget class="QLabel" name="sync_status_label">
2734
=== modified file 'data/qt/images.qrc'
--- data/qt/images.qrc 2011-09-06 13:43:25 +0000
+++ data/qt/images.qrc 2012-02-21 23:16:17 +0000
@@ -6,6 +6,7 @@
6 <file>../sync_status_alert.png</file>6 <file>../sync_status_alert.png</file>
7 <file>../sync_status_sync_done.png</file>7 <file>../sync_status_sync_done.png</file>
8 <file>../sync_status_syncing.png</file>8 <file>../sync_status_syncing.png</file>
9 <file>../sync_status_loading.png</file>
9 <file>../folder.png</file>10 <file>../folder.png</file>
10 <file>../computer.png</file>11 <file>../computer.png</file>
11 <file>../phone.png</file>12 <file>../phone.png</file>
1213
=== added file 'data/sync_status_loading.png'
13Binary 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 differ14Binary 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
=== modified file 'ubuntuone/controlpanel/gui/__init__.py'
--- ubuntuone/controlpanel/gui/__init__.py 2012-02-06 15:23:27 +0000
+++ ubuntuone/controlpanel/gui/__init__.py 2012-02-21 23:16:17 +0000
@@ -1,9 +1,6 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
22
3# Authors: Natalia B Bidart <natalia.bidart@canonical.com>3# Copyright 2011-2012 Canonical Ltd.
4# Authors: Alejandro J. Cura <alecu@canonical.com>
5#
6# Copyright 2011 Canonical Ltd.
7#4#
8# This program is free software: you can redistribute it and/or modify it5# This program is free software: you can redistribute it and/or modify it
9# under the terms of the GNU General Public License version 3, as published6# under the terms of the GNU General Public License version 3, as published
@@ -29,10 +26,14 @@
2926
30ERROR_COLOR = u'red'27ERROR_COLOR = u'red'
31KILOBYTES = 102428KILOBYTES = 1024
29FREE_ACCOUNT_SIZE = (KILOBYTES ** 3) * 5 # 5 gigs
32NO_OP = lambda *a, **kw: None30NO_OP = lambda *a, **kw: None
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/
34ORANGE = u'#DD4814'32ORANGE = u'#DD4814'
35QUOTA_THRESHOLD = 0.9533QUOTA_THRESHOLD = 0.95
34QUOTA_THRESHOLD_ACCOUNTS = {
35 'free': FREE_ACCOUNT_SIZE * 0.1, # 10% of the free account size
36 'pay': (KILOBYTES ** 3) * 3} # 3 gigs
36SHARES_MIN_SIZE_FULL = 104857637SHARES_MIN_SIZE_FULL = 1048576
37SUCCESS_COLOR = u'green'38SUCCESS_COLOR = u'green'
3839
@@ -153,6 +154,7 @@
153NO_FOLDERS = _('No folders to show.')154NO_FOLDERS = _('No folders to show.')
154NO_PAIRING_RECORD = _('There is no Ubuntu One pairing record.')155NO_PAIRING_RECORD = _('There is no Ubuntu One pairing record.')
155PERCENTAGE_LABEL = _('%(percentage)s used')156PERCENTAGE_LABEL = _('%(percentage)s used')
157PLEASE_WAIT = _('Please wait')
156QUOTA_LABEL = _('Using %(used)s of %(total)s (%(percentage).0f%%)')158QUOTA_LABEL = _('Using %(used)s of %(total)s (%(percentage).0f%%)')
157USAGE_LABEL = _('%(used)s of %(total)s')159USAGE_LABEL = _('%(used)s of %(total)s')
158SERVICES_BUTTON_TOOLTIP = _('Manage the sync services')160SERVICES_BUTTON_TOOLTIP = _('Manage the sync services')
@@ -184,3 +186,14 @@
184 str_bytes = str_bytes.rstrip('0')186 str_bytes = str_bytes.rstrip('0')
185 str_bytes = str_bytes.rstrip('.')187 str_bytes = str_bytes.rstrip('.')
186 return '%s %s' % (str_bytes, units[unit])188 return '%s %s' % (str_bytes, units[unit])
189
190
191def show_quota_warning(int_bytes_used, int_bytes_total):
192 """Return True if the user should be warn about the remaining quota."""
193 available = (int_bytes_total - int_bytes_used)
194 free_threshold = (int_bytes_total == FREE_ACCOUNT_SIZE and
195 available <= QUOTA_THRESHOLD_ACCOUNTS['free'])
196 payed_threshold = (int_bytes_total > FREE_ACCOUNT_SIZE and
197 available <= QUOTA_THRESHOLD_ACCOUNTS['pay'])
198
199 return free_threshold or payed_threshold
187200
=== modified file 'ubuntuone/controlpanel/gui/qt/controlpanel.py'
--- ubuntuone/controlpanel/gui/qt/controlpanel.py 2011-09-23 15:05:27 +0000
+++ ubuntuone/controlpanel/gui/qt/controlpanel.py 2012-02-21 23:16:17 +0000
@@ -1,9 +1,6 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
22
3# Authors: Alejandro J. Cura <alecu@canonical.com>3# Copyright 2012 Canonical Ltd.
4# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
5#
6# Copyright 2011 Canonical Ltd.
7#4#
8# This program is free software: you can redistribute it and/or modify it5# This program is free software: you can redistribute it and/or modify it
9# under the terms of the GNU General Public License version 3, as published6# under the terms of the GNU General Public License version 3, as published
@@ -28,12 +25,12 @@
28from ubuntuone.controlpanel.logger import setup_logging, log_call25from ubuntuone.controlpanel.logger import setup_logging, log_call
29from ubuntuone.controlpanel.gui import (26from ubuntuone.controlpanel.gui import (
30 humanize,27 humanize,
28 show_quota_warning,
31 EDIT_SERVICES_LINK,29 EDIT_SERVICES_LINK,
32 FACEBOOK_LINK,30 FACEBOOK_LINK,
33 GET_SUPPORT_LINK,31 GET_SUPPORT_LINK,
34 GREETING,32 GREETING,
35 PERCENTAGE_LABEL,33 PERCENTAGE_LABEL,
36 QUOTA_THRESHOLD,
37 TWITTER_LINK,34 TWITTER_LINK,
38 USAGE_LABEL,35 USAGE_LABEL,
39)36)
@@ -105,27 +102,19 @@
105 total = int(info['quota_total'])102 total = int(info['quota_total'])
106 percentage_value = ((used / total) * 100)103 percentage_value = ((used / total) * 100)
107 percentage = {'percentage': PERCENTAGE_STYLE % percentage_value}104 percentage = {'percentage': PERCENTAGE_STYLE % percentage_value}
105 show_warning = show_quota_warning(used, total)
108 data = {'used': humanize(used), 'total': humanize(total)}106 data = {'used': humanize(used), 'total': humanize(total)}
109 self.ui.percentage_usage_label.setText(PERCENTAGE_LABEL % percentage)107 self.ui.percentage_usage_label.setText(PERCENTAGE_LABEL % percentage)
110 self.ui.quota_usage_label.setText(USAGE_LABEL % data)108 self.ui.quota_usage_label.setText(USAGE_LABEL % data)
111 self._update_quota({'percentage': percentage_value})109 self._update_quota(show_warning)
112110
113 @log_call(logger.debug)111 @log_call(logger.debug)
114 def _update_quota(self, data=None):112 def _update_quota(self, show_warning=False):
115 """Update the quota info."""113 """Update the quota info."""
116 fraction = 0.0114 logger.debug('ManagementPanel: show warning in quota %r.',
117 if data is not None:115 show_warning)
118 fraction = data.get('percentage', 0.0) / 100116 self.ui.percentage_usage_label.setProperty("OverQuota", show_warning)
119 if fraction > 0 and fraction < 0.05:117 self.ui.quota_usage_label.setProperty("OverQuota", show_warning)
120 fraction = 0.05
121 else:
122 fraction = round(fraction, 2)
123
124 logger.debug('ManagementPanel: updating quota to %r.', fraction)
125 self.ui.percentage_usage_label.setProperty("OverQuota",
126 fraction >= QUOTA_THRESHOLD)
127 self.ui.quota_usage_label.setProperty("OverQuota",
128 fraction >= QUOTA_THRESHOLD)
129 self.ui.percentage_usage_label.style().unpolish(118 self.ui.percentage_usage_label.style().unpolish(
130 self.ui.percentage_usage_label)119 self.ui.percentage_usage_label)
131 self.ui.percentage_usage_label.style().polish(120 self.ui.percentage_usage_label.style().polish(
132121
=== modified file 'ubuntuone/controlpanel/gui/qt/filesyncstatus.py'
--- ubuntuone/controlpanel/gui/qt/filesyncstatus.py 2011-09-02 17:59:39 +0000
+++ ubuntuone/controlpanel/gui/qt/filesyncstatus.py 2012-02-21 23:16:17 +0000
@@ -1,8 +1,6 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2
3# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
4#2#
5# Copyright 2011 Canonical Ltd.3# Copyright 2011-2012 Canonical Ltd.
6#4#
7# This program is free software: you can redistribute it and/or modify it5# 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 published6# under the terms of the GNU General Public License version 3, as published
@@ -44,6 +42,8 @@
44 FILE_SYNC_STOP_TOOLTIP,42 FILE_SYNC_STOP_TOOLTIP,
45 FILE_SYNC_STOPPED,43 FILE_SYNC_STOPPED,
46 FILE_SYNC_SYNCING,44 FILE_SYNC_SYNCING,
45 LOADING,
46 PLEASE_WAIT,
47)47)
48from ubuntuone.controlpanel.gui.qt import pixmap_from_name48from ubuntuone.controlpanel.gui.qt import pixmap_from_name
49from ubuntuone.controlpanel.gui.qt.ui import filesyncstatus_ui49from ubuntuone.controlpanel.gui.qt.ui import filesyncstatus_ui
@@ -186,6 +186,15 @@
186 """Button was clicked, act accordingly to the label."""186 """Button was clicked, act accordingly to the label."""
187 self.ui.sync_status_button.setEnabled(False)187 self.ui.sync_status_button.setEnabled(False)
188 if self._backend_method is not None:188 if self._backend_method is not None:
189 self.ui.sync_status_label.setText(LOADING)
190 self.ui.sync_status_button.setText(PLEASE_WAIT)
191 pixmap = pixmap_from_name('sync_status_loading')
192 self.ui.sync_status_icon.setPixmap(pixmap)
193 self.ui.sync_status_button.setProperty("secondary", True)
194 self.ui.sync_status_button.style().unpolish(
195 self.ui.sync_status_button)
196 self.ui.sync_status_button.style().polish(
197 self.ui.sync_status_button)
189 self._backend_method()198 self._backend_method()
190 else:199 else:
191 logger.error('on_sync_status_button_clicked: backend method is '200 logger.error('on_sync_status_button_clicked: backend method is '
192201
=== modified file 'ubuntuone/controlpanel/gui/qt/gui.py'
--- ubuntuone/controlpanel/gui/qt/gui.py 2012-02-07 13:54:46 +0000
+++ ubuntuone/controlpanel/gui/qt/gui.py 2012-02-21 23:16:17 +0000
@@ -1,8 +1,6 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2
3# Authors: Alejandro J. Cura <alecu@canonical.com>
4#2#
5# Copyright 2011 Canonical Ltd.3# Copyright 2011-2012 Canonical Ltd.
6#4#
7# This program is free software: you can redistribute it and/or modify it5# 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 published6# under the terms of the GNU General Public License version 3, as published
@@ -18,8 +16,7 @@
1816
19"""The user interface for the control panel for Ubuntu One."""17"""The user interface for the control panel for Ubuntu One."""
2018
2119from PyQt4 import QtGui, QtCore
22from PyQt4 import QtGui
2320
24from ubuntuone.controlpanel.gui.qt.systray import TrayIcon21from ubuntuone.controlpanel.gui.qt.systray import TrayIcon
25from ubuntuone.controlpanel.gui.qt.ui import mainwindow_ui22from ubuntuone.controlpanel.gui.qt.ui import mainwindow_ui
@@ -60,6 +57,11 @@
60 window = MainWindow()57 window = MainWindow()
61 else:58 else:
62 window = MainWindow(close_callback=close_callback)59 window = MainWindow(close_callback=close_callback)
60 app = QtGui.QApplication.instance()
61 style = QtGui.QStyle.alignedRect(
62 QtCore.Qt.LeftToRight, QtCore.Qt.AlignCenter,
63 window.size(), app.desktop().availableGeometry())
64 window.setGeometry(style)
63 window.show()65 window.show()
64 else:66 else:
65 window = None67 window = None
6668
=== modified file 'ubuntuone/controlpanel/gui/qt/tests/__init__.py'
--- ubuntuone/controlpanel/gui/qt/tests/__init__.py 2012-02-06 15:23:27 +0000
+++ ubuntuone/controlpanel/gui/qt/tests/__init__.py 2012-02-21 23:16:17 +0000
@@ -233,6 +233,73 @@
233 # pylint: enable=C0103233 # pylint: enable=C0103
234234
235235
236class FakePageUiStyle(object):
237 """Fake the page."""
238
239 def __init__(self):
240 self.ui = self
241 self.properties = {}
242 super(FakePageUiStyle, self).__init__()
243
244 def wizard(self):
245 """Use itself as a fake wizard, too."""
246 return self
247
248 def text(self):
249 """Return text."""
250 return self.properties.get('text', '')
251
252 # setText, setEnabled are inherited
253 # pylint: disable=C0103
254 def setText(self, text):
255 """Save text."""
256 self.properties['text'] = text
257
258 def setEnabled(self, value):
259 """Fake setEnabled."""
260 self.properties['enabled'] = value
261
262 def enabled(self):
263 """Fake enabled."""
264 return self.properties.get('enabled', False)
265
266 def isEnabled(self):
267 """Fake isEnabled."""
268 return self.properties.get('enabled', False)
269
270 def setProperty(self, key, val):
271 """Fake setProperty to restyle some widget."""
272 self.properties[key] = val
273
274 def property(self, key):
275 """Fake property from widget style."""
276 return self.properties.get(key, False)
277
278 def setDefault(self, val):
279 """Fake button setDefault."""
280 self.properties['default'] = val
281
282 def style(self):
283 """Fake style."""
284 return self
285
286 def unpolish(self, *args):
287 """Fake unpolish."""
288 self.properties['unpolish'] = len(args) > 0
289
290 def polish(self, *args):
291 """Fake polish."""
292 self.properties['polish'] = len(args) > 0
293
294 def setVisible(self, val):
295 """Fake setVisible from Qt."""
296 self.properties['visible'] = val
297
298 def isVisible(self):
299 """Fake isVisible from Qt."""
300 return self.properties['visible']
301
302
236class BaseTestCase(TestCase):303class BaseTestCase(TestCase):
237 """Base Test Case."""304 """Base Test Case."""
238305
239306
=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py'
--- ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py 2011-09-12 20:17:37 +0000
+++ ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py 2012-02-21 23:16:17 +0000
@@ -126,9 +126,8 @@
126126
127 def test_update_over_quota(self):127 def test_update_over_quota(self):
128 """Check the labels state when the user exceed the quota."""128 """Check the labels state when the user exceed the quota."""
129 percentage_value = 100
130 # pylint: disable=W0212129 # pylint: disable=W0212
131 self.ui._update_quota({'percentage': percentage_value})130 self.ui._update_quota(True)
132 # pylint: enable=W0212131 # pylint: enable=W0212
133132
134 self.assertTrue(133 self.assertTrue(
@@ -138,9 +137,8 @@
138137
139 def test_update_quota_in_range(self):138 def test_update_quota_in_range(self):
140 """Check the labels state when the quota is under the threshold."""139 """Check the labels state when the quota is under the threshold."""
141 percentage_value = 50
142 # pylint: disable=W0212140 # pylint: disable=W0212
143 self.ui._update_quota({'percentage': percentage_value})141 self.ui._update_quota(False)
144 # pylint: enable=W0212142 # pylint: enable=W0212
145143
146 self.assertFalse(144 self.assertFalse(
147145
=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_filesyncstatus.py'
--- ubuntuone/controlpanel/gui/qt/tests/test_filesyncstatus.py 2011-10-28 08:19:20 +0000
+++ ubuntuone/controlpanel/gui/qt/tests/test_filesyncstatus.py 2012-02-21 23:16:17 +0000
@@ -21,7 +21,14 @@
21from twisted.internet import defer21from twisted.internet import defer
2222
23from ubuntuone.controlpanel.gui.qt import filesyncstatus as gui23from ubuntuone.controlpanel.gui.qt import filesyncstatus as gui
24from ubuntuone.controlpanel.gui.qt.tests import BaseTestCase24from ubuntuone.controlpanel.gui.qt.tests import (
25 BaseTestCase,
26 FakePageUiStyle,
27)
28from ubuntuone.controlpanel.gui import (
29 LOADING,
30 PLEASE_WAIT,
31)
2532
26backend = gui.backend # pylint: disable=C010333backend = gui.backend # pylint: disable=C0103
2734
@@ -171,3 +178,24 @@
171 action=gui.FILE_SYNC_RESTART,178 action=gui.FILE_SYNC_RESTART,
172 callback='restart_files',179 callback='restart_files',
173 tooltip=gui.FILE_SYNC_RESTART_TOOLTIP)180 tooltip=gui.FILE_SYNC_RESTART_TOOLTIP)
181
182 def test_on_sync_status_button_clicked(self):
183 """Check the labels and icon when the button is pressed."""
184 # Ensure the _backend_method is not None to execute the first
185 # part of the If.
186 self.ui._backend_method = lambda: 'Not None'
187 self.patch(self.ui.ui, "sync_status_button", FakePageUiStyle())
188 # Simulate the click event
189 self.ui.on_sync_status_button_clicked()
190 self.assertFalse(self.ui.ui.sync_status_button.isEnabled())
191 self.assertTrue(self.ui.ui.sync_status_button.property("secondary"))
192 actual_text = self.ui.ui.sync_status_label.text()
193 self.assertEqual(actual_text, LOADING)
194 self.assertEqual(self.ui.ui.sync_status_button.text(), PLEASE_WAIT)
195 actual_icon = self.ui.ui.sync_status_icon.pixmap()
196 expected_icon = gui.pixmap_from_name('sync_status_loading')
197 self.assertEqualPixmaps(expected_icon, actual_icon)
198 self.assertTrue(
199 self.ui.ui.sync_status_button.properties.get('unpolish', True))
200 self.assertTrue(
201 self.ui.ui.sync_status_button.properties.get('polish', True))
174202
=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_start.py'
--- ubuntuone/controlpanel/gui/qt/tests/test_start.py 2012-02-07 13:54:46 +0000
+++ ubuntuone/controlpanel/gui/qt/tests/test_start.py 2012-02-21 23:16:17 +0000
@@ -28,9 +28,12 @@
2828
29 """A fake thing."""29 """A fake thing."""
3030
31 shown = False
32 size = lambda *a: gui.QtCore.QSize(123456, 654321)
33 style = None
34
31 def __init__(self):35 def __init__(self):
32 self.args = []36 self.args = []
33 self.shown = False
3437
35 def __call__(self, *args, **kwargs):38 def __call__(self, *args, **kwargs):
36 self.args.append((args, kwargs))39 self.args.append((args, kwargs))
@@ -40,6 +43,13 @@
40 """Show."""43 """Show."""
41 self.shown = True44 self.shown = True
4245
46 # Invalid name "setGeometry"
47 # pylint: disable=C0103
48
49 def setGeometry(self, style):
50 """Save the new geometry."""
51 self.style = style
52
4353
44class StartTestCase(TestCase):54class StartTestCase(TestCase):
45 """Test the qt control panel."""55 """Test the qt control panel."""
@@ -87,3 +97,12 @@
87 kwargs = {'close_callback': self.close_cb, 'window': None}97 kwargs = {'close_callback': self.close_cb, 'window': None}
88 self.assertEqual(self.tray_icon.args, [((), kwargs)])98 self.assertEqual(self.tray_icon.args, [((), kwargs)])
89 self.assertEqual(self.main_window.args, [])99 self.assertEqual(self.main_window.args, [])
100
101 def test_center_window(self):
102 """The main window should be centered."""
103 gui.start(close_callback=self.close_cb)
104 app = gui.QtGui.QApplication.instance()
105 expected = gui.QtGui.QStyle.alignedRect(gui.QtCore.Qt.LeftToRight,
106 gui.QtCore.Qt.AlignCenter, self.main_window.size(),
107 app.desktop().availableGeometry())
108 self.assertEqual(self.main_window.style, expected)
90109
=== added file 'ubuntuone/controlpanel/gui/tests/test_show_quota_warning.py'
--- ubuntuone/controlpanel/gui/tests/test_show_quota_warning.py 1970-01-01 00:00:00 +0000
+++ ubuntuone/controlpanel/gui/tests/test_show_quota_warning.py 2012-02-21 23:16:17 +0000
@@ -0,0 +1,75 @@
1# -*- coding: utf-8 -*-
2
3# Copyright 2012 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranties of
11# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12# PURPOSE. See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program. If not, see <http://www.gnu.org/licenses/>.
16
17"""Tests for the show_quota_warning function."""
18
19from ubuntuone.controlpanel.tests import TestCase
20from ubuntuone.controlpanel.gui import show_quota_warning
21
22
23GB5 = 5368709120 # 5 Gb
24GB25 = 26843545600 # 25 Gb
25
26
27class QuotaWarningTestCase(TestCase):
28
29 """Test cases for the humanize function."""
30
31 def test_quota_warning_with_used_0_free_account(self):
32 """Check the return value for show_quota_warning with 0 bytes used."""
33 self.assertFalse(show_quota_warning(0, GB5))
34
35 def test_quota_warning_with_free_account_used_medium(self):
36 """Check the return value for show_quota_warning with 2.5 gb used."""
37 used = 2.5 * (1024 ** 3) # 2.5 Gb
38 self.assertFalse(show_quota_warning(used, GB5))
39
40 def test_quota_warning_with_free_account_used_almost_full(self):
41 """Check the return value for show_quota_warning with 4.5 gb used."""
42 # For free accounts the warning should be activate when the user
43 # has equal or less than 500 mb remaining
44 used = 4.5 * (1024 ** 3) # 4.5 Gb
45 self.assertTrue(show_quota_warning(used, GB5))
46
47 def test_quota_warning_with_free_account_used_full(self):
48 """Check the return value for show_quota_warning with 5 gb used."""
49 # For free accounts the warning should be activate when the user
50 # has equal or less than 500 mb remaining
51 used = 5.0 * (1024 ** 3) # 5.0 Gb
52 self.assertTrue(show_quota_warning(used, GB5))
53
54 def test_quota_warning_with_used_0_pay_account(self):
55 """Check the return value for show_quota_warning with 0 bytes used."""
56 self.assertFalse(show_quota_warning(0, GB25))
57
58 def test_quota_warning_with_pay_account_used_medium(self):
59 """Check the return value for show_quota_warning with 12.5 gb used."""
60 used = 12.5 * (1024 ** 3) # 12.5 Gb
61 self.assertFalse(show_quota_warning(used, GB25))
62
63 def test_quota_warning_with_pay_account_used_almost_full(self):
64 """Check the return value for show_quota_warning with 22 gb used."""
65 # For pay accounts the warning should be activate when the user
66 # has equal or less than 3 Gb remaining
67 used = 22 * (1024 ** 3) # 22 Gb
68 self.assertTrue(show_quota_warning(used, GB25))
69
70 def test_quota_warning_with_pay_account_used_full(self):
71 """Check the return value for show_quota_warning with 25 gb used."""
72 # For free accounts the warning should be activate when the user
73 # has equal or less than 3 gb remaining
74 used = 25 * (1024 ** 3) # 25 Gb
75 self.assertTrue(show_quota_warning(used, GB25))

Subscribers

People subscribed via source and target branches