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
1=== modified file 'softwarecenter/db/application.py'
2--- softwarecenter/db/application.py 2012-09-04 09:13:13 +0000
3+++ softwarecenter/db/application.py 2012-09-05 10:32:18 +0000
4@@ -579,11 +579,18 @@
5 """ The raw price, useful for e.g. sort-by """
6 if self._doc:
7 return self._doc.get_value(XapianValues.PRICE)
8+ # the unity-lens expects a "" string here for "no-price"
9+ return ""
10
11 @property
12 def price(self):
13- """ The price and the currency ready to display to the user """
14+ """ The price and the currency ready to display to the user
15+ or "Free" is its a libre or gratis app
16+ """
17 raw_price = self.raw_price
18+ if raw_price == '0.00':
19+ # TRANSLATORS: Free here means Gratis
20+ return _("Free")
21 currency = self.currency
22 if raw_price and currency:
23 # FIXME: need to determine the currency dynamically once we can
24@@ -597,7 +604,8 @@
25 # to format them here differently too, e.g.
26 # "US$ 1" but "1EUR"
27 return "%s %s" % (currency, raw_price)
28- return ""
29+ # TRANSLATORS: Free here means Libre
30+ return _("Free")
31
32 @property
33 def supported_distros(self):
34
35=== modified file 'softwarecenter/ui/gtk3/widgets/buttons.py'
36--- softwarecenter/ui/gtk3/widgets/buttons.py 2012-05-30 18:39:55 +0000
37+++ softwarecenter/ui/gtk3/widgets/buttons.py 2012-09-05 10:32:18 +0000
38@@ -22,7 +22,6 @@
39 from gettext import gettext as _
40
41 from softwarecenter.backend import get_install_backend
42-from softwarecenter.db.application import AppDetails
43 from softwarecenter.enums import Icons
44 from softwarecenter.ui.gtk3.em import StockEms, em
45 from softwarecenter.ui.gtk3.drawing import darken
46@@ -38,6 +37,8 @@
47 image = image.set_from_pixbuf(icon.get_pixbuf())
48 elif isinstance(icon, str):
49 image = image.set_from_icon_name(icon, icon_size)
50+ elif icon is None:
51+ image = Gtk.Image()
52 else:
53 msg = "Acceptable icon values: None, GdkPixbuf, GtkImage or str"
54 raise TypeError(msg)
55@@ -246,15 +247,8 @@
56 _global_featured_tile_width = max(_global_featured_tile_width,
57 req_width)
58
59- details = AppDetails(db=helper.db, doc=doc)
60- # TRANSLATORS: Free here means Gratis
61- price = details.price or _("Free")
62- if price == '0.00':
63- # TRANSLATORS: Free here means Gratis
64- price = _("Free")
65- # TRANSLATORS: Free here means Gratis
66- if price != _("Free"):
67- price = 'US$ ' + price
68+ # TRANSLATORS: Free here means Gratis
69+ price = helper.get_display_price(doc)
70 self.price = Gtk.Label.new(
71 '<span font_desc="%i">%s</span>' % (em(0.6), price))
72 self.price.set_use_markup(True)
73
74=== added file 'tests/gtk3/test_buttons.py'
75--- tests/gtk3/test_buttons.py 1970-01-01 00:00:00 +0000
76+++ tests/gtk3/test_buttons.py 2012-09-05 10:32:18 +0000
77@@ -0,0 +1,33 @@
78+import unittest
79+
80+from tests.utils import (
81+ get_mock_app_properties_helper,
82+ setup_test_env,
83+)
84+setup_test_env()
85+
86+from softwarecenter.ui.gtk3.widgets.buttons import FeaturedTile
87+
88+
89+class TestWidgets(unittest.TestCase):
90+ """ basic tests for the TileButton widget """
91+
92+ def test_feature_tile_dup_symbol(self):
93+ values = {'display_price': 'US$ 1.00' }
94+ mock_property_helper = get_mock_app_properties_helper(values)
95+ # we don't really need a "doc" on second input as we mock the helper
96+ button = FeaturedTile(mock_property_helper, None)
97+ self.assertEqual(
98+ button.price.get_label(), '<span font_desc="10">US$ 1.00</span>')
99+
100+ def test_free_price(self):
101+ values = {'display_price': "Free"}
102+ mock_property_helper = get_mock_app_properties_helper(values)
103+ # we don't really need a "doc" on second input as we mock the helper
104+ button = FeaturedTile(mock_property_helper, None)
105+ self.assertEqual(
106+ button.price.get_label(), '<span font_desc="10">Free</span>')
107+
108+
109+if __name__ == "__main__":
110+ unittest.main()
111
112=== modified file 'tests/test_database.py'
113--- tests/test_database.py 2012-08-28 13:07:22 +0000
114+++ tests/test_database.py 2012-09-05 10:32:18 +0000
115@@ -266,7 +266,8 @@
116 "http://screenshots.ubuntu.com/thumbnail-with-version/software-center/[\d.]+",
117 appdetails.thumbnail))
118 # FIXME: add document that has a price
119- self.assertEqual(appdetails.price, None)
120+ self.assertEqual(appdetails.price, "Free")
121+ self.assertEqual(appdetails.raw_price, "")
122 self.assertEqual(appdetails.license, "Open source")
123 # test lazy history loading for installation date
124 self.ensure_installation_date_and_lazy_history_loading(appdetails)
125
126=== modified file 'tests/test_dataprovider.py'
127--- tests/test_dataprovider.py 2012-09-04 09:13:13 +0000
128+++ tests/test_dataprovider.py 2012-09-05 10:32:18 +0000
129@@ -34,7 +34,8 @@
130 self.assertEqual(result["icon"], "accessories-text-editor")
131 self.assertEqual(result["name"], "gedit")
132 self.assertEqual(result["pkgname"], "gedit")
133- self.assertEqual(result["price"], "")
134+ self.assertEqual(result["price"], "Free")
135+ self.assertEqual(result["raw_price"], "")
136
137
138 if __name__ == "__main__":
139
140=== modified file 'tests/test_testutils.py'
141--- tests/test_testutils.py 2012-05-30 18:39:55 +0000
142+++ tests/test_testutils.py 2012-09-05 10:32:18 +0000
143@@ -1,13 +1,13 @@
144 import unittest
145
146 import dbus
147-import time
148-from gi.repository import GObject
149
150 from tests.utils import (
151+ do_events_with_sleep,
152 setup_test_env,
153 start_dummy_backend,
154 stop_dummy_backend,
155+ get_mock_app_properties_helper,
156 )
157 setup_test_env()
158
159@@ -15,7 +15,7 @@
160 from softwarecenter.backend.installbackend_impl.aptd import get_dbus_bus
161
162
163-class TestTestUtils(unittest.TestCase):
164+class DummyBackendTestUtilsTestCase(unittest.TestCase):
165
166 def setUp(self):
167 start_dummy_backend()
168@@ -32,7 +32,7 @@
169 # get names and ...
170 names = bus.list_names()
171 # ensure we have the following:
172- # org.freedesktop.DBus,
173+ # org.freedesktop.DBus,
174 # org.freedesktop.PolicyKit1
175 # org.debian.apt
176 # (and :1.0, :1.1, :1.2)
177@@ -42,14 +42,22 @@
178 from softwarecenter.backend import get_install_backend
179 backend = get_install_backend()
180 backend.install(Application("2vcard", ""), iconname="")
181- self._p()
182-
183- def _p(self):
184- context = GObject.main_context_default()
185- for i in range(10):
186- while context.pending():
187- context.iteration()
188- time.sleep(0.1)
189+ do_events_with_sleep()
190+
191+
192+class TestUtilsTestCase(unittest.TestCase):
193+
194+ def test_app_properties_helper_mock_with_defaults(self):
195+ app_properties_helper = get_mock_app_properties_helper()
196+ self.assertEqual(
197+ app_properties_helper.get_pkgname(None), "apkg")
198+
199+ def test_app_properties_helper_mock_with_custom_values(self):
200+ my_defaults = {'pkgname': 'diemoldau',
201+ }
202+ app_properties_helper = get_mock_app_properties_helper(my_defaults)
203+ self.assertEqual(
204+ app_properties_helper.get_pkgname(None), "diemoldau")
205
206
207 if __name__ == "__main__":
208
209=== modified file 'tests/utils.py'
210--- tests/utils.py 2012-08-23 14:37:28 +0000
211+++ tests/utils.py 2012-09-05 10:32:18 +0000
212@@ -43,6 +43,7 @@
213 get_viewmanager,
214 )
215 from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
216+from softwarecenter.ui.gtk3.models.appstore2 import AppPropertiesHelper
217 from softwarecenter.utils import get_uuid
218 from softwarecenter.db.update import update_from_app_install_data
219
220@@ -196,6 +197,49 @@
221 return mock_options
222
223
224+def get_mock_app_properties_helper(override_values={}):
225+ """Return a mock suitable as a AppPropertiesHelper.
226+
227+ It can be passed a "values" dict for customization. But it will
228+ return always the same data for each "doc" document (it will
229+ not even look at doc)
230+ """
231+ # provide some defaults
232+ values = {
233+ 'appname': 'some Appname',
234+ 'pkgname': 'apkg',
235+ 'categories': 'cat1,cat2,lolcat',
236+ 'ratings_average': 3.5,
237+ 'ratings_total': 12,
238+ 'icon': None,
239+ 'display_price': '',
240+ }
241+ # override
242+ values.update(override_values)
243+ # do it
244+ mock_property_helper = Mock(AppPropertiesHelper)
245+ mock_property_helper.get_appname.return_value = values["appname"]
246+ mock_property_helper.get_pkgname.return_value = values["pkgname"]
247+ mock_property_helper.get_categories.return_value = values["categories"]
248+ mock_property_helper.get_display_price.return_value = values[
249+ "display_price"]
250+
251+ mock_property_helper.db = Mock()
252+ mock_property_helper.db._aptcache = FakedCache()
253+ mock_property_helper.db.get_pkgname.return_value = values["pkgname"]
254+ mock_property_helper.db.get_appname.return_value = values["appname"]
255+
256+ mock_ratings = Mock()
257+ mock_ratings.ratings_average = values["ratings_average"]
258+ mock_ratings.ratings_total = values["ratings_total"]
259+
260+ mock_property_helper.get_review_stats.return_value = mock_ratings
261+ mock_property_helper.get_icon_at_size.return_value = values["icon"]
262+ mock_property_helper.icons = Mock()
263+ mock_property_helper.icons.load_icon.return_value = values["icon"]
264+ return mock_property_helper
265+
266+
267 def setup_test_env():
268 """ Setup environment suitable for running the test/* code in a checkout.
269 This includes PYTHONPATH, sys.path and softwarecenter.paths.datadir.

Subscribers

People subscribed via source and target branches