Merge lp:~canonical-ca-hackers/ubuntu-webcatalog/1006362-remove-maverick-add-quantal into lp:ubuntu-webcatalog

Proposed by Łukasz Czyżykowski
Status: Merged
Approved by: Łukasz Czyżykowski
Approved revision: 142
Merged at revision: 140
Proposed branch: lp:~canonical-ca-hackers/ubuntu-webcatalog/1006362-remove-maverick-add-quantal
Merge into: lp:ubuntu-webcatalog
Diff against target: 230 lines (+147/-4)
5 files modified
django_project/config/main.cfg (+0/-1)
src/webcatalog/management/commands/import_all_app_install_data.py (+47/-0)
src/webcatalog/management/commands/import_all_ratings_stats.py (+47/-0)
src/webcatalog/management/commands/import_for_purchase_apps.py (+7/-1)
src/webcatalog/tests/test_commands.py (+46/-2)
To merge this branch: bzr merge lp:~canonical-ca-hackers/ubuntu-webcatalog/1006362-remove-maverick-add-quantal
Reviewer Review Type Date Requested Status
Anthony Lenton (community) Approve
Review via email: mp+109376@code.launchpad.net

Commit message

Only create distroseries which are set in settings.

Description of the change

Overview
========
This branch makes sure that import for purchase apps only creates distroseries from ubuntu_series_for_versions dict.

Additionally there are two new import commands, import_all_ratings_stats and import_all_app_install_data which takes distroseries setting and iterate over it calling appropriate import_* command.

To post a comment you must log in.
Revision history for this message
Anthony Lenton (elachuni) wrote :

Hi Łukasz,

Looks good! Another minor improvement: import_ratings_stats, import_exhibits, import_for_purchase_apps and import_app_install_data all create DistroSeries objects if they don't find one in the DB, but they do so with the information they find available at the time, which I think is always only the code_name, not the version. Could you use the UBUNTU_SERIES_FOR_VERSIONS setting to create DistroSeries always with the right value for both fields? (If you think this is something for a separate branch, I'm happy to land this as is!)

achuni.

review: Approve
Revision history for this message
Łukasz Czyżykowski (lukasz-czyzykowski) wrote :

Yes I think it will be better done separately.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'django_project/config/main.cfg'
2--- django_project/config/main.cfg 2012-06-04 10:54:02 +0000
3+++ django_project/config/main.cfg 2012-06-08 15:05:22 +0000
4@@ -117,7 +117,6 @@
5
6 [series_for_versions]
7 10.04 = lucid
8-10.10 = maverick
9 11.04 = natty
10 11.10 = oneiric
11 12.04 = precise
12
13=== added file 'src/webcatalog/management/commands/import_all_app_install_data.py'
14--- src/webcatalog/management/commands/import_all_app_install_data.py 1970-01-01 00:00:00 +0000
15+++ src/webcatalog/management/commands/import_all_app_install_data.py 2012-06-08 15:05:22 +0000
16@@ -0,0 +1,47 @@
17+# -*- coding: utf-8 -*-
18+# This file is part of the Apps Directory
19+# Copyright (C) 2011 Canonical Ltd.
20+#
21+# This program is free software: you can redistribute it and/or modify
22+# it under the terms of the GNU Affero General Public License as
23+# published by the Free Software Foundation, either version 3 of the
24+# License, or (at your option) any later version.
25+#
26+# This program is distributed in the hope that it will be useful,
27+# but WITHOUT ANY WARRANTY; without even the implied warranty of
28+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29+# GNU Affero General Public License for more details.
30+#
31+# You should have received a copy of the GNU Affero General Public License
32+# along with this program. If not, see <http://www.gnu.org/licenses/>.
33+
34+"""Management command to import app install data for all distroseries."""
35+
36+from __future__ import (
37+ absolute_import,
38+ with_statement,
39+)
40+
41+__metaclass__ = type
42+__all__ = []
43+
44+from django.conf import settings
45+from django.core.management import call_command
46+from django.core.management.base import NoArgsCommand
47+
48+
49+class Command(NoArgsCommand):
50+
51+ def handle_noargs(self, **options):
52+ self.verbosity = int(options['verbosity'])
53+ for distroseries in settings.UBUNTU_SERIES_FOR_VERSIONS.values():
54+ self.output("Importing app-install-data for {0}".format(
55+ distroseries), 1)
56+ call_command('import_app_install_data', distroseries)
57+
58+ def output(self, message, level=None, flush=False):
59+ if hasattr(self, 'stdout'):
60+ if level is None or self.verbosity >= level:
61+ self.stdout.write(message)
62+ if flush:
63+ self.stdout.flush()
64
65=== added file 'src/webcatalog/management/commands/import_all_ratings_stats.py'
66--- src/webcatalog/management/commands/import_all_ratings_stats.py 1970-01-01 00:00:00 +0000
67+++ src/webcatalog/management/commands/import_all_ratings_stats.py 2012-06-08 15:05:22 +0000
68@@ -0,0 +1,47 @@
69+# -*- coding: utf-8 -*-
70+# This file is part of the Apps Directory
71+# Copyright (C) 2011 Canonical Ltd.
72+#
73+# This program is free software: you can redistribute it and/or modify
74+# it under the terms of the GNU Affero General Public License as
75+# published by the Free Software Foundation, either version 3 of the
76+# License, or (at your option) any later version.
77+#
78+# This program is distributed in the hope that it will be useful,
79+# but WITHOUT ANY WARRANTY; without even the implied warranty of
80+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81+# GNU Affero General Public License for more details.
82+#
83+# You should have received a copy of the GNU Affero General Public License
84+# along with this program. If not, see <http://www.gnu.org/licenses/>.
85+
86+"""Management command to import review statistics for all distroseries."""
87+
88+from __future__ import (
89+ absolute_import,
90+ with_statement,
91+)
92+
93+__metaclass__ = type
94+__all__ = []
95+
96+from django.conf import settings
97+from django.core.management import call_command
98+from django.core.management.base import NoArgsCommand
99+
100+
101+class Command(NoArgsCommand):
102+
103+ def handle_noargs(self, **options):
104+ self.verbosity = int(options['verbosity'])
105+ for distroseries in settings.UBUNTU_SERIES_FOR_VERSIONS.values():
106+ self.output("Importing ratings stats for {0}".format(
107+ distroseries), 1)
108+ call_command('import_ratings_stats', distroseries)
109+
110+ def output(self, message, level=None, flush=False):
111+ if hasattr(self, 'stdout'):
112+ if level is None or self.verbosity >= level:
113+ self.stdout.write(message)
114+ if flush:
115+ self.stdout.flush()
116
117=== modified file 'src/webcatalog/management/commands/import_for_purchase_apps.py'
118--- src/webcatalog/management/commands/import_for_purchase_apps.py 2012-06-06 16:38:11 +0000
119+++ src/webcatalog/management/commands/import_for_purchase_apps.py 2012-06-08 15:05:22 +0000
120@@ -55,12 +55,18 @@
121 if response.code != 200:
122 raise Exception("Couldn't connect to server at %s" % url)
123 app_list = json.loads(response.read())
124+ reverse_versions = dict((v, k) for (k, v) in
125+ settings.UBUNTU_SERIES_FOR_VERSIONS.items())
126 for app_data in app_list:
127 # get icon data once per app (not per app per distroseries!)
128 icon_data = self.get_icon_data(app_data)
129 for series_name in app_data['series']:
130+ if series_name not in reverse_versions:
131+ continue
132 distroseries, created = DistroSeries.objects.get_or_create(
133- code_name=series_name)
134+ code_name=series_name,
135+ defaults=dict(version=reverse_versions[series_name])
136+ )
137 if created:
138 self.output(
139 "Created a DistroSeries record called '{0}'.\n".format(
140
141=== modified file 'src/webcatalog/tests/test_commands.py'
142--- src/webcatalog/tests/test_commands.py 2012-06-06 18:00:26 +0000
143+++ src/webcatalog/tests/test_commands.py 2012-06-08 15:05:22 +0000
144@@ -61,6 +61,7 @@
145 TestCaseWithFactory,
146 WebCatalogObjectFactory,
147 )
148+from webcatalog.tests.helpers import patch_settings
149
150 __metaclass__ = type
151 __all__ = [
152@@ -71,8 +72,16 @@
153 'ImportExhibitsTestCase',
154 'ImportForPurchaseAppsTestCase',
155 'ImportRatingsTestCase',
156+ 'ImportAllAppInstallDataTestCase',
157+ 'ImportAllRatingsStatsTestCase',
158 ]
159
160+TEST_VERSIONS = {
161+ '11.04': 'natty',
162+ '10.10': 'maverick',
163+ '12.04': 'precise',
164+}
165+
166
167 class ImportAppInstallTestCase(TestCaseWithFactory):
168
169@@ -551,12 +560,22 @@
170 self.assertTrue(app_for_purchase.description.find('hello') > -1)
171
172 def test_app_gets_distroseries(self):
173- call_command('import_for_purchase_apps')
174+ with patch_settings(UBUNTU_SERIES_FOR_VERSIONS=TEST_VERSIONS):
175+ call_command('import_for_purchase_apps')
176
177 app = Application.objects.get(name='MyApp',
178 distroseries=self.natty)
179 self.assertEqual(2, len(app.available_distroseries()))
180
181+ def test_app_gets_only_distroseries_from_the_list_from_settings(self):
182+ with patch_settings(UBUNTU_SERIES_FOR_VERSIONS={'11.04': 'natty'}):
183+ call_command('import_for_purchase_apps')
184+
185+ app = Application.objects.get(
186+ name='MyApp', distroseries=self.natty)
187+
188+ self.assertEqual(1, len(app.available_distroseries()))
189+
190 def test_app_gets_price(self):
191 call_command('import_for_purchase_apps')
192
193@@ -575,7 +594,8 @@
194 distroseries__in=(self.natty, self.maverick)).count()
195 self.assertEqual(2, apps)
196
197- call_command('import_for_purchase_apps')
198+ with patch_settings(UBUNTU_SERIES_FOR_VERSIONS=TEST_VERSIONS):
199+ call_command('import_for_purchase_apps')
200
201 actual_apps = Application.objects.filter(
202 distroseries__in=(self.natty, self.maverick))
203@@ -958,3 +978,27 @@
204
205 self.assertEqual(4, Session.objects.count())
206 self.check_expected_output()
207+
208+
209+class ImportAllAppInstallDataTestCase(TestCaseWithFactory):
210+
211+ def test_handle(self):
212+ patch_attr = ('webcatalog.management.commands.'
213+ 'import_all_app_install_data.call_command')
214+ with patch_settings(UBUNTU_SERIES_FOR_VERSIONS=TEST_VERSIONS):
215+ with patch(patch_attr) as mock_call_command:
216+ call_command('import_all_app_install_data')
217+
218+ self.assertEqual(mock_call_command.call_count, 3)
219+
220+
221+class ImportAllRatingsStatsTestCase(TestCaseWithFactory):
222+
223+ def test_handle(self):
224+ patch_attr = ('webcatalog.management.commands.'
225+ 'import_all_ratings_stats.call_command')
226+ with patch_settings(UBUNTU_SERIES_FOR_VERSIONS=TEST_VERSIONS):
227+ with patch(patch_attr) as mock_call_command:
228+ call_command('import_all_ratings_stats')
229+
230+ self.assertEqual(mock_call_command.call_count, 3)

Subscribers

People subscribed via source and target branches