Merge lp:~michael.nelson/software-center/833982-previous-purchase-no-feedback-2 into lp:software-center

Proposed by Michael Nelson
Status: Merged
Merged at revision: 2687
Proposed branch: lp:~michael.nelson/software-center/833982-previous-purchase-no-feedback-2
Merge into: lp:software-center
Prerequisite: lp:~michael.nelson/software-center/833982-previous-purchase-no-feedback-really-this-time
Diff against target: 138 lines (+59/-1)
3 files modified
softwarecenter/db/update.py (+22/-0)
test/test_database.py (+0/-1)
test/test_reinstall_purchased.py (+37/-0)
To merge this branch: bzr merge lp:~michael.nelson/software-center/833982-previous-purchase-no-feedback-2
Reviewer Review Type Date Requested Status
software-store-developers Pending
Review via email: mp+89285@code.launchpad.net

Description of the change

Overview
========

This branch fixes another an issue found while trying to reproduce the original reported bug 833982. Rather getting a failure about not being able to install the app, the app was installed for the incorrect distroseries (ie. a sources.list was added for the incorrect distroseries).

Details
=======
Updates the SCAPurchasedApplicationParser so that the deb-line uses the *current* distro series of the OS, rather than the one with which the purchase was created. In case it's needed, I've made the original accessible also.

To post a comment you must log in.
2692. By Michael Nelson

REFACTOR: updated to use SourceEntry for deb line handling and removed some pyflakes lint.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/db/update.py'
2--- softwarecenter/db/update.py 2012-01-19 16:48:24 +0000
3+++ softwarecenter/db/update.py 2012-01-19 16:48:24 +0000
4@@ -25,9 +25,11 @@
5 import xapian
6 import time
7
8+from aptsources.sourceslist import SourceEntry
9 from gi.repository import GObject
10 from piston_mini_client import PistonResponseObject
11
12+from softwarecenter.distro import get_distro
13 from softwarecenter.utils import utf8
14
15 # py3 compat
16@@ -132,6 +134,7 @@
17 def desktopf(self):
18 """ return the file that the AppInfo comes from """
19
20+
21 class SCAApplicationParser(AppInfoParserBase):
22 """ map the data we get from the software-center-agent """
23
24@@ -225,6 +228,7 @@
25
26 SUBSCRIPTION_MAPPING = {
27 'Deb-Line' : 'deb_line',
28+ 'Deb-Line-Orig' : 'deb_line',
29 'Purchased-Date' : 'purchase_date',
30 'License-Key' : 'license_key',
31 'License-Key-Path' : 'license_key_path',
32@@ -233,8 +237,26 @@
33 MAPPING = dict(
34 SCAApplicationParser.MAPPING.items() + SUBSCRIPTION_MAPPING.items())
35
36+ @classmethod
37+ def update_debline(cls, debline):
38+ # Be careful to handle deblines with pockets.
39+ source_entry = SourceEntry(debline)
40+ distro_pocket = source_entry.dist.split('-')
41+ distro_pocket[0] = get_distro().get_codename()
42+ source_entry.dist = "-".join(distro_pocket)
43+
44+ return unicode(source_entry)
45+
46 def get_desktop(self, key, translated=True):
47 if self._subscription_has_option_desktop(key):
48+ if key.startswith('Deb-Line'):
49+ debline_orig = getattr(
50+ self.sca_subscription, self._apply_mapping('Deb-Line'))
51+ if key == 'Deb-Line-Orig':
52+ return debline_orig
53+ else:
54+ return self.update_debline(debline_orig)
55+
56 return getattr(self.sca_subscription, self._apply_mapping(key))
57 return super(SCAPurchasedApplicationParser, self).get_desktop(key)
58
59
60=== modified file 'test/test_database.py'
61--- test/test_database.py 2012-01-19 16:48:24 +0000
62+++ test/test_database.py 2012-01-19 16:48:24 +0000
63@@ -216,7 +216,6 @@
64 self.assertEqual(app.pkgname, 'linux-headers-'+os.uname()[2])
65 # $distro
66 details = app.get_details(db)
67- from softwarecenter.distro import get_distro
68 distro = get_distro().get_codename()
69 self.assertEqual(app.request, 'channel=' + distro + '-partner')
70
71
72=== modified file 'test/test_reinstall_purchased.py'
73--- test/test_reinstall_purchased.py 2012-01-19 16:48:24 +0000
74+++ test/test_reinstall_purchased.py 2012-01-19 16:48:24 +0000
75@@ -7,6 +7,7 @@
76 import unittest
77 import xapian
78
79+from mock import patch
80 from piston_mini_client import PistonResponseObject
81 from testutils import setup_test_env
82 setup_test_env()
83@@ -231,12 +232,22 @@
84
85 return SCAPurchasedApplicationParser(piston_subscription)
86
87+ def setUp(self):
88+ get_distro_patcher = patch('softwarecenter.db.update.get_distro')
89+ self.addCleanup(get_distro_patcher.stop)
90+ mock_get_distro = get_distro_patcher.start()
91+ mock_get_distro.return_value.get_codename.return_value = 'quintessential'
92+
93 def test_get_desktop_subscription(self):
94 parser = self._make_application_parser()
95
96 expected_results = {
97 "Deb-Line": "deb https://username:random3atoken@"
98 "private-ppa.launchpad.net/commercial-ppa-uploaders"
99+ "/photobomb/ubuntu quintessential main",
100+ "Deb-Line-Orig":
101+ "deb https://username:random3atoken@"
102+ "private-ppa.launchpad.net/commercial-ppa-uploaders"
103 "/photobomb/ubuntu natty main",
104 "Purchased-Date": "2011-09-16 06:37:52",
105 }
106@@ -315,6 +326,32 @@
107 supported_distros,
108 parser.get_desktop('Supported-Distros'))
109
110+ def test_update_debline_other_series(self):
111+ orig_debline = (
112+ "deb https://username:random3atoken@"
113+ "private-ppa.launchpad.net/commercial-ppa-uploaders"
114+ "/photobomb/ubuntu karmic main")
115+ expected_debline = (
116+ "deb https://username:random3atoken@"
117+ "private-ppa.launchpad.net/commercial-ppa-uploaders"
118+ "/photobomb/ubuntu quintessential main")
119+
120+ self.assertEqual(expected_debline,
121+ SCAPurchasedApplicationParser.update_debline(orig_debline))
122+
123+ def test_update_debline_with_pocket(self):
124+ orig_debline = (
125+ "deb https://username:random3atoken@"
126+ "private-ppa.launchpad.net/commercial-ppa-uploaders"
127+ "/photobomb/ubuntu karmic-security main")
128+ expected_debline = (
129+ "deb https://username:random3atoken@"
130+ "private-ppa.launchpad.net/commercial-ppa-uploaders"
131+ "/photobomb/ubuntu quintessential-security main")
132+
133+ self.assertEqual(expected_debline,
134+ SCAPurchasedApplicationParser.update_debline(orig_debline))
135+
136
137 if __name__ == "__main__":
138 logging.basicConfig(level=logging.DEBUG)