Merge lp:~mvo/software-center/lp1045826 into lp:software-center

Proposed by Michael Vogt on 2012-09-05
Status: Merged
Merged at revision: 3151
Proposed branch: lp:~mvo/software-center/lp1045826
Merge into: lp:software-center
Diff against target: 269 lines (+115/-26)
7 files modified
softwarecenter/db/application.py (+10/-2)
softwarecenter/ui/gtk3/widgets/buttons.py (+4/-10)
tests/gtk3/test_buttons.py (+33/-0)
tests/test_database.py (+2/-1)
tests/test_dataprovider.py (+2/-1)
tests/test_testutils.py (+20/-12)
tests/utils.py (+44/-0)
To merge this branch: bzr merge lp:~mvo/software-center/lp1045826
Reviewer Review Type Date Requested Status
Gary Lasker (community) 2012-09-05 Approve on 2012-09-06
Review via email: mp+122821@code.launchpad.net

Description of the change

Fix double display of currency and cleanup around this code

To post a comment you must log in.
lp:~mvo/software-center/lp1045826 updated on 2012-09-05
3159. By Michael Vogt on 2012-09-05

tests/gtk3/test_buttons.py: fix test name

3160. By Michael Vogt on 2012-09-05

remove dead code

3161. By Michael Vogt on 2012-09-05

if there is no "raw_price" return "" as the untiy-lens is expecting this

3162. By Michael Vogt on 2012-09-05

tests/test_dataprovider.py: update test for the new price value

3163. By Michael Vogt on 2012-09-05

pyflake fixes

Gary Lasker (gary-lasker) wrote :

I verified this fixes the issue. It's very nice to have the new test_buttons.py, and the mock property helper should be very useful for us as well. Many thanks for this!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'softwarecenter/db/application.py'
--- softwarecenter/db/application.py 2012-09-04 09:13:13 +0000
+++ softwarecenter/db/application.py 2012-09-05 10:32:18 +0000
@@ -579,11 +579,18 @@
579 """ The raw price, useful for e.g. sort-by """579 """ The raw price, useful for e.g. sort-by """
580 if self._doc:580 if self._doc:
581 return self._doc.get_value(XapianValues.PRICE)581 return self._doc.get_value(XapianValues.PRICE)
582 # the unity-lens expects a "" string here for "no-price"
583 return ""
582584
583 @property585 @property
584 def price(self):586 def price(self):
585 """ The price and the currency ready to display to the user """587 """ The price and the currency ready to display to the user
588 or "Free" is its a libre or gratis app
589 """
586 raw_price = self.raw_price590 raw_price = self.raw_price
591 if raw_price == '0.00':
592 # TRANSLATORS: Free here means Gratis
593 return _("Free")
587 currency = self.currency594 currency = self.currency
588 if raw_price and currency:595 if raw_price and currency:
589 # FIXME: need to determine the currency dynamically once we can596 # FIXME: need to determine the currency dynamically once we can
@@ -597,7 +604,8 @@
597 # to format them here differently too, e.g.604 # to format them here differently too, e.g.
598 # "US$ 1" but "1EUR"605 # "US$ 1" but "1EUR"
599 return "%s %s" % (currency, raw_price)606 return "%s %s" % (currency, raw_price)
600 return ""607 # TRANSLATORS: Free here means Libre
608 return _("Free")
601609
602 @property610 @property
603 def supported_distros(self):611 def supported_distros(self):
604612
=== modified file 'softwarecenter/ui/gtk3/widgets/buttons.py'
--- softwarecenter/ui/gtk3/widgets/buttons.py 2012-05-30 18:39:55 +0000
+++ softwarecenter/ui/gtk3/widgets/buttons.py 2012-09-05 10:32:18 +0000
@@ -22,7 +22,6 @@
22from gettext import gettext as _22from gettext import gettext as _
2323
24from softwarecenter.backend import get_install_backend24from softwarecenter.backend import get_install_backend
25from softwarecenter.db.application import AppDetails
26from softwarecenter.enums import Icons25from softwarecenter.enums import Icons
27from softwarecenter.ui.gtk3.em import StockEms, em26from softwarecenter.ui.gtk3.em import StockEms, em
28from softwarecenter.ui.gtk3.drawing import darken27from softwarecenter.ui.gtk3.drawing import darken
@@ -38,6 +37,8 @@
38 image = image.set_from_pixbuf(icon.get_pixbuf())37 image = image.set_from_pixbuf(icon.get_pixbuf())
39 elif isinstance(icon, str):38 elif isinstance(icon, str):
40 image = image.set_from_icon_name(icon, icon_size)39 image = image.set_from_icon_name(icon, icon_size)
40 elif icon is None:
41 image = Gtk.Image()
41 else:42 else:
42 msg = "Acceptable icon values: None, GdkPixbuf, GtkImage or str"43 msg = "Acceptable icon values: None, GdkPixbuf, GtkImage or str"
43 raise TypeError(msg)44 raise TypeError(msg)
@@ -246,15 +247,8 @@
246 _global_featured_tile_width = max(_global_featured_tile_width,247 _global_featured_tile_width = max(_global_featured_tile_width,
247 req_width)248 req_width)
248249
249 details = AppDetails(db=helper.db, doc=doc)250 # TRANSLATORS: Free here means Gratis
250 # TRANSLATORS: Free here means Gratis251 price = helper.get_display_price(doc)
251 price = details.price or _("Free")
252 if price == '0.00':
253 # TRANSLATORS: Free here means Gratis
254 price = _("Free")
255 # TRANSLATORS: Free here means Gratis
256 if price != _("Free"):
257 price = 'US$ ' + price
258 self.price = Gtk.Label.new(252 self.price = Gtk.Label.new(
259 '<span font_desc="%i">%s</span>' % (em(0.6), price))253 '<span font_desc="%i">%s</span>' % (em(0.6), price))
260 self.price.set_use_markup(True)254 self.price.set_use_markup(True)
261255
=== added file 'tests/gtk3/test_buttons.py'
--- tests/gtk3/test_buttons.py 1970-01-01 00:00:00 +0000
+++ tests/gtk3/test_buttons.py 2012-09-05 10:32:18 +0000
@@ -0,0 +1,33 @@
1import unittest
2
3from tests.utils import (
4 get_mock_app_properties_helper,
5 setup_test_env,
6)
7setup_test_env()
8
9from softwarecenter.ui.gtk3.widgets.buttons import FeaturedTile
10
11
12class TestWidgets(unittest.TestCase):
13 """ basic tests for the TileButton widget """
14
15 def test_feature_tile_dup_symbol(self):
16 values = {'display_price': 'US$ 1.00' }
17 mock_property_helper = get_mock_app_properties_helper(values)
18 # we don't really need a "doc" on second input as we mock the helper
19 button = FeaturedTile(mock_property_helper, None)
20 self.assertEqual(
21 button.price.get_label(), '<span font_desc="10">US$ 1.00</span>')
22
23 def test_free_price(self):
24 values = {'display_price': "Free"}
25 mock_property_helper = get_mock_app_properties_helper(values)
26 # we don't really need a "doc" on second input as we mock the helper
27 button = FeaturedTile(mock_property_helper, None)
28 self.assertEqual(
29 button.price.get_label(), '<span font_desc="10">Free</span>')
30
31
32if __name__ == "__main__":
33 unittest.main()
034
=== modified file 'tests/test_database.py'
--- tests/test_database.py 2012-08-28 13:07:22 +0000
+++ tests/test_database.py 2012-09-05 10:32:18 +0000
@@ -266,7 +266,8 @@
266 "http://screenshots.ubuntu.com/thumbnail-with-version/software-center/[\d.]+",266 "http://screenshots.ubuntu.com/thumbnail-with-version/software-center/[\d.]+",
267 appdetails.thumbnail))267 appdetails.thumbnail))
268 # FIXME: add document that has a price268 # FIXME: add document that has a price
269 self.assertEqual(appdetails.price, None)269 self.assertEqual(appdetails.price, "Free")
270 self.assertEqual(appdetails.raw_price, "")
270 self.assertEqual(appdetails.license, "Open source")271 self.assertEqual(appdetails.license, "Open source")
271 # test lazy history loading for installation date272 # test lazy history loading for installation date
272 self.ensure_installation_date_and_lazy_history_loading(appdetails)273 self.ensure_installation_date_and_lazy_history_loading(appdetails)
273274
=== modified file 'tests/test_dataprovider.py'
--- tests/test_dataprovider.py 2012-09-04 09:13:13 +0000
+++ tests/test_dataprovider.py 2012-09-05 10:32:18 +0000
@@ -34,7 +34,8 @@
34 self.assertEqual(result["icon"], "accessories-text-editor")34 self.assertEqual(result["icon"], "accessories-text-editor")
35 self.assertEqual(result["name"], "gedit")35 self.assertEqual(result["name"], "gedit")
36 self.assertEqual(result["pkgname"], "gedit")36 self.assertEqual(result["pkgname"], "gedit")
37 self.assertEqual(result["price"], "")37 self.assertEqual(result["price"], "Free")
38 self.assertEqual(result["raw_price"], "")
3839
3940
40if __name__ == "__main__":41if __name__ == "__main__":
4142
=== modified file 'tests/test_testutils.py'
--- tests/test_testutils.py 2012-05-30 18:39:55 +0000
+++ tests/test_testutils.py 2012-09-05 10:32:18 +0000
@@ -1,13 +1,13 @@
1import unittest1import unittest
22
3import dbus3import dbus
4import time
5from gi.repository import GObject
64
7from tests.utils import (5from tests.utils import (
6 do_events_with_sleep,
8 setup_test_env,7 setup_test_env,
9 start_dummy_backend,8 start_dummy_backend,
10 stop_dummy_backend,9 stop_dummy_backend,
10 get_mock_app_properties_helper,
11)11)
12setup_test_env()12setup_test_env()
1313
@@ -15,7 +15,7 @@
15from softwarecenter.backend.installbackend_impl.aptd import get_dbus_bus15from softwarecenter.backend.installbackend_impl.aptd import get_dbus_bus
1616
1717
18class TestTestUtils(unittest.TestCase):18class DummyBackendTestUtilsTestCase(unittest.TestCase):
1919
20 def setUp(self):20 def setUp(self):
21 start_dummy_backend()21 start_dummy_backend()
@@ -32,7 +32,7 @@
32 # get names and ...32 # get names and ...
33 names = bus.list_names()33 names = bus.list_names()
34 # ensure we have the following:34 # ensure we have the following:
35 # org.freedesktop.DBus, 35 # org.freedesktop.DBus,
36 # org.freedesktop.PolicyKit136 # org.freedesktop.PolicyKit1
37 # org.debian.apt37 # org.debian.apt
38 # (and :1.0, :1.1, :1.2)38 # (and :1.0, :1.1, :1.2)
@@ -42,14 +42,22 @@
42 from softwarecenter.backend import get_install_backend42 from softwarecenter.backend import get_install_backend
43 backend = get_install_backend()43 backend = get_install_backend()
44 backend.install(Application("2vcard", ""), iconname="")44 backend.install(Application("2vcard", ""), iconname="")
45 self._p()45 do_events_with_sleep()
4646
47 def _p(self):47
48 context = GObject.main_context_default()48class TestUtilsTestCase(unittest.TestCase):
49 for i in range(10):49
50 while context.pending():50 def test_app_properties_helper_mock_with_defaults(self):
51 context.iteration()51 app_properties_helper = get_mock_app_properties_helper()
52 time.sleep(0.1)52 self.assertEqual(
53 app_properties_helper.get_pkgname(None), "apkg")
54
55 def test_app_properties_helper_mock_with_custom_values(self):
56 my_defaults = {'pkgname': 'diemoldau',
57 }
58 app_properties_helper = get_mock_app_properties_helper(my_defaults)
59 self.assertEqual(
60 app_properties_helper.get_pkgname(None), "diemoldau")
5361
5462
55if __name__ == "__main__":63if __name__ == "__main__":
5664
=== modified file 'tests/utils.py'
--- tests/utils.py 2012-08-23 14:37:28 +0000
+++ tests/utils.py 2012-09-05 10:32:18 +0000
@@ -43,6 +43,7 @@
43 get_viewmanager,43 get_viewmanager,
44)44)
45from softwarecenter.ui.gtk3.utils import get_sc_icon_theme45from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
46from softwarecenter.ui.gtk3.models.appstore2 import AppPropertiesHelper
46from softwarecenter.utils import get_uuid47from softwarecenter.utils import get_uuid
47from softwarecenter.db.update import update_from_app_install_data48from softwarecenter.db.update import update_from_app_install_data
4849
@@ -196,6 +197,49 @@
196 return mock_options197 return mock_options
197198
198199
200def get_mock_app_properties_helper(override_values={}):
201 """Return a mock suitable as a AppPropertiesHelper.
202
203 It can be passed a "values" dict for customization. But it will
204 return always the same data for each "doc" document (it will
205 not even look at doc)
206 """
207 # provide some defaults
208 values = {
209 'appname': 'some Appname',
210 'pkgname': 'apkg',
211 'categories': 'cat1,cat2,lolcat',
212 'ratings_average': 3.5,
213 'ratings_total': 12,
214 'icon': None,
215 'display_price': '',
216 }
217 # override
218 values.update(override_values)
219 # do it
220 mock_property_helper = Mock(AppPropertiesHelper)
221 mock_property_helper.get_appname.return_value = values["appname"]
222 mock_property_helper.get_pkgname.return_value = values["pkgname"]
223 mock_property_helper.get_categories.return_value = values["categories"]
224 mock_property_helper.get_display_price.return_value = values[
225 "display_price"]
226
227 mock_property_helper.db = Mock()
228 mock_property_helper.db._aptcache = FakedCache()
229 mock_property_helper.db.get_pkgname.return_value = values["pkgname"]
230 mock_property_helper.db.get_appname.return_value = values["appname"]
231
232 mock_ratings = Mock()
233 mock_ratings.ratings_average = values["ratings_average"]
234 mock_ratings.ratings_total = values["ratings_total"]
235
236 mock_property_helper.get_review_stats.return_value = mock_ratings
237 mock_property_helper.get_icon_at_size.return_value = values["icon"]
238 mock_property_helper.icons = Mock()
239 mock_property_helper.icons.load_icon.return_value = values["icon"]
240 return mock_property_helper
241
242
199def setup_test_env():243def setup_test_env():
200 """ Setup environment suitable for running the test/* code in a checkout.244 """ Setup environment suitable for running the test/* code in a checkout.
201 This includes PYTHONPATH, sys.path and softwarecenter.paths.datadir.245 This includes PYTHONPATH, sys.path and softwarecenter.paths.datadir.

Subscribers

People subscribed via source and target branches