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
=== modified file 'django_project/config/main.cfg'
--- django_project/config/main.cfg 2012-06-04 10:54:02 +0000
+++ django_project/config/main.cfg 2012-06-08 15:05:22 +0000
@@ -117,7 +117,6 @@
117117
118[series_for_versions]118[series_for_versions]
11910.04 = lucid11910.04 = lucid
12010.10 = maverick
12111.04 = natty12011.04 = natty
12211.10 = oneiric12111.10 = oneiric
12312.04 = precise12212.04 = precise
124123
=== added file 'src/webcatalog/management/commands/import_all_app_install_data.py'
--- src/webcatalog/management/commands/import_all_app_install_data.py 1970-01-01 00:00:00 +0000
+++ src/webcatalog/management/commands/import_all_app_install_data.py 2012-06-08 15:05:22 +0000
@@ -0,0 +1,47 @@
1# -*- coding: utf-8 -*-
2# This file is part of the Apps Directory
3# Copyright (C) 2011 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Affero General Public License as
7# published by the Free Software Foundation, either version 3 of the
8# License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Management command to import app install data for all distroseries."""
19
20from __future__ import (
21 absolute_import,
22 with_statement,
23)
24
25__metaclass__ = type
26__all__ = []
27
28from django.conf import settings
29from django.core.management import call_command
30from django.core.management.base import NoArgsCommand
31
32
33class Command(NoArgsCommand):
34
35 def handle_noargs(self, **options):
36 self.verbosity = int(options['verbosity'])
37 for distroseries in settings.UBUNTU_SERIES_FOR_VERSIONS.values():
38 self.output("Importing app-install-data for {0}".format(
39 distroseries), 1)
40 call_command('import_app_install_data', distroseries)
41
42 def output(self, message, level=None, flush=False):
43 if hasattr(self, 'stdout'):
44 if level is None or self.verbosity >= level:
45 self.stdout.write(message)
46 if flush:
47 self.stdout.flush()
048
=== added file 'src/webcatalog/management/commands/import_all_ratings_stats.py'
--- src/webcatalog/management/commands/import_all_ratings_stats.py 1970-01-01 00:00:00 +0000
+++ src/webcatalog/management/commands/import_all_ratings_stats.py 2012-06-08 15:05:22 +0000
@@ -0,0 +1,47 @@
1# -*- coding: utf-8 -*-
2# This file is part of the Apps Directory
3# Copyright (C) 2011 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Affero General Public License as
7# published by the Free Software Foundation, either version 3 of the
8# License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Management command to import review statistics for all distroseries."""
19
20from __future__ import (
21 absolute_import,
22 with_statement,
23)
24
25__metaclass__ = type
26__all__ = []
27
28from django.conf import settings
29from django.core.management import call_command
30from django.core.management.base import NoArgsCommand
31
32
33class Command(NoArgsCommand):
34
35 def handle_noargs(self, **options):
36 self.verbosity = int(options['verbosity'])
37 for distroseries in settings.UBUNTU_SERIES_FOR_VERSIONS.values():
38 self.output("Importing ratings stats for {0}".format(
39 distroseries), 1)
40 call_command('import_ratings_stats', distroseries)
41
42 def output(self, message, level=None, flush=False):
43 if hasattr(self, 'stdout'):
44 if level is None or self.verbosity >= level:
45 self.stdout.write(message)
46 if flush:
47 self.stdout.flush()
048
=== modified file 'src/webcatalog/management/commands/import_for_purchase_apps.py'
--- src/webcatalog/management/commands/import_for_purchase_apps.py 2012-06-06 16:38:11 +0000
+++ src/webcatalog/management/commands/import_for_purchase_apps.py 2012-06-08 15:05:22 +0000
@@ -55,12 +55,18 @@
55 if response.code != 200:55 if response.code != 200:
56 raise Exception("Couldn't connect to server at %s" % url)56 raise Exception("Couldn't connect to server at %s" % url)
57 app_list = json.loads(response.read())57 app_list = json.loads(response.read())
58 reverse_versions = dict((v, k) for (k, v) in
59 settings.UBUNTU_SERIES_FOR_VERSIONS.items())
58 for app_data in app_list:60 for app_data in app_list:
59 # get icon data once per app (not per app per distroseries!)61 # get icon data once per app (not per app per distroseries!)
60 icon_data = self.get_icon_data(app_data)62 icon_data = self.get_icon_data(app_data)
61 for series_name in app_data['series']:63 for series_name in app_data['series']:
64 if series_name not in reverse_versions:
65 continue
62 distroseries, created = DistroSeries.objects.get_or_create(66 distroseries, created = DistroSeries.objects.get_or_create(
63 code_name=series_name)67 code_name=series_name,
68 defaults=dict(version=reverse_versions[series_name])
69 )
64 if created:70 if created:
65 self.output(71 self.output(
66 "Created a DistroSeries record called '{0}'.\n".format(72 "Created a DistroSeries record called '{0}'.\n".format(
6773
=== modified file 'src/webcatalog/tests/test_commands.py'
--- src/webcatalog/tests/test_commands.py 2012-06-06 18:00:26 +0000
+++ src/webcatalog/tests/test_commands.py 2012-06-08 15:05:22 +0000
@@ -61,6 +61,7 @@
61 TestCaseWithFactory,61 TestCaseWithFactory,
62 WebCatalogObjectFactory,62 WebCatalogObjectFactory,
63)63)
64from webcatalog.tests.helpers import patch_settings
6465
65__metaclass__ = type66__metaclass__ = type
66__all__ = [67__all__ = [
@@ -71,8 +72,16 @@
71 'ImportExhibitsTestCase',72 'ImportExhibitsTestCase',
72 'ImportForPurchaseAppsTestCase',73 'ImportForPurchaseAppsTestCase',
73 'ImportRatingsTestCase',74 'ImportRatingsTestCase',
75 'ImportAllAppInstallDataTestCase',
76 'ImportAllRatingsStatsTestCase',
74]77]
7578
79TEST_VERSIONS = {
80 '11.04': 'natty',
81 '10.10': 'maverick',
82 '12.04': 'precise',
83}
84
7685
77class ImportAppInstallTestCase(TestCaseWithFactory):86class ImportAppInstallTestCase(TestCaseWithFactory):
7887
@@ -551,12 +560,22 @@
551 self.assertTrue(app_for_purchase.description.find('hello') > -1)560 self.assertTrue(app_for_purchase.description.find('hello') > -1)
552561
553 def test_app_gets_distroseries(self):562 def test_app_gets_distroseries(self):
554 call_command('import_for_purchase_apps')563 with patch_settings(UBUNTU_SERIES_FOR_VERSIONS=TEST_VERSIONS):
564 call_command('import_for_purchase_apps')
555565
556 app = Application.objects.get(name='MyApp',566 app = Application.objects.get(name='MyApp',
557 distroseries=self.natty)567 distroseries=self.natty)
558 self.assertEqual(2, len(app.available_distroseries()))568 self.assertEqual(2, len(app.available_distroseries()))
559569
570 def test_app_gets_only_distroseries_from_the_list_from_settings(self):
571 with patch_settings(UBUNTU_SERIES_FOR_VERSIONS={'11.04': 'natty'}):
572 call_command('import_for_purchase_apps')
573
574 app = Application.objects.get(
575 name='MyApp', distroseries=self.natty)
576
577 self.assertEqual(1, len(app.available_distroseries()))
578
560 def test_app_gets_price(self):579 def test_app_gets_price(self):
561 call_command('import_for_purchase_apps')580 call_command('import_for_purchase_apps')
562581
@@ -575,7 +594,8 @@
575 distroseries__in=(self.natty, self.maverick)).count()594 distroseries__in=(self.natty, self.maverick)).count()
576 self.assertEqual(2, apps)595 self.assertEqual(2, apps)
577596
578 call_command('import_for_purchase_apps')597 with patch_settings(UBUNTU_SERIES_FOR_VERSIONS=TEST_VERSIONS):
598 call_command('import_for_purchase_apps')
579599
580 actual_apps = Application.objects.filter(600 actual_apps = Application.objects.filter(
581 distroseries__in=(self.natty, self.maverick))601 distroseries__in=(self.natty, self.maverick))
@@ -958,3 +978,27 @@
958978
959 self.assertEqual(4, Session.objects.count())979 self.assertEqual(4, Session.objects.count())
960 self.check_expected_output()980 self.check_expected_output()
981
982
983class ImportAllAppInstallDataTestCase(TestCaseWithFactory):
984
985 def test_handle(self):
986 patch_attr = ('webcatalog.management.commands.'
987 'import_all_app_install_data.call_command')
988 with patch_settings(UBUNTU_SERIES_FOR_VERSIONS=TEST_VERSIONS):
989 with patch(patch_attr) as mock_call_command:
990 call_command('import_all_app_install_data')
991
992 self.assertEqual(mock_call_command.call_count, 3)
993
994
995class ImportAllRatingsStatsTestCase(TestCaseWithFactory):
996
997 def test_handle(self):
998 patch_attr = ('webcatalog.management.commands.'
999 'import_all_ratings_stats.call_command')
1000 with patch_settings(UBUNTU_SERIES_FOR_VERSIONS=TEST_VERSIONS):
1001 with patch(patch_attr) as mock_call_command:
1002 call_command('import_all_ratings_stats')
1003
1004 self.assertEqual(mock_call_command.call_count, 3)

Subscribers

People subscribed via source and target branches