Merge lp:~mvo/software-center/display-price-property into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 3110
Proposed branch: lp:~mvo/software-center/display-price-property
Merge into: lp:software-center
Diff against target: 167 lines (+72/-21)
6 files modified
softwarecenter/db/application.py (+24/-4)
softwarecenter/ui/gtk3/models/appstore2.py (+2/-5)
softwarecenter/ui/gtk3/views/appdetailsview.py (+1/-8)
softwarecenter/ui/gtk3/widgets/cellrenderers.py (+1/-2)
tests/gtk3/test_appdetailsview.py (+2/-2)
tests/test_application.py (+42/-0)
To merge this branch: bzr merge lp:~mvo/software-center/display-price-property
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+120083@code.launchpad.net

Description of the change

This is another branch for the unity people, it will include the currency
in the "price" property. In addition there is a new "raw_price" property
that can be used as a sort key and that will not include currency data.

To post a comment you must log in.
Revision history for this message
Gary Lasker (gary-lasker) wrote :

This looks fine. Thanks for the unit test!

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-08-15 14:11:19 +0000
3+++ softwarecenter/db/application.py 2012-08-17 09:01:23 +0000
4@@ -531,7 +531,7 @@
5 u"current software sources.")) % utf8(self.pkgname)
6 return PkgStates.NOT_FOUND
7 else:
8- if self.price:
9+ if self.raw_price:
10 return PkgStates.NEEDS_PURCHASE
11 if (self.purchase_date and
12 self._doc.get_value(XapianValues.ARCHIVE_DEB_LINE)):
13@@ -568,15 +568,35 @@
14
15 @property
16 def currency(self):
17- if self.price:
18+ """ Get the currency for the price """
19+ if self.raw_price:
20 # this is hardcoded to US dollar for now, but if the server
21 # ever changes that we are prepared
22 return "US$"
23
24 @property
25+ def raw_price(self):
26+ """ The raw price, useful for e.g. sort-by """
27+ if self._doc:
28+ return self._doc.get_value(XapianValues.PRICE)
29+
30+ @property
31 def price(self):
32- if self._doc:
33- return self._doc.get_value(XapianValues.PRICE)
34+ """ The price and the currency ready to display to the user """
35+ raw_price = self.raw_price
36+ currency = self.currency
37+ if raw_price and currency:
38+ # FIXME: need to determine the currency dynamically once we can
39+ # get that info from the software-center-agent/payments
40+ # service.
41+ # NOTE: the currency string for this label is purposely not
42+ # translatable when hardcoded, since it (currently)
43+ # won't vary based on locale and as such we don't want
44+ # it translated
45+ # FIXME: if we support different currencies eventually we need
46+ # to format them here differently too, e.g.
47+ # "US$ 1" but "1EUR"
48+ return "%s %s" % (currency, raw_price)
49
50 @property
51 def supported_distros(self):
52
53=== modified file 'softwarecenter/ui/gtk3/models/appstore2.py'
54--- softwarecenter/ui/gtk3/models/appstore2.py 2012-08-15 14:11:19 +0000
55+++ softwarecenter/ui/gtk3/models/appstore2.py 2012-08-17 09:01:23 +0000
56@@ -213,13 +213,10 @@
57 GObject.markup_escape_text(appname),
58 GObject.markup_escape_text(summary))
59
60- def get_price(self, doc):
61- return doc.get_value(XapianValues.PRICE)
62-
63- def get_currency(self, doc):
64+ def get_display_price(self, doc):
65 app = self.db.get_application(doc)
66 details = app.get_details(self.db)
67- return details.currency
68+ return details.price
69
70 def get_icon(self, doc):
71 try:
72
73=== modified file 'softwarecenter/ui/gtk3/views/appdetailsview.py'
74--- softwarecenter/ui/gtk3/views/appdetailsview.py 2012-08-16 14:44:29 +0000
75+++ softwarecenter/ui/gtk3/views/appdetailsview.py 2012-08-17 09:01:23 +0000
76@@ -365,14 +365,7 @@
77 elif state == PkgStates.INSTALLED:
78 self.set_button_label(_('Remove'))
79 elif state == PkgStates.NEEDS_PURCHASE:
80- # FIXME: need to determine the currency dynamically once we can
81- # get that info from the software-center-agent/payments
82- # service.
83- # NOTE: the currency string for this label is purposely not
84- # translatable when hardcoded, since it (currently)
85- # won't vary based on locale and as such we don't want
86- # it translated
87- self.set_label("%s %s" % (app_details.currency, app_details.price))
88+ self.set_label("%s" % (app_details.price))
89 if (app_details.hardware_requirements_satisfied and
90 app_details.region_requirements_satisfied):
91 self.set_button_label(_(u'Buy\u2026'))
92
93=== modified file 'softwarecenter/ui/gtk3/widgets/cellrenderers.py'
94--- softwarecenter/ui/gtk3/widgets/cellrenderers.py 2012-08-15 14:11:19 +0000
95+++ softwarecenter/ui/gtk3/widgets/cellrenderers.py 2012-08-17 09:01:23 +0000
96@@ -123,8 +123,7 @@
97
98 def _render_price(self, context, cr, app, layout, cell_area, xpad, ypad,
99 is_rtl):
100- layout.set_markup("%s %s" % (
101- self.model.get_currency(app), self.model.get_price(app)), -1)
102+ layout.set_markup("%s" % self.model.get_display_price(app))
103
104 if is_rtl:
105 x = cell_area.x + xpad
106
107=== modified file 'tests/gtk3/test_appdetailsview.py'
108--- tests/gtk3/test_appdetailsview.py 2012-08-17 08:06:50 +0000
109+++ tests/gtk3/test_appdetailsview.py 2012-08-17 09:01:23 +0000
110@@ -82,8 +82,8 @@
111 # create mock app
112 self.set_mock_app_and_details(
113 app_name="abiword", purchase_date="2011-11-20 17:45:01",
114- _error_not_found="error not found", price="1.00",
115- currency="US$", pkgname="abiword", error="error-text")
116+ _error_not_found="error not found", price="US$ 1.00",
117+ pkgname="abiword", error="error-text")
118 mock_app = self.view.app
119 mock_details = self.view.app_details
120
121
122=== added file 'tests/test_application.py'
123--- tests/test_application.py 1970-01-01 00:00:00 +0000
124+++ tests/test_application.py 2012-08-17 09:01:23 +0000
125@@ -0,0 +1,42 @@
126+import unittest
127+
128+from mock import (
129+ patch,
130+ Mock,
131+ )
132+
133+from tests.utils import (
134+ setup_test_env,
135+ get_test_db,
136+)
137+setup_test_env()
138+from softwarecenter.db.application import (
139+ Application,
140+ AppDetails,
141+ )
142+
143+
144+# FIXME: move application/appdetails tests from test_database.py
145+# into this file for better structure
146+class ApplicationTestCase(unittest.TestCase):
147+
148+ def test_application_name(self):
149+ app1 = Application(appname="The AppName", pkgname="pkgapp")
150+ self.assertEqual(app1.name, "The AppName")
151+ app2 = Application(appname="", pkgname="pkgapp2")
152+ self.assertEqual(app2.name, "pkgapp2")
153+
154+ def test_appdetails(self):
155+ app = Application("Foo app", "dpkg")
156+ db = get_test_db()
157+ appdetails = app.get_details(db)
158+ # patching properties is a bit cumbersome
159+ with patch.object(AppDetails, "raw_price") as mock_price:
160+ with patch.object(AppDetails, "currency") as mock_currency:
161+ mock_price.__get__ = Mock(return_value="2.99")
162+ mock_currency.__get__ = Mock(return_value="USD")
163+ self.assertEqual("USD 2.99", appdetails.price)
164+
165+
166+if __name__ == "__main__":
167+ unittest.main()

Subscribers

People subscribed via source and target branches