Merge lp:~diegosarmentero/ubuntuone-control-panel/quota-warning into lp:ubuntuone-control-panel

Proposed by Diego Sarmentero on 2012-01-31
Status: Merged
Approved by: Natalia Bidart on 2012-02-17
Approved revision: 264
Merged at revision: 262
Proposed branch: lp:~diegosarmentero/ubuntuone-control-panel/quota-warning
Merge into: lp:ubuntuone-control-panel
Diff against target: 214 lines (+102/-28)
4 files modified
ubuntuone/controlpanel/gui/__init__.py (+16/-4)
ubuntuone/controlpanel/gui/qt/controlpanel.py (+9/-20)
ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py (+2/-4)
ubuntuone/controlpanel/gui/tests/test_show_quota_warning.py (+75/-0)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntuone-control-panel/quota-warning
Reviewer Review Type Date Requested Status
Natalia Bidart Approve on 2012-02-17
Roberto Alsina (community) 2012-01-31 Approve on 2012-02-01
Review via email: mp+90946@code.launchpad.net

Commit Message

- Control Panel shows quota in red with more accuracy depending on the free space (LP: #901314).

Description of the Change

Change the actual implementation to not be based in percentage, but instead in some fix sizes.

For Free accounts:
- Show warning when the available quota is 500mb or less

For Pay accounts:
- Show warning when the available quota is 3gb or less

To post a comment you must log in.
Roberto Alsina (ralsina) wrote :

I like this better.

review: Approve
256. By Manuel de la Peña on 2012-02-01

Forward extra params to u1trial.

Natalia Bidart (nataliabidart) wrote :

Branch looks great.

Can you please do the whole quota-highlight calculation using bytes, to ease the understanding of the code?

Thanks!

review: Needs Fixing
Diego Sarmentero (diegosarmentero) wrote :

> Branch looks great.
>
> Can you please do the whole quota-highlight calculation using bytes, to ease
> the understanding of the code?
>
> Thanks!

Done!

257. By Natalia Bidart on 2012-02-07

- Avoid TypeError when fetching credentials in the Gtk OverviewPanel
   (LP: #927743).
- Run the whole test suite with a single command (LP: #927770).
- Do proper cleanup when dealing with UIs (LP: #925617).

258. By Natalia Bidart on 2012-02-08

 - Replaced custom webclient with the one from ubuntu-sso-client
   (LP: #926311).
- Removed the dependency on qt4reactor for Linux implementation.

259. By Natalia Bidart on 2012-02-10

- Install the uniqueapp module (LP: #930269).

260. By Diego Sarmentero on 2012-02-17

Conflict resolved

Natalia Bidart (nataliabidart) wrote :

The following method does not indent the multiline guard properly. I would advice something like:

def show_quota_warning(int_bytes_used, int_bytes_total):
    """Return True if the user should be warn about the remaining quota."""
    available = (int_bytes_total - int_bytes_used)
    free_threshold = (int_bytes_total == FREE_ACCOUNT_SIZE and
                      available <= QUOTA_THRESHOLD_ACCOUNTS['free'])
    payed_threshold = (int_bytes_total > FREE_ACCOUNT_SIZE and
                       available <= QUOTA_THRESHOLD_ACCOUNTS['pay'])
    return free_threshold or payed_threshold

For the constants about quota, I would change these:

1 +FREE_ACCOUNT_SIZE = 5368709120
27 +QUOTA_THRESHOLD_ACCOUNTS = {'free': 536870912, 'pay': 3221225472}

to be:

        FREE_ACCOUNT_SIZE = (BYTES**3) * 5 # 5 gigs
        QUOTA_THRESHOLD_ACCOUNTS = {'free': FREE_ACCOUNT_SIZE * 0.1, # 10% of the free account size
                                    'pay': (BYTES**3) * 3} # 3 gigs

The rest looks good!

review: Needs Fixing
261. By Diego Sarmentero on 2012-02-17

reverting red constant to unicode

262. By Diego Sarmentero on 2012-02-17

Improving quota sizes readability

263. By Diego Sarmentero on 2012-02-17

Changes in the way the boolean value is calculated in show_quota_warning.

264. By Diego Sarmentero on 2012-02-17

Removing duplicated quota_threshold

Natalia Bidart (nataliabidart) wrote :

Looks great!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/controlpanel/gui/__init__.py'
2--- ubuntuone/controlpanel/gui/__init__.py 2012-02-17 12:01:56 +0000
3+++ ubuntuone/controlpanel/gui/__init__.py 2012-02-17 14:55:36 +0000
4@@ -1,9 +1,6 @@
5 # -*- coding: utf-8 -*-
6
7-# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
8-# Authors: Alejandro J. Cura <alecu@canonical.com>
9-#
10-# Copyright 2011 Canonical Ltd.
11+# Copyright 2011-2012 Canonical Ltd.
12 #
13 # This program is free software: you can redistribute it and/or modify it
14 # under the terms of the GNU General Public License version 3, as published
15@@ -29,10 +26,14 @@
16
17 ERROR_COLOR = u'red'
18 KILOBYTES = 1024
19+FREE_ACCOUNT_SIZE = (KILOBYTES ** 3) * 5 # 5 gigs
20 NO_OP = lambda *a, **kw: None
21 # http://design.canonical.com/the-toolkit/ubuntu-logo-and-circle-of-friends/
22 ORANGE = u'#DD4814'
23 QUOTA_THRESHOLD = 0.95
24+QUOTA_THRESHOLD_ACCOUNTS = {
25+ 'free': FREE_ACCOUNT_SIZE * 0.1, # 10% of the free account size
26+ 'pay': (KILOBYTES ** 3) * 3} # 3 gigs
27 SHARES_MIN_SIZE_FULL = 1048576
28 SUCCESS_COLOR = u'green'
29
30@@ -185,3 +186,14 @@
31 str_bytes = str_bytes.rstrip('0')
32 str_bytes = str_bytes.rstrip('.')
33 return '%s %s' % (str_bytes, units[unit])
34+
35+
36+def show_quota_warning(int_bytes_used, int_bytes_total):
37+ """Return True if the user should be warn about the remaining quota."""
38+ available = (int_bytes_total - int_bytes_used)
39+ free_threshold = (int_bytes_total == FREE_ACCOUNT_SIZE and
40+ available <= QUOTA_THRESHOLD_ACCOUNTS['free'])
41+ payed_threshold = (int_bytes_total > FREE_ACCOUNT_SIZE and
42+ available <= QUOTA_THRESHOLD_ACCOUNTS['pay'])
43+
44+ return free_threshold or payed_threshold
45
46=== modified file 'ubuntuone/controlpanel/gui/qt/controlpanel.py'
47--- ubuntuone/controlpanel/gui/qt/controlpanel.py 2011-09-23 15:05:27 +0000
48+++ ubuntuone/controlpanel/gui/qt/controlpanel.py 2012-02-17 14:55:36 +0000
49@@ -1,9 +1,6 @@
50 # -*- coding: utf-8 -*-
51
52-# Authors: Alejandro J. Cura <alecu@canonical.com>
53-# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
54-#
55-# Copyright 2011 Canonical Ltd.
56+# Copyright 2012 Canonical Ltd.
57 #
58 # This program is free software: you can redistribute it and/or modify it
59 # under the terms of the GNU General Public License version 3, as published
60@@ -28,12 +25,12 @@
61 from ubuntuone.controlpanel.logger import setup_logging, log_call
62 from ubuntuone.controlpanel.gui import (
63 humanize,
64+ show_quota_warning,
65 EDIT_SERVICES_LINK,
66 FACEBOOK_LINK,
67 GET_SUPPORT_LINK,
68 GREETING,
69 PERCENTAGE_LABEL,
70- QUOTA_THRESHOLD,
71 TWITTER_LINK,
72 USAGE_LABEL,
73 )
74@@ -105,27 +102,19 @@
75 total = int(info['quota_total'])
76 percentage_value = ((used / total) * 100)
77 percentage = {'percentage': PERCENTAGE_STYLE % percentage_value}
78+ show_warning = show_quota_warning(used, total)
79 data = {'used': humanize(used), 'total': humanize(total)}
80 self.ui.percentage_usage_label.setText(PERCENTAGE_LABEL % percentage)
81 self.ui.quota_usage_label.setText(USAGE_LABEL % data)
82- self._update_quota({'percentage': percentage_value})
83+ self._update_quota(show_warning)
84
85 @log_call(logger.debug)
86- def _update_quota(self, data=None):
87+ def _update_quota(self, show_warning=False):
88 """Update the quota info."""
89- fraction = 0.0
90- if data is not None:
91- fraction = data.get('percentage', 0.0) / 100
92- if fraction > 0 and fraction < 0.05:
93- fraction = 0.05
94- else:
95- fraction = round(fraction, 2)
96-
97- logger.debug('ManagementPanel: updating quota to %r.', fraction)
98- self.ui.percentage_usage_label.setProperty("OverQuota",
99- fraction >= QUOTA_THRESHOLD)
100- self.ui.quota_usage_label.setProperty("OverQuota",
101- fraction >= QUOTA_THRESHOLD)
102+ logger.debug('ManagementPanel: show warning in quota %r.',
103+ show_warning)
104+ self.ui.percentage_usage_label.setProperty("OverQuota", show_warning)
105+ self.ui.quota_usage_label.setProperty("OverQuota", show_warning)
106 self.ui.percentage_usage_label.style().unpolish(
107 self.ui.percentage_usage_label)
108 self.ui.percentage_usage_label.style().polish(
109
110=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py'
111--- ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py 2011-09-12 20:17:37 +0000
112+++ ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py 2012-02-17 14:55:36 +0000
113@@ -126,9 +126,8 @@
114
115 def test_update_over_quota(self):
116 """Check the labels state when the user exceed the quota."""
117- percentage_value = 100
118 # pylint: disable=W0212
119- self.ui._update_quota({'percentage': percentage_value})
120+ self.ui._update_quota(True)
121 # pylint: enable=W0212
122
123 self.assertTrue(
124@@ -138,9 +137,8 @@
125
126 def test_update_quota_in_range(self):
127 """Check the labels state when the quota is under the threshold."""
128- percentage_value = 50
129 # pylint: disable=W0212
130- self.ui._update_quota({'percentage': percentage_value})
131+ self.ui._update_quota(False)
132 # pylint: enable=W0212
133
134 self.assertFalse(
135
136=== added file 'ubuntuone/controlpanel/gui/tests/test_show_quota_warning.py'
137--- ubuntuone/controlpanel/gui/tests/test_show_quota_warning.py 1970-01-01 00:00:00 +0000
138+++ ubuntuone/controlpanel/gui/tests/test_show_quota_warning.py 2012-02-17 14:55:36 +0000
139@@ -0,0 +1,75 @@
140+# -*- coding: utf-8 -*-
141+
142+# Copyright 2012 Canonical Ltd.
143+#
144+# This program is free software: you can redistribute it and/or modify it
145+# under the terms of the GNU General Public License version 3, as published
146+# by the Free Software Foundation.
147+#
148+# This program is distributed in the hope that it will be useful, but
149+# WITHOUT ANY WARRANTY; without even the implied warranties of
150+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
151+# PURPOSE. See the GNU General Public License for more details.
152+#
153+# You should have received a copy of the GNU General Public License along
154+# with this program. If not, see <http://www.gnu.org/licenses/>.
155+
156+"""Tests for the show_quota_warning function."""
157+
158+from ubuntuone.controlpanel.tests import TestCase
159+from ubuntuone.controlpanel.gui import show_quota_warning
160+
161+
162+GB5 = 5368709120 # 5 Gb
163+GB25 = 26843545600 # 25 Gb
164+
165+
166+class QuotaWarningTestCase(TestCase):
167+
168+ """Test cases for the humanize function."""
169+
170+ def test_quota_warning_with_used_0_free_account(self):
171+ """Check the return value for show_quota_warning with 0 bytes used."""
172+ self.assertFalse(show_quota_warning(0, GB5))
173+
174+ def test_quota_warning_with_free_account_used_medium(self):
175+ """Check the return value for show_quota_warning with 2.5 gb used."""
176+ used = 2.5 * (1024 ** 3) # 2.5 Gb
177+ self.assertFalse(show_quota_warning(used, GB5))
178+
179+ def test_quota_warning_with_free_account_used_almost_full(self):
180+ """Check the return value for show_quota_warning with 4.5 gb used."""
181+ # For free accounts the warning should be activate when the user
182+ # has equal or less than 500 mb remaining
183+ used = 4.5 * (1024 ** 3) # 4.5 Gb
184+ self.assertTrue(show_quota_warning(used, GB5))
185+
186+ def test_quota_warning_with_free_account_used_full(self):
187+ """Check the return value for show_quota_warning with 5 gb used."""
188+ # For free accounts the warning should be activate when the user
189+ # has equal or less than 500 mb remaining
190+ used = 5.0 * (1024 ** 3) # 5.0 Gb
191+ self.assertTrue(show_quota_warning(used, GB5))
192+
193+ def test_quota_warning_with_used_0_pay_account(self):
194+ """Check the return value for show_quota_warning with 0 bytes used."""
195+ self.assertFalse(show_quota_warning(0, GB25))
196+
197+ def test_quota_warning_with_pay_account_used_medium(self):
198+ """Check the return value for show_quota_warning with 12.5 gb used."""
199+ used = 12.5 * (1024 ** 3) # 12.5 Gb
200+ self.assertFalse(show_quota_warning(used, GB25))
201+
202+ def test_quota_warning_with_pay_account_used_almost_full(self):
203+ """Check the return value for show_quota_warning with 22 gb used."""
204+ # For pay accounts the warning should be activate when the user
205+ # has equal or less than 3 Gb remaining
206+ used = 22 * (1024 ** 3) # 22 Gb
207+ self.assertTrue(show_quota_warning(used, GB25))
208+
209+ def test_quota_warning_with_pay_account_used_full(self):
210+ """Check the return value for show_quota_warning with 25 gb used."""
211+ # For free accounts the warning should be activate when the user
212+ # has equal or less than 3 gb remaining
213+ used = 25 * (1024 ** 3) # 25 Gb
214+ self.assertTrue(show_quota_warning(used, GB25))

Subscribers

People subscribed via source and target branches