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

Proposed by Diego Sarmentero
Status: Merged
Approved by: Natalia Bidart
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 (community) Approve
Roberto Alsina (community) Approve
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.
Revision history for this message
Roberto Alsina (ralsina) wrote :

I like this better.

review: Approve
256. By Manuel de la Peña

Forward extra params to u1trial.

Revision history for this message
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
Revision history for this message
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

- 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

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

259. By Natalia Bidart

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

260. By Diego Sarmentero

Conflict resolved

Revision history for this message
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

reverting red constant to unicode

262. By Diego Sarmentero

Improving quota sizes readability

263. By Diego Sarmentero

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

264. By Diego Sarmentero

Removing duplicated quota_threshold

Revision history for this message
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
=== modified file 'ubuntuone/controlpanel/gui/__init__.py'
--- ubuntuone/controlpanel/gui/__init__.py 2012-02-17 12:01:56 +0000
+++ ubuntuone/controlpanel/gui/__init__.py 2012-02-17 14:55:36 +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
@@ -185,3 +186,14 @@
185 str_bytes = str_bytes.rstrip('0')186 str_bytes = str_bytes.rstrip('0')
186 str_bytes = str_bytes.rstrip('.')187 str_bytes = str_bytes.rstrip('.')
187 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
188200
=== 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-17 14:55:36 +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/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-17 14:55:36 +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
=== 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-17 14:55:36 +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