diff --git a/apps/access/tests.py b/apps/access/tests.py index e33fcfc571..0e1d9df418 100644 --- a/apps/access/tests.py +++ b/apps/access/tests.py @@ -75,7 +75,7 @@ class ACLTestCase(TestCase): class TestHasPerm(TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): assert self.client.login(username='del@icio.us', password='password') diff --git a/apps/addons/fixtures/addons/default-to-compat.json b/apps/addons/fixtures/addons/default-to-compat.json index 03f360d92e..244cc6dfc3 100644 --- a/apps/addons/fixtures/addons/default-to-compat.json +++ b/apps/addons/fixtures/addons/default-to-compat.json @@ -1,13 +1,4 @@ [ - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2011-07-29 09:20:37", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 233, "model": "applications.appversion", diff --git a/apps/addons/fixtures/addons/listed.json b/apps/addons/fixtures/addons/listed.json index ae14d40b46..966a496eed 100644 --- a/apps/addons/fixtures/addons/listed.json +++ b/apps/addons/fixtures/addons/listed.json @@ -94,15 +94,6 @@ "addon": 3723 } }, - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 73083, "model": "versions.applicationsversions", diff --git a/apps/addons/fixtures/addons/ptbr-promobox.json b/apps/addons/fixtures/addons/ptbr-promobox.json index d8bee9204d..50f75b1e35 100644 --- a/apps/addons/fixtures/addons/ptbr-promobox.json +++ b/apps/addons/fixtures/addons/ptbr-promobox.json @@ -1,13 +1,4 @@ [ - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 4, "model": "bandwagon.collectionfeature", diff --git a/apps/addons/fixtures/addons/test_manager.json b/apps/addons/fixtures/addons/test_manager.json index 81683c2db4..0e081749d2 100644 --- a/apps/addons/fixtures/addons/test_manager.json +++ b/apps/addons/fixtures/addons/test_manager.json @@ -1,22 +1,4 @@ [ - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 18, - "model": "applications.application", - "fields": { - "guid": "{zzz}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 1, "model": "addons.addon", diff --git a/apps/addons/fixtures/addons/update.json b/apps/addons/fixtures/addons/update.json index 973f2c699f..64c47631de 100644 --- a/apps/addons/fixtures/addons/update.json +++ b/apps/addons/fixtures/addons/update.json @@ -597,61 +597,6 @@ "min": 103 } }, - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 2, - "model": "applications.application", - "fields": { - "guid": "{86c18b42-e466-45a9-ae7a-9b95ba6f5640}", - "modified": "2008-11-03 15:35:00", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 18, - "model": "applications.application", - "fields": { - "guid": "{3550f703-e582-4d05-9a08-453d09bdfdc6}", - "modified": "2008-06-17 08:29:00", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 52, - "model": "applications.application", - "fields": { - "guid": "{718e30fb-e89b-41dd-9da7-e25a45638b28}", - "supported": "0", - "modified": "2008-06-17 08:29:01", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 59, - "model": "applications.application", - "fields": { - "guid": "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}", - "modified": "2008-06-17 08:29:01", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 60, - "model": "applications.application", - "fields": { - "guid": "{a23983c0-fd0e-11dc-95ff-0800200c9a66}", - "modified": "2010-09-28 10:50:30", - "created": "2008-10-28 18:25:09" - } - }, { "pk": 411, "model": "applications.appversion", diff --git a/apps/addons/forms.py b/apps/addons/forms.py index 8bec119123..2b052e9bb6 100644 --- a/apps/addons/forms.py +++ b/apps/addons/forms.py @@ -22,7 +22,6 @@ from addons.models import (Addon, AddonCategory, BlacklistedSlug, Category, from addons.tasks import save_theme, save_theme_reupload from addons.utils import reverse_name_lookup from addons.widgets import IconWidgetRenderer, CategoriesSelectMultiple -from applications.models import Application from devhub import tasks as devhub_tasks from tags.models import Tag from translations import LOCALES @@ -184,16 +183,10 @@ class AppFormBasic(AddonFormBasic): name = TransField(max_length=128) -class ApplicationChoiceField(forms.ModelChoiceField): - - def label_from_instance(self, obj): - return obj.id - - class CategoryForm(forms.Form): - application = ApplicationChoiceField(Application.objects.all(), - widget=forms.HiddenInput, - required=False) + application = forms.ChoiceField(amo.APPS_CHOICES, + widget=forms.HiddenInput, + required=False) categories = forms.ModelMultipleChoiceField( queryset=Category.objects.all(), widget=CategoriesSelectMultiple) @@ -201,8 +194,8 @@ class CategoryForm(forms.Form): application = self.cleaned_data['application'] categories_new = self.cleaned_data['categories'] categories_old = [cats for app, cats in addon.app_categories if - (app and application and app.id == application.id) or - (not app and not application)] + (app and application and app.id == int(application)) + or (not app and not application)] if categories_old: categories_old = categories_old[0] @@ -251,7 +244,7 @@ class BaseCategoryFormSet(BaseFormSet): # Drop any apps that don't have appropriate categories. qs = Category.objects.filter(type=self.addon.type) app_cats = dict((k, list(v)) for k, v in - sorted_groupby(qs, 'application_id')) + sorted_groupby(qs, 'application')) for app in list(apps): if app and not app_cats.get(app.id): apps.remove(app) diff --git a/apps/addons/models.py b/apps/addons/models.py index b365ef8d56..56572dbb4e 100644 --- a/apps/addons/models.py +++ b/apps/addons/models.py @@ -613,7 +613,7 @@ class Addon(amo.models.OnChangeMixin, amo.models.ModelBase): status_list = ','.join(map(str, status)) fltr = {'files__status__in': status} if backup_version: - fltr['apps__application__id'] = amo.FIREFOX.id + fltr['apps__application'] = amo.FIREFOX.id fltr['apps__min__version_int__lt'] = amo.FIREFOX.backup_version return self.versions.no_cache().filter(**fltr).extra( where=[""" @@ -772,13 +772,12 @@ class Addon(amo.models.OnChangeMixin, amo.models.ModelBase): ON addons.id = versions.addon_id AND addons.id = %(id)s INNER JOIN applications_versions ON applications_versions.version_id = versions.id - INNER JOIN applications - ON applications_versions.application_id = applications.id - AND applications.id = %(app_id)s INNER JOIN appversions appmin ON appmin.id = applications_versions.min + AND appmin.application_id = %(app_id)s INNER JOIN appversions appmax ON appmax.id = applications_versions.max + AND appmax.application_id = %(app_id)s INNER JOIN files ON files.version_id = versions.id AND (files.platform_id = 1"""] @@ -1342,7 +1341,7 @@ class Addon(amo.models.OnChangeMixin, amo.models.ModelBase): def app_categories(self): categories = sorted_groupby(order_by_translation(self.categories.all(), 'name'), - key=lambda x: x.application_id) + key=lambda x: x.application) app_cats = [] for app_id, cats in categories: app = amo.APP_IDS.get(app_id) @@ -1926,8 +1925,8 @@ class Category(amo.models.OnChangeMixin, amo.models.ModelBase): help_text='Used in Category URLs.') type = models.PositiveIntegerField(db_column='addontype_id', choices=do_dictsort(amo.ADDON_TYPE)) - application = models.ForeignKey('applications.Application', null=True, - blank=True) + application = models.PositiveIntegerField(null=True, blank=True, + db_column='application_id') count = models.IntegerField('Addon count', default=0) weight = models.IntegerField( default=0, help_text='Category weight used in sort ordering') @@ -1978,7 +1977,7 @@ class Feature(amo.models.ModelBase): start = models.DateTimeField() end = models.DateTimeField() locale = models.CharField(max_length=10, default='', blank=True, null=True) - application = models.ForeignKey('applications.Application') + application = models.PositiveIntegerField(db_column='application_id') class Meta: db_table = 'features' @@ -2088,7 +2087,7 @@ dbsignals.pre_save.connect(save_signal, sender=Preview, class AppSupport(amo.models.ModelBase): """Cache to tell us if an add-on's current version supports an app.""" addon = models.ForeignKey(Addon) - app = models.ForeignKey('applications.Application') + app = models.PositiveIntegerField(db_column='app_id') min = models.BigIntegerField("Minimum app version", null=True) max = models.BigIntegerField("Maximum app version", null=True) @@ -2212,7 +2211,7 @@ class CompatOverride(amo.models.ModelBase): item = Range(first.override_type(), first.min_version, first.max_version, []) for compat in compats: - app = AppRange(amo.APPS_ALL[compat.app_id], + app = AppRange(amo.APPS_ALL[compat.app], compat.min_app_version, compat.max_app_version) item.apps.append(app) rv.append(item) @@ -2237,7 +2236,7 @@ class CompatOverrideRange(amo.models.ModelBase): max_length=255, default='*', help_text=u'If not "*", version is required to exist for the override' u' to take effect.') - app = models.ForeignKey('applications.Application') + app = models.PositiveIntegerField(db_column='app_id') min_app_version = models.CharField(max_length=255, default='0') max_app_version = models.CharField(max_length=255, default='*') @@ -2260,7 +2259,7 @@ class IncompatibleVersions(amo.models.ModelBase): a particular version falls within the range of a compatibility override. """ version = models.ForeignKey(Version, related_name='+') - app = models.ForeignKey('applications.Application', related_name='+') + app = models.PositiveIntegerField(db_column='app_id') min_app_version = models.CharField(max_length=255, blank=True, default='0') max_app_version = models.CharField(max_length=255, blank=True, default='*') min_app_version_int = models.BigIntegerField(blank=True, null=True, diff --git a/apps/addons/tasks.py b/apps/addons/tasks.py index 8685230d4c..200ef04db4 100644 --- a/apps/addons/tasks.py +++ b/apps/addons/tasks.py @@ -252,7 +252,7 @@ def update_incompatible_appversions(data, **kw): for app_range in app_ranges: IncompatibleVersions.objects.create(version=version, - app_id=app_range.app.id, + app=app_range.app.id, min_app_version=app_range.min, max_app_version=app_range.max) log.info('Added incompatible version for version ID [%d]: ' diff --git a/apps/addons/tests/test_buttons.py b/apps/addons/tests/test_buttons.py index a5e186a407..09aa59e48d 100644 --- a/apps/addons/tests/test_buttons.py +++ b/apps/addons/tests/test_buttons.py @@ -570,7 +570,7 @@ class TestBackup(ButtonTest): class TestViews(amo.tests.TestCase): - fixtures = ['addons/eula+contrib-addon', 'base/apps'] + fixtures = ['addons/eula+contrib-addon'] def test_eula_with_contrib_roadblock(self): url = reverse('addons.eula', args=[11730, 53612]) diff --git a/apps/addons/tests/test_cron.py b/apps/addons/tests/test_cron.py index dd64f61c53..b8bb6ac185 100644 --- a/apps/addons/tests/test_cron.py +++ b/apps/addons/tests/test_cron.py @@ -34,7 +34,7 @@ class CurrentVersionTestCase(amo.tests.TestCase): class TestLastUpdated(amo.tests.TestCase): - fixtures = ['base/addon_3615', 'addons/listed', 'base/apps', + fixtures = ['base/addon_3615', 'addons/listed', 'addons/persona', 'base/seamonkey', 'base/thunderbird'] def test_personas(self): diff --git a/apps/addons/tests/test_forms.py b/apps/addons/tests/test_forms.py index cbd8f550a4..c72e8d36d4 100644 --- a/apps/addons/tests/test_forms.py +++ b/apps/addons/tests/test_forms.py @@ -271,11 +271,10 @@ class TestIconForm(amo.tests.TestCase): class TestCategoryForm(amo.tests.TestCase): - fixtures = ['base/apps'] def test_no_possible_categories(self): Category.objects.create(type=amo.ADDON_SEARCH, - application_id=amo.FIREFOX.id) + application=amo.FIREFOX.id) addon = Addon.objects.create(type=amo.ADDON_SEARCH) form = forms.CategoryFormSet(addon=addon) apps = [f.app for f in form.forms] diff --git a/apps/addons/tests/test_models.py b/apps/addons/tests/test_models.py index 77dfe3fded..2da5bec367 100644 --- a/apps/addons/tests/test_models.py +++ b/apps/addons/tests/test_models.py @@ -27,7 +27,7 @@ from addons.models import (Addon, AddonCategory, AddonDependency, CompatOverrideRange, FrozenAddon, IncompatibleVersions, Persona, Preview) from addons.search import setup_mapping -from applications.models import Application, AppVersion +from applications.models import AppVersion from constants.applications import DEVICE_TYPES from devhub.models import ActivityLog, AddonLog, RssKey, SubmitStep from editors.models import EscalationQueue @@ -180,7 +180,7 @@ class TestCleanSlug(amo.tests.TestCase): class TestAddonManager(amo.tests.TestCase): - fixtures = ['base/apps', 'base/appversion', 'base/users', + fixtures = ['base/appversion', 'base/users', 'base/addon_3615', 'addons/featured', 'addons/test_manager', 'base/collections', 'base/featured', 'bandwagon/featured_collections', 'base/addon_5299_gcal'] @@ -199,8 +199,9 @@ class TestAddonManager(amo.tests.TestCase): q = Addon.objects.listed(amo.FIREFOX, amo.STATUS_PUBLIC) eq_(len(q.all()), 4) - addon = q[0] - eq_(addon.id, 2464) + # Pick one of the listed addons. + addon = Addon.objects.get(pk=2464) + assert addon in q.all() # Disabling hides it. addon.disabled_by_user = True @@ -296,8 +297,7 @@ class TestAddonManager(amo.tests.TestCase): class TestAddonModels(amo.tests.TestCase): - fixtures = ['base/apps', - 'base/appversion', + fixtures = ['base/appversion', 'base/collections', 'base/featured', 'base/users', @@ -384,7 +384,7 @@ class TestAddonModels(amo.tests.TestCase): v = Version.objects.create(addon=addon, version='99') File.objects.create(status=status, version=v) - ApplicationsVersions.objects.create(application_id=amo.FIREFOX.id, + ApplicationsVersions.objects.create(application=amo.FIREFOX.id, version=v, min=av.min, max=av.max) return v @@ -510,7 +510,7 @@ class TestAddonModels(amo.tests.TestCase): def test_incompatible_asterix(self): av = ApplicationsVersions.objects.get(pk=47881) - av.max = AppVersion.objects.create(application_id=amo.FIREFOX.id, + av.max = AppVersion.objects.create(application=amo.FIREFOX.id, version_int=version_int('5.*'), version='5.*') av.save() @@ -972,15 +972,14 @@ class TestAddonModels(amo.tests.TestCase): cats = addon().all_categories eq_(cats, [c22, c23, c24]) for cat in cats: - eq_(cat.application.id, amo.FIREFOX.id) + eq_(cat.application, amo.FIREFOX.id) cats = [c24, c23, c22] app_cats = [(amo.FIREFOX, cats)] eq_(addon().app_categories, app_cats) - tb = Application.objects.get(id=amo.THUNDERBIRD.id) - c = Category(application=tb, name='XXX', type=addon().type, count=1, - weight=1) + c = Category(application=amo.THUNDERBIRD.id, name='XXX', + type=addon().type, count=1, weight=1) c.save() AddonCategory.objects.create(addon=addon(), category=c) c24.save() # Clear the app_categories cache. @@ -996,9 +995,8 @@ class TestAddonModels(amo.tests.TestCase): eq_(addon.app_categories, [(amo.FIREFOX, cats)]) # Associate this add-on with a Sunbird category. - a = Application.objects.create(id=amo.SUNBIRD.id) - c2 = Category.objects.create(application=a, type=amo.ADDON_EXTENSION, - name='Sunny D') + c2 = Category.objects.create(application=amo.SUNBIRD.id, + type=amo.ADDON_EXTENSION, name='Sunny D') AddonCategory.objects.create(addon=addon, category=c2) # Sunbird category should be excluded. @@ -1470,8 +1468,7 @@ class TestAddonDelete(amo.tests.TestCase): other_addon=addon, score=0) AddonUser.objects.create(addon=addon, user=UserProfile.objects.create()) - AppSupport.objects.create(addon=addon, - app=Application.objects.create()) + AppSupport.objects.create(addon=addon, app=1) CompatOverride.objects.create(addon=addon) FrozenAddon.objects.create(addon=addon) Persona.objects.create(addon=addon, persona_id=0) @@ -1600,7 +1597,7 @@ class TestAddonGetURLPath(amo.tests.TestCase): class TestAddonModelsFeatured(amo.tests.TestCase): - fixtures = ['base/apps', 'base/appversion', 'base/users', + fixtures = ['base/appversion', 'base/users', 'addons/featured', 'bandwagon/featured_collections', 'base/addon_3615', 'base/collections', 'base/featured'] @@ -1622,7 +1619,7 @@ class TestAddonModelsFeatured(amo.tests.TestCase): class TestBackupVersion(amo.tests.TestCase): - fixtures = ['addons/update', 'base/apps', 'base/appversion'] + fixtures = ['addons/update', 'base/appversion'] def setUp(self): self.version_1_2_0 = 105387 @@ -1818,8 +1815,7 @@ class TestAddonRecommendations(amo.tests.TestCase): class TestAddonDependencies(amo.tests.TestCase): - fixtures = ['base/apps', - 'base/appversion', + fixtures = ['base/appversion', 'base/users', 'base/addon_5299_gcal', 'base/addon_3615', @@ -1857,8 +1853,7 @@ class TestListedAddonTwoVersions(amo.tests.TestCase): class TestFlushURLs(amo.tests.TestCase): - fixtures = ['base/apps', - 'base/appversion', + fixtures = ['base/appversion', 'base/users', 'base/addon_5579', 'base/previews', @@ -1904,7 +1899,7 @@ class TestFlushURLs(amo.tests.TestCase): class TestAddonFromUpload(UploadTest): - fixtures = ('base/apps', 'base/users') + fixtures = ['base/users'] def setUp(self): super(TestAddonFromUpload, self).setUp() @@ -1912,7 +1907,7 @@ class TestAddonFromUpload(UploadTest): set_user(u) self.platform = amo.PLATFORM_MAC.id for version in ('3.0', '3.6.*'): - AppVersion.objects.create(application_id=1, version=version) + AppVersion.objects.create(application=1, version=version) self.addCleanup(translation.deactivate) def manifest(self, basename): @@ -2257,15 +2252,15 @@ class TestLanguagePack(amo.tests.TestCase, amo.tests.AMOPaths): class TestCompatOverride(amo.tests.TestCase): def setUp(self): - self.app = Application.objects.create(id=1) + self.app = amo.APP_IDS[1] one = CompatOverride.objects.create(guid='one') - CompatOverrideRange.objects.create(compat=one, app=self.app) + CompatOverrideRange.objects.create(compat=one, app=self.app.id) two = CompatOverride.objects.create(guid='two') - CompatOverrideRange.objects.create(compat=two, app=self.app, + CompatOverrideRange.objects.create(compat=two, app=self.app.id, min_version='1', max_version='2') - CompatOverrideRange.objects.create(compat=two, app=self.app, + CompatOverrideRange.objects.create(compat=two, app=self.app.id, min_version='1', max_version='2', min_app_version='3', max_app_version='4') @@ -2288,10 +2283,10 @@ class TestCompatOverride(amo.tests.TestCase): one = CompatOverride.objects.get(guid='one') # The default is incompatible. - c = CompatOverrideRange.objects.create(compat=one, app_id=1) + c = CompatOverrideRange.objects.create(compat=one, app=1) eq_(c.override_type(), 'incompatible') - c = CompatOverrideRange.objects.create(compat=one, app_id=1, type=0) + c = CompatOverrideRange.objects.create(compat=one, app=1, type=0) eq_(c.override_type(), 'compatible') def test_guid_match(self): @@ -2327,7 +2322,7 @@ class TestCompatOverride(amo.tests.TestCase): def test_collapsed_ranges_multiple_versions(self): c = CompatOverride.objects.get(guid='one') - CompatOverrideRange.objects.create(compat=c, app_id=1, + CompatOverrideRange.objects.create(compat=c, app=1, min_version='1', max_version='2', min_app_version='3', max_app_version='3.*') @@ -2347,7 +2342,7 @@ class TestCompatOverride(amo.tests.TestCase): # If the override ranges have different types they should be separate # entries. c = CompatOverride.objects.get(guid='one') - CompatOverrideRange.objects.create(compat=c, app_id=1, type=0, + CompatOverrideRange.objects.create(compat=c, app=1, type=0, min_app_version='3', max_app_version='3.*') r = c.collapsed_ranges() @@ -2377,7 +2372,7 @@ class TestCompatOverride(amo.tests.TestCase): def test_collapsed_ranges_multiple_versions_and_apps(self): c = CompatOverride.objects.get(guid='two') CompatOverrideRange.objects.create(min_version='5', max_version='6', - compat=c, app_id=1) + compat=c, app=1) r = c.collapsed_ranges() eq_(len(r), 2) @@ -2395,14 +2390,14 @@ class TestCompatOverride(amo.tests.TestCase): class TestIncompatibleVersions(amo.tests.TestCase): def setUp(self): - self.app = Application.objects.create(id=amo.FIREFOX.id) + self.app = amo.APP_IDS[amo.FIREFOX.id] self.addon = Addon.objects.create(guid='r@b', type=amo.ADDON_EXTENSION) def test_signals_min(self): eq_(IncompatibleVersions.objects.count(), 0) c = CompatOverride.objects.create(guid='r@b') - CompatOverrideRange.objects.create(compat=c, app=self.app, + CompatOverrideRange.objects.create(compat=c, app=self.app.id, min_version='0', max_version='1.0') @@ -2429,7 +2424,7 @@ class TestIncompatibleVersions(amo.tests.TestCase): eq_(IncompatibleVersions.objects.count(), 0) c = CompatOverride.objects.create(guid='r@b') - CompatOverrideRange.objects.create(compat=c, app=self.app, + CompatOverrideRange.objects.create(compat=c, app=self.app.id, min_version='1.0', max_version='*') diff --git a/apps/addons/tests/test_search.py b/apps/addons/tests/test_search.py index a502776dd6..86ccdb0032 100644 --- a/apps/addons/tests/test_search.py +++ b/apps/addons/tests/test_search.py @@ -7,7 +7,7 @@ from addons.search import extract class TestExtract(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): self.attrs = ('id', 'slug', 'app_slug', 'created', 'last_updated', diff --git a/apps/addons/tests/test_update.py b/apps/addons/tests/test_update.py index 6e5243dd60..86cd64e5cc 100644 --- a/apps/addons/tests/test_update.py +++ b/apps/addons/tests/test_update.py @@ -11,7 +11,7 @@ import amo.tests from addons.models import (Addon, CompatOverride, CompatOverrideRange, IncompatibleVersions) from amo.helpers import user_media_url -from applications.models import Application, AppVersion +from applications.models import AppVersion from files.models import File from services import update from versions.models import ApplicationsVersions, Version @@ -26,7 +26,7 @@ class VersionCheckMixin(object): class TestDataValidate(VersionCheckMixin, amo.tests.TestCase): - fixtures = ['base/addon_3615', 'base/apps', 'base/appversion'] + fixtures = ['base/addon_3615', 'base/appversion'] def setUp(self): super(TestDataValidate, self).setUp() @@ -94,7 +94,7 @@ class TestDataValidate(VersionCheckMixin, amo.tests.TestCase): class TestLookup(VersionCheckMixin, amo.tests.TestCase): - fixtures = ['addons/update', 'base/apps', 'base/appversion'] + fixtures = ['addons/update', 'base/appversion'] def setUp(self): super(TestLookup, self).setUp() @@ -102,7 +102,7 @@ class TestLookup(VersionCheckMixin, amo.tests.TestCase): self.platform = None self.version_int = 3069900200100 - self.app = Application.objects.get(id=1) + self.app = amo.APP_IDS[1] self.version_1_0_2 = 66463 self.version_1_1_3 = 90149 self.version_1_2_0 = 105387 @@ -384,7 +384,7 @@ class TestDefaultToCompat(VersionCheckMixin, amo.tests.TestCase): super(TestDefaultToCompat, self).setUp() self.addon = Addon.objects.get(id=337203) self.platform = None - self.app = Application.objects.get(id=1) + self.app = amo.APP_IDS[1] self.app_version_int_3_0 = 3000000200100 self.app_version_int_4_0 = 4000000200100 self.app_version_int_5_0 = 5000000200100 @@ -419,7 +419,7 @@ class TestDefaultToCompat(VersionCheckMixin, amo.tests.TestCase): co = CompatOverride.objects.create( name='test', guid=self.addon.guid, addon=self.addon ) - default = dict(compat=co, app=self.app, min_version='0', + default = dict(compat=co, app=self.app.id, min_version='0', max_version='*', min_app_version='0', max_app_version='*') default.update(kw) diff --git a/apps/addons/tests/test_views.py b/apps/addons/tests/test_views.py index 869527b93f..3e5c28ae74 100644 --- a/apps/addons/tests/test_views.py +++ b/apps/addons/tests/test_views.py @@ -71,7 +71,6 @@ def test_hovercards(self, doc, addons, src=''): class TestHomepage(amo.tests.TestCase): - fixtures = ['base/apps'] def setUp(self): self.base_url = reverse('home') @@ -96,8 +95,7 @@ class TestHomepage(amo.tests.TestCase): class TestHomepageFeatures(amo.tests.TestCase): - fixtures = ['base/apps', - 'base/appversion', + fixtures = ['base/appversion', 'base/users', 'base/addon_3615', 'base/collections', @@ -166,7 +164,7 @@ class TestPromobox(amo.tests.TestCase): class TestContributeInstalled(amo.tests.TestCase): - fixtures = ['base/apps', 'base/appversion', 'base/addon_592'] + fixtures = ['base/appversion', 'base/addon_592'] def setUp(self): self.addon = Addon.objects.get(pk=592) @@ -339,7 +337,7 @@ class TestContributeEmbedded(amo.tests.TestCase): class TestDeveloperPages(amo.tests.TestCase): - fixtures = ['base/addon_3615', 'base/addon_592', 'base/apps', + fixtures = ['base/addon_3615', 'base/addon_592', 'base/users', 'addons/eula+contrib-addon', 'addons/addon_228106_info+dev+bio.json', 'addons/addon_228107_multiple-devs.json'] @@ -483,8 +481,7 @@ class TestLicensePage(amo.tests.TestCase): class TestDetailPage(amo.tests.TestCase): - fixtures = ['base/apps', - 'base/addon_3615', + fixtures = ['base/addon_3615', 'base/users', 'base/addon_59', 'base/addon_4594_a9', @@ -823,7 +820,7 @@ class TestDetailPage(amo.tests.TestCase): class TestImpalaDetailPage(amo.tests.TestCase): - fixtures = ['base/addon_3615', 'base/addon_592', 'base/apps', 'base/users'] + fixtures = ['base/addon_3615', 'base/addon_592', 'base/users'] def setUp(self): self.addon = Addon.objects.get(id=3615) @@ -988,7 +985,7 @@ class TestImpalaDetailPage(amo.tests.TestCase): def test_categories(self): c = self.addon.all_categories[0] - c.application_id = amo.THUNDERBIRD.id + c.application = amo.THUNDERBIRD.id c.save() links = self.get_more_pq()('#related ul:first').find('a') expected = [(unicode(c.name), c.get_url_path()) for c in @@ -1185,7 +1182,7 @@ class TestEulaPolicyRedirects(amo.tests.TestCase): class TestEula(amo.tests.TestCase): - fixtures = ['base/apps', 'addons/eula+contrib-addon'] + fixtures = ['addons/eula+contrib-addon'] def setUp(self): self.addon = Addon.objects.get(id=11730) @@ -1300,7 +1297,7 @@ class TestXssOnName(amo.tests.TestCase): class TestPrivacyPolicy(amo.tests.TestCase): - fixtures = ['base/apps', 'addons/eula+contrib-addon'] + fixtures = ['addons/eula+contrib-addon'] def setUp(self): self.addon = Addon.objects.get(id=11730) @@ -1389,7 +1386,7 @@ class TestReportAbuse(amo.tests.TestCase): class TestMobile(amo.tests.MobileTest, amo.tests.TestCase): - fixtures = ['addons/featured', 'base/apps', 'base/users', + fixtures = ['addons/featured', 'base/users', 'base/addon_3615', 'base/featured', 'bandwagon/featured_collections'] diff --git a/apps/addons/utils.py b/apps/addons/utils.py index 4a12e303e3..e57f87e341 100644 --- a/apps/addons/utils.py +++ b/apps/addons/utils.py @@ -35,7 +35,7 @@ def get_featured_ids(app, lang=None, type=None): from addons.models import Addon ids = [] is_featured = (Q(collections__featuredcollection__isnull=False) & - Q(collections__featuredcollection__application__id=app.id)) + Q(collections__featuredcollection__application=app.id)) qs = Addon.objects.all() if type: diff --git a/apps/addons/views.py b/apps/addons/views.py index 2cf93bce15..79fc5bbcb3 100644 --- a/apps/addons/views.py +++ b/apps/addons/views.py @@ -116,7 +116,7 @@ def extension_detail(request, addon): # Popular collections this addon is part of. collections = Collection.objects.listed().filter( - addons=addon, application__id=request.APP.id) + addons=addon, application=request.APP.id) ctx = { 'addon': addon, diff --git a/apps/amo/fixtures/base/addon_3615.json b/apps/amo/fixtures/base/addon_3615.json index a72878554a..63ea7538ef 100644 --- a/apps/amo/fixtures/base/addon_3615.json +++ b/apps/amo/fixtures/base/addon_3615.json @@ -1,13 +1,4 @@ [ - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 418039, "model": "translations.translation", diff --git a/apps/amo/fixtures/base/apps.json b/apps/amo/fixtures/base/apps.json deleted file mode 100644 index 7a13086d39..0000000000 --- a/apps/amo/fixtures/base/apps.json +++ /dev/null @@ -1,56 +0,0 @@ -[ - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 60, - "model": "applications.application", - "fields": { - "guid": "{a23983c0-fd0e-11dc-95ff-0800200c9a66}", - "modified": "2008-10-28 18:25:09", - "created": "2008-10-28 18:25:09" - } - }, - { - "pk": 61, - "model": "applications.application", - "fields": { - "guid": "{aa3c5121-dab2-40e2-81ca-7ea25febc110}", - "modified": "2008-10-28 18:25:09", - "created": "2008-10-28 18:25:09" - } - }, - { - "pk": 59, - "model": "applications.application", - "fields": { - "guid": "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}", - "modified": "2008-06-17 08:29:01", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 18, - "model": "applications.application", - "fields": { - "guid": "{3550f703-e582-4d05-9a08-453d09bdfdc6}", - "modified": "2006-08-21 23:53:19", - "created": "2006-08-21 23:53:19" - } - }, - { - "pk": 2, - "model": "applications.application", - "fields": { - "guid": "{86c18b42-e466-45a9-ae7a-9b95ba6f5640}", - "modified": "2006-08-21 23:53:19", - "created": "2006-08-21 23:53:19" - } - } -] diff --git a/apps/amo/fixtures/base/appversion.json b/apps/amo/fixtures/base/appversion.json index df673a3bee..baeea86879 100644 --- a/apps/amo/fixtures/base/appversion.json +++ b/apps/amo/fixtures/base/appversion.json @@ -1,13 +1,4 @@ [ - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 86, "model": "applications.appversion", diff --git a/apps/amo/fixtures/base/category.json b/apps/amo/fixtures/base/category.json index 82863a8a11..667201f6f4 100644 --- a/apps/amo/fixtures/base/category.json +++ b/apps/amo/fixtures/base/category.json @@ -32,15 +32,6 @@ "localized_string": "Extension" } }, - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 1118, "model": "translations.translation", diff --git a/apps/amo/fixtures/base/collection_57181.json b/apps/amo/fixtures/base/collection_57181.json index 9ab6ce1f10..f72cc14562 100644 --- a/apps/amo/fixtures/base/collection_57181.json +++ b/apps/amo/fixtures/base/collection_57181.json @@ -24,15 +24,6 @@ "notifyevents": true } }, - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 906021, "model": "translations.translation", diff --git a/apps/amo/fixtures/base/featured.json b/apps/amo/fixtures/base/featured.json index 7ee56285fa..a3ac1dfbfe 100644 --- a/apps/amo/fixtures/base/featured.json +++ b/apps/amo/fixtures/base/featured.json @@ -10,15 +10,6 @@ "id": 590910 } }, - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 15679, "model": "addons.addon", diff --git a/apps/amo/fixtures/base/seamonkey.json b/apps/amo/fixtures/base/seamonkey.json index 63f57513d7..8f3e31bc95 100644 --- a/apps/amo/fixtures/base/seamonkey.json +++ b/apps/amo/fixtures/base/seamonkey.json @@ -133,24 +133,6 @@ "size": 173056 } }, - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 59, - "model": "applications.application", - "fields": { - "guid": "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}", - "modified": "2008-06-17 08:29:01", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 84, "model": "addons.feature", diff --git a/apps/amo/fixtures/base/thunderbird.json b/apps/amo/fixtures/base/thunderbird.json index b3eafdc170..a80c7e98e6 100644 --- a/apps/amo/fixtures/base/thunderbird.json +++ b/apps/amo/fixtures/base/thunderbird.json @@ -1,13 +1,4 @@ [ - { - "pk": 18, - "model": "applications.application", - "fields": { - "guid": "{3550f703-e582-4d05-9a08-453d09bdfdc6}", - "modified": "2008-06-17 08:29:00", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 298, "model": "applications.appversion", diff --git a/apps/amo/tests/__init__.py b/apps/amo/tests/__init__.py index ab0cfdabf0..4df686eb5d 100644 --- a/apps/amo/tests/__init__.py +++ b/apps/amo/tests/__init__.py @@ -44,7 +44,7 @@ from addons.models import (Addon, Persona, update_search_index as addon_update_search_index) from addons.tasks import unindex_addons from amo.urlresolvers import get_url_prefix, Prefixer, reverse, set_url_prefix -from applications.models import Application, AppVersion +from applications.models import AppVersion from bandwagon.models import Collection from files.models import File from lib.es.signals import process, reset @@ -633,7 +633,7 @@ def addon_factory(status=amo.STATUS_PUBLIC, version_kw={}, file_kw={}, **kw): def collection_factory(**kw): data = { 'type': amo.COLLECTION_NORMAL, - 'application_id': amo.FIREFOX.id, + 'application': amo.FIREFOX.id, 'name': 'Collection %s' % abs(hash(datetime.now())), 'addon_count': random.randint(200, 2000), 'subscribers': random.randint(1000, 5000), @@ -702,13 +702,13 @@ def version_factory(file_kw={}, **kw): v.created = v.last_updated = _get_created(kw.pop('created', 'now')) v.save() if kw.get('addon').type != amo.ADDON_PERSONA: - a, _ = Application.objects.get_or_create(id=amo.FIREFOX.id) - av_min, _ = AppVersion.objects.get_or_create(application=a, + av_min, _ = AppVersion.objects.get_or_create(application=amo.FIREFOX.id, version=min_app_version) - av_max, _ = AppVersion.objects.get_or_create(application=a, + av_max, _ = AppVersion.objects.get_or_create(application=amo.FIREFOX.id, version=max_app_version) - ApplicationsVersions.objects.get_or_create(application=a, version=v, - min=av_min, max=av_max) + ApplicationsVersions.objects.get_or_create(application=amo.FIREFOX.id, + version=v, min=av_min, + max=av_max) file_factory(version=v, **file_kw) return v diff --git a/apps/amo/tests/test_models.py b/apps/amo/tests/test_models.py index 74ee66b917..08e820842f 100644 --- a/apps/amo/tests/test_models.py +++ b/apps/amo/tests/test_models.py @@ -10,8 +10,7 @@ from addons.models import Addon class ManualOrderTest(TestCase): - fixtures = ('base/apps', 'base/addon_3615', 'base/addon_5299_gcal', - 'base/addon_40') + fixtures = ('base/addon_3615', 'base/addon_5299_gcal', 'base/addon_40') def test_ordering(self): """Given a specific set of primary keys, assure that we return addons diff --git a/apps/amo/tests/test_redirects.py b/apps/amo/tests/test_redirects.py index ae0d4e538b..3718bdfefc 100644 --- a/apps/amo/tests/test_redirects.py +++ b/apps/amo/tests/test_redirects.py @@ -5,14 +5,12 @@ from nose.tools import eq_ import amo import amo.tests from addons.models import Category -from applications.models import Application from django.db import connection class TestRedirects(amo.tests.TestCase): - fixtures = ['base/apps', 'reviews/test_models', - 'addons/persona', 'base/global-stats'] + fixtures = ['reviews/test_models', 'addons/persona', 'base/global-stats'] def test_persona_category(self): """`/personas/film and tv` should go to /themes/film-and-tv""" @@ -144,9 +142,8 @@ class TestRedirects(amo.tests.TestCase): self.assert3xx(r, '/en-US/firefox/extensions/', status_code=301) - a = Application.objects.create() Category.objects.create(pk=12, slug='woo', type=amo.ADDON_EXTENSION, - application=a, count=1, weight=0) + application=amo.FIREFOX.id, count=1, weight=0) r = self.client.get('/browse/type:1/cat:12?sort=averagerating', follow=True) url, code = r.redirect_chain[-1] diff --git a/apps/amo/tests/test_views.py b/apps/amo/tests/test_views.py index 86a6cf1897..9758adb0a1 100644 --- a/apps/amo/tests/test_views.py +++ b/apps/amo/tests/test_views.py @@ -61,8 +61,7 @@ class Test404(amo.tests.TestCase): class TestCommon(amo.tests.TestCase): - fixtures = ('base/users', 'base/global-stats', 'base/configs', - 'base/addon_3615') + fixtures = ('base/users', 'base/global-stats', 'base/addon_3615') def setUp(self): self.url = reverse('home') diff --git a/apps/amo/utils.py b/apps/amo/utils.py index 6549e72240..901bf6cb08 100644 --- a/apps/amo/utils.py +++ b/apps/amo/utils.py @@ -314,7 +314,7 @@ class JSONEncoder(json.DjangoJSONEncoder): if isinstance(obj, unicodable): return unicode(obj) if isinstance(obj, ApplicationsVersions): - return {unicode(obj.application): {'min': unicode(obj.min), + return {unicode(amo.APP_IDS[obj.application].pretty): {'min': unicode(obj.min), 'max': unicode(obj.max)}} return super(JSONEncoder, self).default(obj) diff --git a/apps/api/templates/api/includes/addon.xml b/apps/api/templates/api/includes/addon.xml index 5b3b50222b..1755e7c7fe 100644 --- a/apps/api/templates/api/includes/addon.xml +++ b/apps/api/templates/api/includes/addon.xml @@ -46,13 +46,13 @@ {%- if version -%} {%- for app in version.compatible_apps.values() %} - {%- if amo.APP_IDS.get(app.application_id) -%} + {%- if amo.APP_IDS.get(app.application) -%} - {{ amo.APP_IDS[app.application_id].pretty }} - {{ app.application_id }} + {{ amo.APP_IDS[app.application].pretty }} + {{ app.application }} {{ app.min }} {{ app.max }} - {{ amo.APP_IDS[app.application_id].guid }} + {{ amo.APP_IDS[app.application].guid }} {%- endif -%} {%- endfor -%} diff --git a/apps/api/tests/test_oauth.py b/apps/api/tests/test_oauth.py index c05e033bc5..6336c070b2 100644 --- a/apps/api/tests/test_oauth.py +++ b/apps/api/tests/test_oauth.py @@ -182,7 +182,7 @@ def get_access_token(consumer, token, authorize=True, verifier=None): class BaseOAuth(TestCase): - fixtures = ['base/users', 'base/apps', 'base/appversion', 'base/licenses'] + fixtures = ['base/users', 'base/appversion', 'base/licenses'] def setUp(self): self.editor = UserProfile.objects.get(email='editor@mozilla.com') diff --git a/apps/api/tests/test_views.py b/apps/api/tests/test_views.py index 62fed014b4..2c5451c42e 100644 --- a/apps/api/tests/test_views.py +++ b/apps/api/tests/test_views.py @@ -22,7 +22,7 @@ from amo.urlresolvers import reverse from amo.views import handler500 from api.utils import addon_to_dict from api.views import addon_filter -from applications.models import Application, AppVersion +from applications.models import AppVersion from bandwagon.models import Collection, CollectionAddon, FeaturedCollection from files.models import File from files.tests.test_models import UploadTest @@ -181,7 +181,7 @@ class StripHTMLTest(TestCase): class APITest(TestCase): - fixtures = ['base/apps', 'base/addon_3615', 'base/addon_4664_twitterbar', + fixtures = ['base/addon_3615', 'base/addon_4664_twitterbar', 'base/addon_5299_gcal', 'perf/index'] def test_api_caching(self): @@ -506,9 +506,8 @@ class APITest(TestCase): c = CollectionAddon.objects.create( addon=Addon.objects.get(id=5299), collection=Collection.objects.create()) - FeaturedCollection.objects.create(locale='ja', - application=Application.objects.get(id=amo.FIREFOX.id), - collection=c.collection) + FeaturedCollection.objects.create( + locale='ja', application=amo.FIREFOX.id, collection=c.collection) for lang, app, result in [('ja', 'firefox', 1), ('en-US', 'firefox', 0), ('ja', 'seamonkey', 0)]: @@ -594,7 +593,7 @@ class DRFAPITest(DRFMixin, APITest): class ListTest(TestCase): """Tests the list view with various urls.""" - fixtures = ['base/apps', 'base/users', 'base/addon_3615', 'base/featured', + fixtures = ['base/users', 'base/addon_3615', 'base/featured', 'addons/featured', 'bandwagon/featured_collections', 'base/collections'] @@ -694,7 +693,7 @@ class DRFListTest(DRFMixin, ListTest): class AddonFilterTest(TestCase): """Tests the addon_filter, including the various d2c cases.""" - fixtures = ['base/apps', 'base/appversion'] + fixtures = ['base/appversion'] def setUp(self): # Start with 2 compatible add-ons. @@ -784,7 +783,7 @@ class AddonFilterTest(TestCase): # Add override for this add-on. compat = CompatOverride.objects.create(guid='three', addon=addon3) CompatOverrideRange.objects.create( - compat=compat, app=Application.objects.get(pk=1), + compat=compat, app=1, min_version=addon3.current_version.version, max_version='*') addons = addon_filter(**self._defaults(addons=addons, version='11.0', @@ -818,7 +817,7 @@ class SeamonkeyFeaturedTest(TestCase): class TestGuidSearch(TestCase): - fixtures = ('base/apps', 'base/addon_6113', 'base/addon_3615') + fixtures = ('base/addon_6113', 'base/addon_3615') # These are the guids for addon 6113 and 3615. good = ('search/guid:{22870005-adef-4c9d-ae36-d0e1f2f27e5a},' '{2fa4ed95-0317-4c6a-a74c-5f3e3912c1f9}') @@ -827,7 +826,7 @@ class TestGuidSearch(TestCase): addon = Addon.objects.get(id=3615) c = CompatOverride.objects.create(guid=addon.guid) app = addon.compatible_apps.keys()[0] - CompatOverrideRange.objects.create(compat=c, app_id=app.id) + CompatOverrideRange.objects.create(compat=c, app=app.id) def test_success(self): r = make_call(self.good) @@ -900,7 +899,7 @@ class TestGuidSearch(TestCase): def test_addon_compatibility_not_hosted(self): c = CompatOverride.objects.create(guid='yeah', name='ok') - CompatOverrideRange.objects.create(app_id=1, compat=c, + CompatOverrideRange.objects.create(app=1, compat=c, min_version='1', max_version='2', min_app_version='3', max_app_version='4') @@ -926,7 +925,7 @@ class TestGuidSearch(TestCase): class SearchTest(ESTestCase): - fixtures = ('base/apps', 'base/appversion', + fixtures = ('base/appversion', 'base/addon_6113', 'base/addon_40', 'base/addon_3615', 'base/addon_6704_grapple', 'base/addon_4664_twitterbar', 'base/addon_10423_youtubesearch', 'base/featured') @@ -1154,11 +1153,10 @@ class SearchTest(ESTestCase): def test_compat_mode_normal_max_version(self): # We ignore versions that don't qualify for d2c by not having the # minimum maxVersion support (e.g. Firefox >= 4.0). - app = Application.objects.get(id=1) - fx30 = AppVersion.objects.get(application=app, version="3.0") - fx35 = AppVersion.objects.get(application=app, version="3.5") + fx30 = AppVersion.objects.get(application=1, version="3.0") + fx35 = AppVersion.objects.get(application=1, version="3.5") addon = Addon.objects.get(pk=3615) - av = addon.current_version.apps.filter(application=app)[0] + av = addon.current_version.apps.filter(application=1)[0] av.min = fx30 av.max = fx35 av.save() @@ -1192,10 +1190,9 @@ class SearchTest(ESTestCase): self.assertContains(response, 'Delicious Bookmarks') # Make add-on have a compat override. - app = Application.objects.get(id=1) co = CompatOverride.objects.create(name='test', guid=addon.guid, addon=addon) - CompatOverrideRange.objects.create(compat=co, app=app, + CompatOverrideRange.objects.create(compat=co, app=1, min_version='0', max_version='*', min_app_version='0', @@ -1272,7 +1269,7 @@ class DRFSearchTest(DRFMixin, SearchTest): class LanguagePacks(UploadTest): - fixtures = ['addons/listed', 'base/apps'] + fixtures = ['addons/listed'] def setUp(self): self.url = reverse('api.language', args=['1.5']) @@ -1293,7 +1290,7 @@ class LanguagePacks(UploadTest): def test_search_app(self): self.addon.update(type=amo.ADDON_LPAPP, status=amo.STATUS_PUBLIC) - AppSupport.objects.create(addon=self.addon, app_id=amo.THUNDERBIRD.id) + AppSupport.objects.create(addon=self.addon, app=amo.THUNDERBIRD.id) res = self.client.get(self.tb_url) self.assertContains(res, "{835A3F80-DF39") diff --git a/apps/api/utils.py b/apps/api/utils.py index 2a17b944ed..1d5027ac76 100644 --- a/apps/api/utils.py +++ b/apps/api/utils.py @@ -105,7 +105,7 @@ def extract_from_query(term, filter, regexp, end_of_word_boundary=True): return (term, value) -def extract_filters(term, app_id=amo.FIREFOX.id, opts=None): +def extract_filters(term, opts=None): """ Pulls all the filtering options out of the term and returns a cleaned term and a dictionary of filter names and filter values. Term filters override @@ -139,15 +139,6 @@ def extract_filters(term, app_id=amo.FIREFOX.id, opts=None): term, version = extract_from_query(term, 'version', '[0-9.]+') params['version'] = version or opts.get('version') - # Category filters. - term, category = extract_from_query(term, 'category', '\w+') - if category and 'app' in opts: - category = (Category.objects.filter(slug__istartswith=category, - application=opts['app']) - .values_list('id', flat=True)) - if category: - filters['category'] = category[0] - # Tag filters. term, tag = extract_from_query(term, 'tag', '\w+') if tag: diff --git a/apps/api/views.py b/apps/api/views.py index 4c9ecb88ec..ada317042a 100644 --- a/apps/api/views.py +++ b/apps/api/views.py @@ -353,8 +353,7 @@ class SearchView(APIView): # This fails if the string is already UTF-8. pass - query, qs_filters, params = extract_filters(query, filters['app'], - opts) + query, qs_filters, params = extract_filters(query, opts) qs = Addon.search().query(or_=name_query(query)) filters.update(qs_filters) diff --git a/apps/api/views_drf.py b/apps/api/views_drf.py index a592c3cd97..ce1d9c9539 100644 --- a/apps/api/views_drf.py +++ b/apps/api/views_drf.py @@ -200,8 +200,7 @@ class SearchView(DRFView): # This fails if the string is already UTF-8. pass - query, qs_filters, params = extract_filters(query, filters['app'], - opts) + query, qs_filters, params = extract_filters(query, opts) qs = Addon.search().query(or_=name_query(query)) filters.update(qs_filters) diff --git a/apps/applications/fixtures/applications/all_apps.json b/apps/applications/fixtures/applications/all_apps.json deleted file mode 100644 index 11f53ba93e..0000000000 --- a/apps/applications/fixtures/applications/all_apps.json +++ /dev/null @@ -1,56 +0,0 @@ -[ - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 2, - "model": "applications.application", - "fields": { - "guid": "{86c18b42-e466-45a9-ae7a-9b95ba6f5640}", - "modified": "2008-11-03 15:35:00", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 18, - "model": "applications.application", - "fields": { - "guid": "{3550f703-e582-4d05-9a08-453d09bdfdc6}", - "modified": "2008-06-17 08:29:00", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 59, - "model": "applications.application", - "fields": { - "guid": "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}", - "modified": "2008-06-17 08:29:01", - "created": "2007-03-05 13:09:26" - } - }, - { - "pk": 60, - "model": "applications.application", - "fields": { - "guid": "{a23983c0-fd0e-11dc-95ff-0800200c9a66}", - "modified": "2008-10-28 18:25:09", - "created": "2008-10-28 18:25:09" - } - }, - { - "pk": 61, - "model": "applications.application", - "fields": { - "guid": "{aa3c5121-dab2-40e2-81ca-7ea25febc110}", - "modified": "2008-10-28 18:25:09", - "created": "2008-10-28 18:25:09" - } - } -] diff --git a/apps/applications/management/commands/addnewversion.py b/apps/applications/management/commands/addnewversion.py index 8276396452..b74ea10b56 100644 --- a/apps/applications/management/commands/addnewversion.py +++ b/apps/applications/management/commands/addnewversion.py @@ -8,7 +8,7 @@ from applications.models import AppVersion class Command(BaseCommand): - help = ('Add a new version to a Application. Syntax: \n' + help = ('Add a new version of an application. Syntax: \n' ' ./manage.py addnewversion ') log = commonware.log.getLogger('z.appversions') diff --git a/apps/applications/management/commands/dump_apps.py b/apps/applications/management/commands/dump_apps.py index 875b21da69..f462306718 100644 --- a/apps/applications/management/commands/dump_apps.py +++ b/apps/applications/management/commands/dump_apps.py @@ -6,7 +6,7 @@ from django.core.management.base import BaseCommand from django.core.files.storage import default_storage as storage import commonware.log import amo -from applications.models import Application, AppVersion +from applications.models import AppVersion log = commonware.log.getLogger('z.cron') @@ -20,9 +20,8 @@ class Command(BaseCommand): def handle(self, *args, **kw): apps = {} - for id, guid in (Application.objects - .supported().values_list('id', 'guid')): - apps[id] = dict(guid=guid, versions=[], + for id, app in amo.APP_IDS.iteritems(): + apps[id] = dict(guid=app.guid, versions=[], name=amo.APPS_ALL[id].short) versions = (AppVersion.objects.values_list('application', 'version') .order_by('version_int')) diff --git a/apps/applications/models.py b/apps/applications/models.py index 6ead8e3f5c..9fede19363 100644 --- a/apps/applications/models.py +++ b/apps/applications/models.py @@ -30,7 +30,7 @@ class Application(amo.models.ModelBase): class AppVersion(amo.models.ModelBase): - application = models.ForeignKey(Application) + application = models.PositiveIntegerField(db_column='application_id') version = models.CharField(max_length=255, default='') version_int = models.BigIntegerField(editable=False) diff --git a/apps/applications/tests.py b/apps/applications/tests.py index e8f8d2d286..8621826b9c 100644 --- a/apps/applications/tests.py +++ b/apps/applications/tests.py @@ -7,7 +7,7 @@ from nose.tools import eq_ import amo import amo.tests from amo.helpers import url -from applications.models import AppVersion, Application +from applications.models import AppVersion from applications.management.commands import dump_apps @@ -39,39 +39,14 @@ class TestAppVersion(amo.tests.TestCase): def test_unique_together_application_version(self): """Check that one can't add duplicate application-version pairs.""" - app = Application.objects.create(guid='foobar') - AppVersion.objects.create(application=app, version='123') + AppVersion.objects.create(application=1, version='123') with self.assertRaises(IntegrityError): - AppVersion.objects.create(application=app, version='123') - - -class TestApplication(amo.tests.TestCase): - fixtures = ['applications/all_apps.json'] - - def test_string_representation(self): - """ - Check that the string representation of the app model instances - matches out constants - """ - for static_app in amo.APP_USAGE: - model_app = Application.objects.get(id=static_app.id) - eq_(unicode(model_app), unicode(static_app.pretty)) - - -class TestApplicationManager(amo.tests.TestCase): - fixtures = ['applications/all_apps.json'] - - def test_default_manager(self): - eq_(Application.objects.count(), 6) - - def test_supported(self): - Application.objects.latest('pk').update(supported=False) - eq_(Application.objects.supported().count(), 5) + AppVersion.objects.create(application=1, version='123') class TestViews(amo.tests.TestCase): - fixtures = ['base/apps', 'base/appversion'] + fixtures = ['base/appversion'] def test_appversions(self): eq_(self.client.get(url('apps.appversions')).status_code, 200) @@ -81,20 +56,17 @@ class TestViews(amo.tests.TestCase): class TestCommands(amo.tests.TestCase): - fixtures = ['applications/all_apps.json', 'base/apps', 'base/appversion'] + fixtures = ['base/appversion'] def test_dump_apps(self): call_command('dump_apps') with open(dump_apps.Command.JSON_PATH, 'r') as f: apps = json.load(f) - db_apps = Application.objects.all() - assert len(db_apps) - for app in db_apps: + for idx, app in amo.APP_IDS.iteritems(): data = apps[str(app.id)] versions = sorted([a.version for a in - AppVersion.objects.filter(application=app)]) - r_app = amo.APPS_ALL[app.id] - eq_("%s: %r" % (r_app.short, sorted(data['versions'])), - "%s: %r" % (r_app.short, versions)) - eq_(data['name'], r_app.short) + AppVersion.objects.filter(application=app.id)]) + eq_("%s: %r" % (app.short, sorted(data['versions'])), + "%s: %r" % (app.short, versions)) + eq_(data['name'], app.short) eq_(data['guid'], app.guid) diff --git a/apps/bandwagon/fixtures/bandwagon/test_models.json b/apps/bandwagon/fixtures/bandwagon/test_models.json index 3544242f8c..ff2329be94 100644 --- a/apps/bandwagon/fixtures/bandwagon/test_models.json +++ b/apps/bandwagon/fixtures/bandwagon/test_models.json @@ -1,13 +1,4 @@ [ - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 434742, "model": "translations.translation", diff --git a/apps/bandwagon/forms.py b/apps/bandwagon/forms.py index ff4deb0615..e6d4fbe33a 100644 --- a/apps/bandwagon/forms.py +++ b/apps/bandwagon/forms.py @@ -35,7 +35,7 @@ class AdminForm(Form): def save(self, collection): collection.type = self.cleaned_data['type'] - collection.application_id = self.cleaned_data['application'] + collection.application = self.cleaned_data['application'] collection.save() @@ -188,7 +188,7 @@ class CollectionForm(ModelForm): def save(self, default_locale=None): c = super(CollectionForm, self).save(commit=False) c.author = self.initial['author'] - c.application_id = self.initial['application_id'] + c.application = self.initial['application'] icon = self.cleaned_data.get('icon') if default_locale: diff --git a/apps/bandwagon/models.py b/apps/bandwagon/models.py index 2116e8dff3..db26f3e4d5 100644 --- a/apps/bandwagon/models.py +++ b/apps/bandwagon/models.py @@ -20,7 +20,6 @@ from addons.models import Addon, AddonRecommendation from amo.helpers import absolutify, user_media_path, user_media_url from amo.urlresolvers import reverse from amo.utils import sorted_groupby -from applications.models import Application from stats.models import CollectionShareCountTotal from translations.fields import (LinkifiedField, save_signal, NoLinksNoMarkupField, TranslatedField) @@ -120,7 +119,8 @@ class Collection(CollectionBase, amo.models.ModelBase): downloads = models.PositiveIntegerField(default=0) weekly_subscribers = models.PositiveIntegerField(default=0) monthly_subscribers = models.PositiveIntegerField(default=0) - application = models.ForeignKey(Application, null=True) + application = models.PositiveIntegerField(db_column='application_id', + null=True) addon_count = models.PositiveIntegerField(default=0, db_column='addonCount') @@ -587,7 +587,7 @@ class RecommendedCollection(Collection): class FeaturedCollection(amo.models.ModelBase): - application = models.ForeignKey(Application) + application = models.PositiveIntegerField(db_column='application_id') collection = models.ForeignKey(Collection) locale = models.CharField(max_length=10, null=True) diff --git a/apps/bandwagon/search.py b/apps/bandwagon/search.py index f6db89800b..e981434ef3 100644 --- a/apps/bandwagon/search.py +++ b/apps/bandwagon/search.py @@ -8,9 +8,9 @@ import amo def extract(collection): attrs = ('id', 'created', 'modified', 'slug', 'author_username', 'subscribers', 'weekly_subscribers', 'monthly_subscribers', - 'rating', 'listed', 'type', 'application_id') + 'rating', 'listed', 'type', 'application') d = dict(zip(attrs, attrgetter(*attrs)(collection))) - d['app'] = d.pop('application_id') + d['app'] = d.pop('application') d['name_sort'] = unicode(collection.name).lower() translations = collection.translations d['name'] = list(set(string for _, string diff --git a/apps/bandwagon/tests/test_views.py b/apps/bandwagon/tests/test_views.py index e3ee180f87..57e05d1e2e 100644 --- a/apps/bandwagon/tests/test_views.py +++ b/apps/bandwagon/tests/test_views.py @@ -348,8 +348,7 @@ class TestVotes(amo.tests.TestCase): class TestCRUD(amo.tests.TestCase): """Test the collection form.""" - fixtures = ('base/apps', 'base/users', 'base/addon_3615', - 'base/collections') + fixtures = ('base/users', 'base/addon_3615', 'base/collections') def setUp(self): self.client = HappyUnicodeClient() @@ -663,7 +662,7 @@ class TestCRUD(amo.tests.TestCase): url = reverse('collections.edit_contributors', args=['admin', self.slug]) r = self.client.post(url, {'contributor': 999, - 'application_id': 1, + 'application': 1, 'type': 1}, follow=True) doc = pq(r.content)('.success') @@ -764,7 +763,7 @@ class TestCRUD(amo.tests.TestCase): url = reverse('collections.edit_contributors', args=['admin', self.slug]) self.client.post(url, - {'contributor': 999, 'application_id': 1, 'type': 1}, + {'contributor': 999, 'application': 1, 'type': 1}, follow=True) url = reverse('collections.edit', args=['admin', self.slug]) @@ -921,7 +920,7 @@ class TestChangeAddon(amo.tests.TestCase): class AjaxTest(amo.tests.TestCase): - fixtures = ('base/apps', 'base/users', 'base/addon_3615', + fixtures = ('base/users', 'base/addon_3615', 'base/addon_5299_gcal', 'base/collections') def setUp(self): @@ -1058,7 +1057,7 @@ class TestCollectionFeed(TestFeeds): class TestCollectionListing(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615', 'base/category', + fixtures = ['base/users', 'base/addon_3615', 'base/category', 'base/featured', 'addons/featured', 'addons/listed', 'base/collections', 'bandwagon/featured_collections'] @@ -1224,7 +1223,7 @@ class TestCollectionForm(amo.tests.TestCase): instance=collection, files={'icon': get_uploaded_file('transparent.png')}, initial={'author': collection.author, - 'application_id': collection.application.pk}) + 'application': collection.application}) assert form.is_valid() form.save() assert update_mock.called diff --git a/apps/bandwagon/views.py b/apps/bandwagon/views.py index f6c2033fa2..a546f7c349 100644 --- a/apps/bandwagon/views.py +++ b/apps/bandwagon/views.py @@ -294,7 +294,7 @@ def collection_vote(request, username, slug, direction): def initial_data_from_request(request): - return dict(author=request.amo_user, application_id=request.APP.id) + return dict(author=request.amo_user, application=request.APP.id) def collection_message(request, collection, option): @@ -346,7 +346,7 @@ def add(request): def ajax_new(request): form = forms.CollectionForm(request.POST or None, initial={'author': request.amo_user, - 'application_id': request.APP.id}, + 'application': request.APP.id}, ) if request.method == 'POST' and form.is_valid(): @@ -448,7 +448,7 @@ def edit(request, collection, username, slug): if is_admin: initial = dict(type=collection.type, - application=collection.application_id) + application=collection.application) admin_form = forms.AdminForm(initial=initial) else: admin_form = None diff --git a/apps/browse/fixtures/browse/test_views.json b/apps/browse/fixtures/browse/test_views.json index 48255f5a4a..e6d63a1621 100644 --- a/apps/browse/fixtures/browse/test_views.json +++ b/apps/browse/fixtures/browse/test_views.json @@ -10,15 +10,6 @@ "localized_string": "Walloon Language Pack" } }, - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 267, "model": "applications.appversion", diff --git a/apps/browse/tests.py b/apps/browse/tests.py index accd202ad4..d42083a698 100644 --- a/apps/browse/tests.py +++ b/apps/browse/tests.py @@ -23,7 +23,6 @@ from amo.helpers import absolutify, numberfmt, urlparams from addons.tests.test_views import TestMobile from addons.models import (Addon, AddonCategory, Category, AppSupport, Feature, FrozenAddon, Persona) -from applications.models import Application from bandwagon.models import Collection, CollectionAddon, FeaturedCollection from browse import feeds from browse.views import (AddonFilter, locale_display_name, @@ -127,7 +126,7 @@ class TestESExtensions(ExtensionTestCase): # Stick one add-on in a category, make sure search finds it. addon = Addon.objects.filter(status=amo.STATUS_PUBLIC, disabled_by_user=False)[0] - c = Category.objects.create(application_id=amo.FIREFOX.id, + c = Category.objects.create(application=amo.FIREFOX.id, slug='alerts', type=addon.type) AddonCategory.objects.create(category=c, addon=addon) addon.save() @@ -159,7 +158,7 @@ def test_locale_display_name(): class TestListing(amo.tests.TestCase): - fixtures = ['base/apps', 'base/appversion', 'base/users', 'base/category', + fixtures = ['base/appversion', 'base/users', 'base/category', 'base/featured', 'addons/featured', 'addons/listed', 'base/collections', 'bandwagon/featured_collections', 'base/addon_3615'] @@ -394,7 +393,7 @@ class TestThemes(amo.tests.TestCase): class TestFeeds(amo.tests.TestCase): - fixtures = ['base/apps', 'base/appversion', 'base/users', 'base/category', + fixtures = ['base/appversion', 'base/users', 'base/category', 'base/featured', 'addons/featured', 'addons/listed', 'base/collections', 'bandwagon/featured_collections', 'base/addon_3615'] @@ -486,7 +485,7 @@ class TestFeeds(amo.tests.TestCase): class TestFeaturedLocale(amo.tests.TestCase): - fixtures = ['base/apps', 'base/appversion', 'base/category', 'base/users', + fixtures = ['base/appversion', 'base/category', 'base/users', 'base/addon_3615', 'base/featured', 'addons/featured', 'browse/nameless-addon', 'base/collections', 'bandwagon/featured_collections', @@ -654,7 +653,7 @@ class TestFeaturedLocale(amo.tests.TestCase): for pk in [1003, 3481]: addon = Addon.objects.get(pk=pk) addon.update(status=amo.STATUS_PUBLIC) - addon.appsupport_set.create(app_id=1) + addon.appsupport_set.create(app=1) # Note 1003 and 3481 are now en-US. # And 7661 and 2464 are now None. @@ -695,7 +694,7 @@ class TestFeaturedLocale(amo.tests.TestCase): def test_featured_duplicated(self): another = Addon.objects.get(id=1003) self.change_addon(another, 'en-US') - another.feature_set.create(application_id=amo.FIREFOX.id, + another.feature_set.create(application=amo.FIREFOX.id, locale=None, start=datetime.today(), end=datetime.today()) @@ -704,7 +703,7 @@ class TestFeaturedLocale(amo.tests.TestCase): def change_addon(self, addon, locale='es'): fc = FeaturedCollection.objects.filter(collection__addons=addon.id)[0] feature = FeaturedCollection.objects.create(locale=locale, - application=Application.objects.get(id=amo.FIREFOX.id), + application=amo.FIREFOX.id, collection=Collection.objects.create()) c = CollectionAddon.objects.filter(addon=addon, collection=fc.collection)[0] @@ -719,13 +718,13 @@ class TestFeaturedLocale(amo.tests.TestCase): c = CollectionAddon.objects.create(addon=addon, collection=Collection.objects.create()) FeaturedCollection.objects.create(locale=locale, - application=Application.objects.get(id=amo.FIREFOX.id), + application=amo.FIREFOX.id, collection=c.collection) self.reset() class TestListingByStatus(amo.tests.TestCase): - fixtures = ['base/apps', 'base/addon_3615'] + fixtures = ['base/addon_3615'] def setUp(self): self.addon = Addon.objects.get(id=3615) @@ -787,7 +786,7 @@ class TestListingByStatus(amo.tests.TestCase): class BaseSearchToolsTest(amo.tests.TestCase): - fixtures = ('base/apps', 'base/appversion', 'base/featured', + fixtures = ('base/appversion', 'base/featured', 'addons/featured', 'base/category', 'addons/listed') def setUp(self): @@ -818,7 +817,7 @@ class BaseSearchToolsTest(amo.tests.TestCase): # Feature foxy : foxy = Addon.objects.get(name__localized_string='FoxyProxy Standard') - Feature(addon=foxy, application_id=amo.FIREFOX.id, + Feature(addon=foxy, application=amo.FIREFOX.id, start=datetime.now(), end=datetime.now() + timedelta(days=30)).save() @@ -1144,7 +1143,7 @@ class TestCategoriesFeed(amo.tests.TestCase): class TestFeaturedFeed(amo.tests.TestCase): - fixtures = ['addons/featured', 'base/addon_3615', 'base/apps', + fixtures = ['addons/featured', 'base/addon_3615', 'base/appversion', 'base/appversion', 'base/collections', 'base/featured', 'base/users', 'bandwagon/featured_collections'] @@ -1164,7 +1163,7 @@ class TestFeaturedFeed(amo.tests.TestCase): class TestPersonas(amo.tests.TestCase): - fixtures = ('base/apps', 'base/appversion', 'base/featured', + fixtures = ('base/appversion', 'base/featured', 'addons/featured', 'addons/persona') def setUp(self): @@ -1223,7 +1222,7 @@ class TestPersonas(amo.tests.TestCase): # Whatever the `category.count` is. category = Category(type=amo.ADDON_PERSONA, slug='abc', count=MIN_COUNT_FOR_LANDING + 1, - application=Application.objects.get(id=amo.FIREFOX.id)) + application=amo.FIREFOX.id) category.save() r = self.client.get(self.landing_url) self.assertTemplateUsed(r, self.landing_template) @@ -1231,7 +1230,7 @@ class TestPersonas(amo.tests.TestCase): def test_personas_grid_sorting(self): """Ensure we hit a grid page if there is a sorting.""" category = Category(type=amo.ADDON_PERSONA, slug='abc', - application=Application.objects.get(id=amo.FIREFOX.id)) + application=amo.FIREFOX.id) category.save() category_url = reverse('browse.personas', args=[category.slug]) r = self.client.get(category_url + '?sort=created') @@ -1405,7 +1404,7 @@ class TestMobilePersonas(TestMobile): def _create_persona_cat(self): category = Category(type=amo.ADDON_PERSONA, slug='xxx', - application_id=amo.FIREFOX.id) + application=amo.FIREFOX.id) category.save() return category diff --git a/apps/constants/applications.py b/apps/constants/applications.py index 994bd8b312..33e7263b45 100644 --- a/apps/constants/applications.py +++ b/apps/constants/applications.py @@ -192,6 +192,7 @@ APPS_ALL = dict((app.id, app) for app in _apps + (MOZILLA, SUNBIRD)) APP_IDS = dict((app.id, app) for app in _apps) APP_GUIDS = dict((app.guid, app) for app in _apps) APPS_RETIRED = dict([(MOZILLA.short, MOZILLA), (SUNBIRD.short, SUNBIRD)]) +APPS_CHOICES = tuple((app.id, app.pretty) for app in _apps) APP_TYPE_SUPPORT = {} for _app in APP_USAGE: diff --git a/apps/devhub/fixtures/devhub/addon-compat-results.json b/apps/devhub/fixtures/devhub/addon-compat-results.json index a7d1c0fa82..e278b15b4a 100644 --- a/apps/devhub/fixtures/devhub/addon-compat-results.json +++ b/apps/devhub/fixtures/devhub/addon-compat-results.json @@ -161,15 +161,6 @@ "created": "2010-01-02 12:34:56" } }, - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 112349, "model": "files.file", diff --git a/apps/devhub/forms.py b/apps/devhub/forms.py index edd4fc8fdb..cd51df1ca7 100644 --- a/apps/devhub/forms.py +++ b/apps/devhub/forms.py @@ -27,7 +27,7 @@ from amo.forms import AMOModelForm from amo.urlresolvers import reverse from amo.utils import raise_required, slugify -from applications.models import Application, AppVersion +from applications.models import AppVersion from files.models import File, FileUpload from files.utils import parse_addon, VERSION_RE from translations.widgets import TranslationTextarea, TranslationTextInput @@ -401,12 +401,6 @@ class VersionForm(WithSourceMixin, happyforms.ModelForm): fields = ('releasenotes', 'approvalnotes', 'source') -class ApplicationChoiceField(forms.ModelChoiceField): - - def label_from_instance(self, obj): - return obj.id - - class AppVersionChoiceField(forms.ModelChoiceField): def label_from_instance(self, obj): @@ -414,8 +408,7 @@ class AppVersionChoiceField(forms.ModelChoiceField): class CompatForm(happyforms.ModelForm): - application = ApplicationChoiceField(Application.objects.all(), - widget=forms.HiddenInput) + application = forms.ChoiceField(amo.APPS_CHOICES, widget=forms.HiddenInput) min = AppVersionChoiceField(AppVersion.objects.none()) max = AppVersionChoiceField(AppVersion.objects.none()) @@ -959,12 +952,12 @@ class CheckCompatibilityForm(happyforms.Form): w.attrs['data-url'] = reverse('devhub.compat_application_versions') def version_choices_for_app_id(self, app_id): - versions = AppVersion.objects.filter(application__id=app_id) + versions = AppVersion.objects.filter(application=app_id) return [(v.id, v.version) for v in versions] def clean_application(self): app_id = int(self.cleaned_data['application']) - app = Application.objects.get(pk=app_id) + app = amo.APPS_IDS.get(app_id) self.cleaned_data['application'] = app choices = self.version_choices_for_app_id(app_id) self.fields['app_version'].choices = choices diff --git a/apps/devhub/tasks.py b/apps/devhub/tasks.py index b0c0fbfec9..1a34d233d5 100644 --- a/apps/devhub/tasks.py +++ b/apps/devhub/tasks.py @@ -22,7 +22,7 @@ from amo.decorators import write, set_modified_on from amo.utils import resize_image, send_html_mail_jinja from addons.models import Addon from applications.management.commands import dump_apps -from applications.models import Application, AppVersion +from applications.models import AppVersion from devhub import perf from files.helpers import copyfileobj from files.models import FileUpload, File, FileValidation @@ -60,8 +60,8 @@ def compatibility_check(upload_id, app_guid, appversion_str, **kw): log.info('COMPAT CHECK for upload %s / app %s version %s' % (upload_id, app_guid, appversion_str)) upload = FileUpload.objects.get(pk=upload_id) - app = Application.objects.get(guid=app_guid) - appver = AppVersion.objects.get(application=app, version=appversion_str) + app = amo.APP_GUIDS.get(app_guid) + appver = AppVersion.objects.get(application=app.id, version=appversion_str) try: result = run_validator(upload.path, for_appversions={app_guid: [appversion_str]}, @@ -74,7 +74,7 @@ def compatibility_check(upload_id, app_guid, appversion_str, **kw): {app_guid: appversion_str}}, compat=True) upload.validation = result - upload.compat_with_app = app + upload.compat_with_app = app.id upload.compat_with_appver = appver upload.save() # We want to hit the custom save(). except: diff --git a/apps/devhub/templates/devhub/validation.html b/apps/devhub/templates/devhub/validation.html index 6a54748734..cebbbb83c7 100644 --- a/apps/devhub/templates/devhub/validation.html +++ b/apps/devhub/templates/devhub/validation.html @@ -24,7 +24,7 @@ {% if result_type == 'compat' %} {{ _('Tested for compatibility against:') }} - {{ amo.APP_IDS[target_app.pk].pretty }} {{ target_version }} + {{ amo.APP_IDS[target_app].pretty }} {{ target_version }} {% endif %} @@ -34,7 +34,7 @@ {% if result_type == 'compat' %} {% with app_trans=app_trans, version_change_links=version_change_links, - target_version={target_app.guid: target_version.version} %} + target_version={amo.APP_IDS[target_app].guid: target_version.version} %} {% include "devhub/addons/includes/validation_compat_test_results.html" %} {% endwith %} {% else %} diff --git a/apps/devhub/tests/test_forms.py b/apps/devhub/tests/test_forms.py index 61ab7f3a16..8ffc77bc74 100644 --- a/apps/devhub/tests/test_forms.py +++ b/apps/devhub/tests/test_forms.py @@ -85,13 +85,13 @@ class TestCharityForm(amo.tests.TestCase): class TestCompatForm(amo.tests.TestCase): - fixtures = ['base/apps', 'base/addon_3615'] + fixtures = ['base/addon_3615'] def test_mozilla_app(self): moz = amo.MOZILLA - appver = AppVersion.objects.create(application_id=moz.id) + appver = AppVersion.objects.create(application=moz.id) v = Addon.objects.get(id=3615).current_version - ApplicationsVersions(application_id=moz.id, version=v, + ApplicationsVersions(application=moz.id, version=v, min=appver, max=appver).save() fs = forms.CompatFormSet(None, queryset=v.apps.all()) apps = [f.app for f in fs.forms] @@ -132,7 +132,7 @@ class TestPreviewForm(amo.tests.TestCase): class TestThemeForm(amo.tests.TestCase): - fixtures = ['base/apps', 'base/user_2519'] + fixtures = ['base/user_2519'] def setUp(self): self.populate() @@ -142,7 +142,7 @@ class TestThemeForm(amo.tests.TestCase): self.request.amo_user.is_authenticated.return_value = True def populate(self): - self.cat = Category.objects.create(application_id=amo.FIREFOX.id, + self.cat = Category.objects.create(application=amo.FIREFOX.id, type=amo.ADDON_PERSONA, name='xxxx') License.objects.create(id=amo.LICENSE_CC_BY.id) @@ -377,7 +377,7 @@ class TestThemeForm(amo.tests.TestCase): class TestEditThemeForm(amo.tests.TestCase): - fixtures = ['base/apps', 'base/user_2519'] + fixtures = ['base/user_2519'] def setUp(self): self.populate() @@ -573,7 +573,7 @@ class TestEditThemeForm(amo.tests.TestCase): class TestEditThemeOwnerForm(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users'] + fixtures = ['base/users'] def setUp(self): self.instance = Addon.objects.create( diff --git a/apps/devhub/tests/test_models.py b/apps/devhub/tests/test_models.py index 5ebafd7fd1..94cb82e632 100644 --- a/apps/devhub/tests/test_models.py +++ b/apps/devhub/tests/test_models.py @@ -175,8 +175,7 @@ class TestActivityLog(amo.tests.TestCase): class TestVersion(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615', - 'base/thunderbird'] + fixtures = ['base/users', 'base/addon_3615', 'base/thunderbird'] def setUp(self): self.addon = Addon.objects.get(pk=3615) diff --git a/apps/devhub/tests/test_views.py b/apps/devhub/tests/test_views.py index 9d78c6ed67..48053dc784 100644 --- a/apps/devhub/tests/test_views.py +++ b/apps/devhub/tests/test_views.py @@ -32,7 +32,7 @@ from amo.tests import (addon_factory, assert_no_validation_exceptions, formset, initial) from amo.tests.test_helpers import get_image_path from amo.urlresolvers import reverse -from applications.models import Application, AppVersion +from applications.models import AppVersion from devhub import tasks from devhub.forms import ContribForm from devhub.models import ActivityLog, BlogPost, SubmitStep @@ -246,8 +246,7 @@ class TestDashboard(HubTest): class TestUpdateCompatibility(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_4594_a9', - 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_4594_a9', 'base/addon_3615'] def setUp(self): assert self.client.login(username='del@icio.us', password='password') @@ -301,11 +300,10 @@ class TestUpdateCompatibility(amo.tests.TestCase): assert doc('.item[data-addonid=3615] .tooltip.compat-error') def test_incompat_mobile(self): - app = Application.objects.get(id=amo.MOBILE.id) appver = AppVersion.objects.get(version='2.0') - appver.update(application=app) + appver.update(application=amo.MOBILE.id) av = ApplicationsVersions.objects.all()[0] - av.application = app + av.application = amo.MOBILE.id av.max = appver av.save() doc = pq(self.client.get(self.url).content) @@ -313,7 +311,7 @@ class TestUpdateCompatibility(amo.tests.TestCase): class TestDevRequired(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): self.addon = Addon.objects.get(id=3615) @@ -357,7 +355,7 @@ class TestDevRequired(amo.tests.TestCase): class TestVersionStats(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): assert self.client.login(username='admin@mozilla.com', @@ -380,7 +378,7 @@ class TestVersionStats(amo.tests.TestCase): class TestEditPayments(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): self.addon = self.get_addon() @@ -588,7 +586,7 @@ class TestEditPayments(amo.tests.TestCase): class TestDisablePayments(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): self.addon = Addon.objects.get(id=3615) @@ -615,7 +613,7 @@ class TestDisablePayments(amo.tests.TestCase): class TestPaymentsProfile(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): raise SkipTest @@ -806,7 +804,7 @@ class TestHome(amo.tests.TestCase): class TestActivityFeed(amo.tests.TestCase): - fixtures = ('base/apps', 'base/users', 'base/addon_3615') + fixtures = ('base/users', 'base/addon_3615') def setUp(self): super(TestActivityFeed, self).setUp() @@ -863,7 +861,7 @@ class TestActivityFeed(amo.tests.TestCase): class TestProfileBase(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): self.addon = Addon.objects.get(id=3615) @@ -1664,7 +1662,7 @@ class TestSubmitBump(TestSubmitBase): class TestSubmitSteps(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): assert self.client.login(username='del@icio.us', password='password') @@ -1750,7 +1748,7 @@ class TestSubmitSteps(amo.tests.TestCase): class TestUpload(BaseUploadTest): - fixtures = ['base/apps', 'base/users'] + fixtures = ['base/users'] def setUp(self): super(TestUpload, self).setUp() @@ -1809,7 +1807,7 @@ class TestUpload(BaseUploadTest): class TestUploadDetail(BaseUploadTest): - fixtures = ['base/apps', 'base/appversion', 'base/users'] + fixtures = ['base/appversion', 'base/users'] def setUp(self): super(TestUploadDetail, self).setUp() @@ -1935,7 +1933,7 @@ def assert_json_field(request, field, msg): class UploadTest(BaseUploadTest, amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): super(UploadTest, self).setUp() @@ -1947,7 +1945,7 @@ class UploadTest(BaseUploadTest, amo.tests.TestCase): class TestQueuePosition(UploadTest): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): super(TestQueuePosition, self).setUp() @@ -1989,7 +1987,7 @@ class TestQueuePosition(UploadTest): class TestVersionAddFile(UploadTest): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): super(TestVersionAddFile, self).setUp() @@ -2003,9 +2001,8 @@ class TestVersionAddFile(UploadTest): version_files.save() def make_mobile(self): - app = Application.objects.get(pk=amo.MOBILE.id) for a in self.version.apps.all(): - a.application = app + a.application = amo.MOBILE.id a.save() def post(self, platform=amo.PLATFORM_MAC, source=None): @@ -2251,7 +2248,7 @@ class TestVersionAddFile(UploadTest): class TestUploadErrors(UploadTest): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] validator_success = json.dumps({ "errors": 0, "success": True, @@ -2394,7 +2391,7 @@ class TestAddVersion(AddVersionTest): class TestAddBetaVersion(AddVersionTest): - fixtures = ['base/apps', 'base/users', 'base/appversion', 'base/addon_3615'] + fixtures = ['base/users', 'base/appversion', 'base/addon_3615'] def setUp(self): super(TestAddBetaVersion, self).setUp() @@ -2512,7 +2509,7 @@ class UploadAddon(object): class TestCreateAddon(BaseUploadTest, UploadAddon, amo.tests.TestCase): - fixtures = ['base/apps', 'base/users'] + fixtures = ['base/users'] def setUp(self): super(TestCreateAddon, self).setUp() @@ -2573,7 +2570,7 @@ class TestCreateAddon(BaseUploadTest, UploadAddon, amo.tests.TestCase): class TestDeleteAddon(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): self.addon = Addon.objects.get(id=3615) @@ -2698,7 +2695,7 @@ class TestRequestReview(amo.tests.TestCase): class TestRedirects(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): self.base = reverse('devhub.index') @@ -2755,7 +2752,7 @@ class TestDocs(amo.tests.TestCase): class TestRemoveLocale(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): self.addon = Addon.objects.get(id=3615) diff --git a/apps/devhub/tests/test_views_edit.py b/apps/devhub/tests/test_views_edit.py index ba73f661f2..bb424bead4 100644 --- a/apps/devhub/tests/test_views_edit.py +++ b/apps/devhub/tests/test_views_edit.py @@ -38,7 +38,7 @@ def get_section_url(addon, section, edit=False): @override_settings(MEDIA_ROOT=None) # Make it overridable. class TestEdit(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615', + fixtures = ['base/users', 'base/addon_3615', 'base/addon_5579', 'base/addon_3615_categories'] def setUp(self): @@ -303,7 +303,7 @@ class TestEditBasic(TestEdit): c = CollectionAddon.objects.create(addon_id=addon_id, collection=Collection.objects.create()) FeaturedCollection.objects.create(collection=c.collection, - application_id=amo.FIREFOX.id) + application=amo.FIREFOX.id) def test_edit_categories_add_creatured(self): raise SkipTest() @@ -1212,7 +1212,7 @@ class TestEditTechnical(TestEdit): class TestAdmin(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def login_admin(self): assert self.client.login(username='admin@mozilla.com', diff --git a/apps/devhub/tests/test_views_ownership.py b/apps/devhub/tests/test_views_ownership.py index ab58fc6309..145dd071a6 100644 --- a/apps/devhub/tests/test_views_ownership.py +++ b/apps/devhub/tests/test_views_ownership.py @@ -13,7 +13,7 @@ from versions.models import License, Version class TestOwnership(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): self.addon = Addon.objects.get(id=3615) diff --git a/apps/devhub/tests/test_views_packager.py b/apps/devhub/tests/test_views_packager.py index f44475e904..a3476d7b97 100644 --- a/apps/devhub/tests/test_views_packager.py +++ b/apps/devhub/tests/test_views_packager.py @@ -19,7 +19,7 @@ from devhub.views import packager_path class TestPackager(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/appversion', + fixtures = ['base/users', 'base/appversion', 'base/addon_3615'] def setUp(self): @@ -207,7 +207,7 @@ class TestPackager(amo.tests.TestCase): @patch.object(amo, 'DEFAULT_MINVER', '3.6') def test_default_firefox_minver(self): - eq_(len(AppVersion.objects.filter(application__id=amo.FIREFOX.id, + eq_(len(AppVersion.objects.filter(application=amo.FIREFOX.id, version='3.6')), 1) r = self.client.get(self.url) eq_(r.status_code, 200) @@ -232,8 +232,7 @@ class TestPackager(amo.tests.TestCase): class TestPackagerDownload(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/appversion', - 'base/addon_3615'] + fixtures = ['base/users', 'base/appversion', 'base/addon_3615'] def setUp(self): self.url = lambda f: reverse('devhub.package_addon_json', args=[f]) diff --git a/apps/devhub/tests/test_views_perf.py b/apps/devhub/tests/test_views_perf.py index db03f89964..da35faa50c 100644 --- a/apps/devhub/tests/test_views_perf.py +++ b/apps/devhub/tests/test_views_perf.py @@ -10,7 +10,7 @@ import amo.tests class TestPerfViews(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615'] + fixtures = ['base/users', 'base/addon_3615'] def setUp(self): super(TestPerfViews, self).setUp() diff --git a/apps/devhub/tests/test_views_submit.py b/apps/devhub/tests/test_views_submit.py index be97a5358a..c115e9af67 100644 --- a/apps/devhub/tests/test_views_submit.py +++ b/apps/devhub/tests/test_views_submit.py @@ -12,7 +12,7 @@ from amo.urlresolvers import reverse class TestSubmitPersona(amo.tests.TestCase): - fixtures = ['base/apps', 'base/user_999'] + fixtures = ['base/user_999'] def setUp(self): assert self.client.login(username='regular@mozilla.com', diff --git a/apps/devhub/tests/test_views_validation.py b/apps/devhub/tests/test_views_validation.py index d7fe0dcceb..9b3b85c945 100644 --- a/apps/devhub/tests/test_views_validation.py +++ b/apps/devhub/tests/test_views_validation.py @@ -18,7 +18,7 @@ from addons.models import Addon from amo.tests import assert_no_validation_exceptions from amo.tests.test_helpers import get_image_path from amo.urlresolvers import reverse -from applications.models import AppVersion, Application +from applications.models import AppVersion from constants.applications import FIREFOX from devhub.tasks import compatibility_check from files.helpers import copyfileobj @@ -30,8 +30,7 @@ from zadmin.models import ValidationResult class TestUploadValidation(BaseUploadTest): - fixtures = ['base/apps', 'base/users', - 'devhub/invalid-id-uploaded-xpi.json'] + fixtures = ['base/users', 'devhub/invalid-id-uploaded-xpi.json'] def setUp(self): super(TestUploadValidation, self).setUp() @@ -69,7 +68,7 @@ class TestUploadValidation(BaseUploadTest): class TestUploadErrors(BaseUploadTest): - fixtures = ('base/apps', 'base/addon_3615', 'base/users') + fixtures = ('base/addon_3615', 'base/users') def setUp(self): super(TestUploadErrors, self).setUp() @@ -95,7 +94,7 @@ class TestUploadErrors(BaseUploadTest): class TestFileValidation(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'devhub/addon-validation-1'] + fixtures = ['base/users', 'devhub/addon-validation-1'] def setUp(self): assert self.client.login(username='del@icio.us', password='password') @@ -198,8 +197,7 @@ class TestValidateAddon(amo.tests.TestCase): class TestValidateFile(BaseUploadTest): - fixtures = ['base/apps', 'base/users', 'base/addon_3615', - 'devhub/addon-file-100456'] + fixtures = ['base/users', 'base/addon_3615', 'devhub/addon-file-100456'] def setUp(self): super(TestValidateFile, self).setUp() @@ -426,7 +424,7 @@ class TestValidateFile(BaseUploadTest): }) xpi = self.get_upload('extension.xpi') AppVersion.objects.create( - application=Application.objects.get(guid=FIREFOX.guid), + application=FIREFOX.id, version='10.0.*') compatibility_check(xpi, FIREFOX.guid, '10.0.*') @@ -527,7 +525,7 @@ class TestCompatibilityResults(amo.tests.TestCase): class TestUploadCompatCheck(BaseUploadTest): - fixtures = ['base/apps', 'base/appversions', 'base/addon_3615'] + fixtures = ['base/appversion', 'base/addon_3615'] compatibility_result = json.dumps({ "errors": 0, "success": True, @@ -544,8 +542,8 @@ class TestUploadCompatCheck(BaseUploadTest): def setUp(self): super(TestUploadCompatCheck, self).setUp() assert self.client.login(username='del@icio.us', password='password') - self.app = Application.objects.get(pk=amo.FIREFOX.id) - self.appver = AppVersion.objects.get(application=self.app, + self.app = amo.FIREFOX + self.appver = AppVersion.objects.get(application=self.app.id, version='3.7a1pre') self.upload_url = reverse('devhub.standalone_upload') @@ -563,7 +561,7 @@ class TestUploadCompatCheck(BaseUploadTest): # Simulate how JS posts data w/ app/version from the form. res = self.client.post(self.upload_url, {'upload': f, - 'app_id': self.app.pk, + 'app_id': self.app.id, 'version_id': self.appver.pk}, follow=True) return json.loads(res.content) @@ -625,7 +623,7 @@ class TestUploadCompatCheck(BaseUploadTest): res = self.client.get(reverse('devhub.check_addon_compatibility')) eq_(res.status_code, 200) doc = pq(res.content) - data = {'application_id': amo.FIREFOX.id, + data = {'application': amo.FIREFOX.id, 'csrfmiddlewaretoken': doc('input[name=csrfmiddlewaretoken]').val()} r = self.client.post(doc('#id_application').attr('data-url'), diff --git a/apps/devhub/tests/test_views_versions.py b/apps/devhub/tests/test_views_versions.py index ab87aab8ef..45ae777a04 100644 --- a/apps/devhub/tests/test_views_versions.py +++ b/apps/devhub/tests/test_views_versions.py @@ -12,7 +12,7 @@ import amo.tests from amo.urlresolvers import reverse from amo.tests import formset, initial from addons.models import Addon -from applications.models import Application, AppVersion +from applications.models import AppVersion from devhub.models import ActivityLog from files.models import File from users.models import UserProfile @@ -337,8 +337,7 @@ class TestVersion(amo.tests.TestCase): class TestVersionEdit(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615', - 'base/thunderbird'] + fixtures = ['base/users', 'base/addon_3615', 'base/thunderbird'] def setUp(self): assert self.client.login(username='del@icio.us', password='password') @@ -347,9 +346,9 @@ class TestVersionEdit(amo.tests.TestCase): self.url = reverse('devhub.versions.edit', args=['a3615', self.version.id]) self.v1, _created = AppVersion.objects.get_or_create( - application_id=amo.FIREFOX.id, version='1.0') + application=amo.FIREFOX.id, version='1.0') self.v5, _created = AppVersion.objects.get_or_create( - application_id=amo.FIREFOX.id, version='5.0') + application=amo.FIREFOX.id, version='5.0') def get_addon(self): return Addon.objects.no_cache().get(id=3615) @@ -368,10 +367,10 @@ class TestVersionEditMobile(TestVersionEdit): def setUp(self): super(TestVersionEditMobile, self).setUp() self.version.apps.all().delete() - mobile = Application.objects.get(id=amo.MOBILE.id) - app_vr = AppVersion.objects.create(application=mobile, version='1.0') + app_vr = AppVersion.objects.create(application=amo.MOBILE.id, + version='1.0') ApplicationsVersions.objects.create(version=self.version, - application=mobile, + application=amo.MOBILE.id, min=app_vr, max=app_vr) self.version.files.update(platform=amo.PLATFORM_ANDROID.id) @@ -436,11 +435,10 @@ class TestVersionEditDetails(TestVersionEdit): assert doc('p.add-app')[0].attrib['class'] == 'add-app' def test_add_not(self): - Application(id=52).save() for id in [18, 52, 59, 60, 61]: - av = AppVersion(application_id=id, version='1') + av = AppVersion(application=id, version='1') av.save() - ApplicationsVersions(application_id=id, min=av, max=av, + ApplicationsVersions(application=id, min=av, max=av, version=self.version).save() res = self.client.get(self.url) @@ -473,8 +471,7 @@ class TestVersionEditDetails(TestVersionEdit): class TestVersionEditSearchEngine(TestVersionEdit): # https://bugzilla.mozilla.org/show_bug.cgi?id=605941 - fixtures = ['base/apps', 'base/users', - 'base/thunderbird', 'base/addon_4594_a9.json'] + fixtures = ['base/users', 'base/thunderbird', 'base/addon_4594_a9.json'] def setUp(self): assert self.client.login(username='admin@mozilla.com', @@ -644,9 +641,8 @@ class TestVersionEditFiles(TestVersionEdit): set(['radio'])) def test_mobile_addon_supports_only_mobile_platforms(self): - app = Application.objects.get(pk=amo.MOBILE.id) for a in self.version.apps.all(): - a.application = app + a.application = amo.MOBILE.id a.save() self.version.files.all().update(platform=amo.PLATFORM_ALL_MOBILE.id) forms = self.client.get(self.url).context['file_form'].forms @@ -656,8 +652,7 @@ class TestVersionEditFiles(TestVersionEdit): class TestPlatformSearch(TestVersionEdit): - fixtures = ['base/apps', 'base/users', - 'base/thunderbird', 'base/addon_4594_a9.json'] + fixtures = ['base/users', 'base/thunderbird', 'base/addon_4594_a9.json'] def setUp(self): assert self.client.login(username='admin@mozilla.com', diff --git a/apps/devhub/views.py b/apps/devhub/views.py index 46cbf8a485..a594908004 100644 --- a/apps/devhub/views.py +++ b/apps/devhub/views.py @@ -39,7 +39,7 @@ from amo.decorators import json_view, login_required, post_required, write from amo.helpers import absolutify, urlparams from amo.urlresolvers import reverse from amo.utils import escape_all, HttpResponseSendFile, MenuItem -from applications.models import Application, AppVersion +from applications.models import AppVersion from devhub import perf from devhub.decorators import dev_required from devhub.forms import CheckCompatibilityForm @@ -514,7 +514,7 @@ def profile(request, addon_id, addon): @post_required @json_view def compat_application_versions(request): - app_id = request.POST['application_id'] + app_id = request.POST['application'] f = CheckCompatibilityForm() return {'choices': f.version_choices_for_app_id(app_id)} @@ -626,8 +626,11 @@ def upload(request, addon_slug=None, is_standalone=False): if request.user.is_authenticated(): fu.user = request.amo_user fu.save() - if request.POST.get('app_id') and request.POST.get('version_id'): - app = get_object_or_404(Application, pk=request.POST['app_id']) + app_id = request.POST.get('app_id') + if app_id and request.POST.get('version_id'): + app = amo.APPS_ALL.get(int(app_id)) + if not app: + raise http.Http404() ver = get_object_or_404(AppVersion, pk=request.POST['version_id']) tasks.compatibility_check.delay(fu.pk, app.guid, ver.version) else: @@ -1112,7 +1115,7 @@ def version_edit(request, addon_id, addon, version_id): def _log_max_version_change(addon, version, appversion): details = {'version': version.version, 'target': appversion.version.version, - 'application': appversion.application.pk} + 'application': appversion.application} amo.log(amo.LOG.MAX_APPVERSION_UPDATED, addon, version, details=details) diff --git a/apps/discovery/models.py b/apps/discovery/models.py index b218e84e2f..5de4777a4a 100644 --- a/apps/discovery/models.py +++ b/apps/discovery/models.py @@ -10,7 +10,7 @@ class DiscoveryModule(amo.models.ModelBase): The modules are defined statically in modules.py and linked to a database row through the module's name. """ - app = models.ForeignKey('applications.Application') + app = models.PositiveIntegerField(db_column='app_id') module = models.CharField(max_length=255) ordering = models.IntegerField(null=True, blank=True) locales = models.CharField(max_length=255, blank=True, default='') diff --git a/apps/discovery/tests/test_views.py b/apps/discovery/tests/test_views.py index 97a2285d74..41063fe566 100644 --- a/apps/discovery/tests/test_views.py +++ b/apps/discovery/tests/test_views.py @@ -15,7 +15,7 @@ import addons.signals from amo.urlresolvers import reverse from addons.models import (Addon, AddonDependency, CompatOverride, CompatOverrideRange, Preview) -from applications.models import Application, AppVersion +from applications.models import AppVersion from bandwagon.models import MonthlyPick, SyncedCollection from bandwagon.tests.test_models import TestRecommendations as Recs from discovery import views @@ -27,7 +27,7 @@ from versions.models import Version, ApplicationsVersions class TestRecs(amo.tests.TestCase): - fixtures = ['base/apps', 'base/appversion', 'base/addon_3615', + fixtures = ['base/appversion', 'base/addon_3615', 'base/addon-recs', 'base/addon_5299_gcal', 'base/category', 'base/featured', 'addons/featured'] @@ -54,7 +54,7 @@ class TestRecs(amo.tests.TestCase): v = Version.objects.create(addon=addon) File.objects.create(version=v, status=amo.STATUS_PUBLIC) ApplicationsVersions.objects.create( - version=v, application_id=amo.FIREFOX.id, + version=v, application=amo.FIREFOX.id, min_id=self.min_id, max_id=self.max_id) addon.update(_current_version=v) addons.signals.version_changed.send(sender=addon) @@ -188,17 +188,15 @@ class TestRecs(amo.tests.TestCase): class TestModuleAdmin(amo.tests.TestCase): - fixtures = ['base/apps'] def test_sync_db_and_registry(self): def check(): - views._sync_db_and_registry(qs, app) + views._sync_db_and_registry(qs, 1) eq_(qs.count(), len(registry)) modules = qs.values_list('module', flat=True) eq_(set(modules), set(registry.keys())) - app = Application.objects.create() - qs = DiscoveryModule.objects.no_cache().filter(app=app) + qs = DiscoveryModule.objects.no_cache().filter(app=1) eq_(qs.count(), 0) # All our modules get added. @@ -221,7 +219,7 @@ class TestModuleAdmin(amo.tests.TestCase): class TestUrls(amo.tests.TestCase): - fixtures = ['base/users', 'base/apps', 'base/featured', 'addons/featured', + fixtures = ['base/users', 'base/featured', 'addons/featured', 'base/addon_3615'] def test_reverse(self): @@ -264,7 +262,7 @@ class TestUrls(amo.tests.TestCase): class TestPromos(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'discovery/discoverymodules'] + fixtures = ['base/users', 'discovery/discoverymodules'] def get_disco_url(self, platform, version): return reverse('discovery.pane.promos', args=[platform, version]) @@ -301,9 +299,8 @@ class TestPromos(amo.tests.TestCase): class TestPane(amo.tests.TestCase): - fixtures = ['addons/featured', 'base/addon_3615', 'base/apps', - 'base/collections', 'base/featured', 'base/users', - 'bandwagon/featured_collections'] + fixtures = ['addons/featured', 'base/addon_3615', 'base/collections', + 'base/featured', 'base/users', 'bandwagon/featured_collections'] def setUp(self): self.url = reverse('discovery.pane', args=['3.7a1pre', 'Darwin']) @@ -393,7 +390,7 @@ class TestPane(amo.tests.TestCase): class TestDetails(amo.tests.TestCase): - fixtures = ['base/apps', 'base/addon_3615', 'base/addon_592'] + fixtures = ['base/addon_3615', 'base/addon_592'] def setUp(self): self.addon = self.get_addon() @@ -471,7 +468,7 @@ class TestPersonaDetails(amo.tests.TestCase): class TestDownloadSources(amo.tests.TestCase): - fixtures = ['base/apps', 'base/addon_3615', 'base/users', + fixtures = ['base/addon_3615', 'base/users', 'base/collections', 'base/featured', 'addons/featured', 'discovery/discoverymodules'] @@ -518,14 +515,14 @@ class TestDownloadSources(amo.tests.TestCase): class TestMonthlyPick(amo.tests.TestCase): - fixtures = ['base/users', 'base/apps', 'base/addon_3615', + fixtures = ['base/users', 'base/addon_3615', 'discovery/discoverymodules'] def setUp(self): self.url = reverse('discovery.pane.promos', args=['Darwin', '10.0']) self.addon = Addon.objects.get(id=3615) DiscoveryModule.objects.create( - app=Application.objects.get(id=amo.FIREFOX.id), ordering=4, + app=amo.FIREFOX.id, ordering=4, module='Monthly Pick') def test_monthlypick(self): @@ -573,7 +570,7 @@ class TestMonthlyPick(amo.tests.TestCase): class TestPaneMoreAddons(amo.tests.TestCase): - fixtures = ['base/apps', 'base/appversion'] + fixtures = ['base/appversion'] def setUp(self): self.addon1 = addon_factory(hotness=99, @@ -634,7 +631,7 @@ class TestPaneMoreAddons(amo.tests.TestCase): # Add override for this add-on. compat = CompatOverride.objects.create(guid='three', addon=addon3) CompatOverrideRange.objects.create( - compat=compat, app=Application.objects.get(pk=1), + compat=compat, app=1, min_version=addon3.current_version.version, max_version='*') res = self.client.get(self._url(version='12.0', compat_mode='normal')) diff --git a/apps/discovery/views.py b/apps/discovery/views.py index 15d326eccd..6c13f818b6 100644 --- a/apps/discovery/views.py +++ b/apps/discovery/views.py @@ -150,7 +150,7 @@ def module_admin(request): SELECT * from discovery_modules WHERE app_id = %s ORDER BY ordering IS NULL, ordering""", [APP.id]) qs.ordered = True # The formset looks for this. - _sync_db_and_registry(qs, APP) + _sync_db_and_registry(qs, APP.id) Form = modelformset_factory(DiscoveryModule, form=DiscoveryModuleForm, can_delete=True, extra=0) @@ -163,14 +163,14 @@ def module_admin(request): return render(request, 'discovery/module_admin.html', {'formset': formset}) -def _sync_db_and_registry(qs, app): +def _sync_db_and_registry(qs, app_id): """Match up the module registry and DiscoveryModule rows in the db.""" existing = dict((m.module, m) for m in qs) to_add = [m for m in module_registry if m not in existing] to_delete = [m for m in existing if m not in module_registry] for m in to_add: - DiscoveryModule.objects.get_or_create(module=m, app_id=app.id) - DiscoveryModule.objects.filter(module__in=to_delete, app=app.id).delete() + DiscoveryModule.objects.get_or_create(module=m, app=app_id) + DiscoveryModule.objects.filter(module__in=to_delete, app=app_id).delete() if to_add or to_delete: qs._result_cache = None diff --git a/apps/editors/forms.py b/apps/editors/forms.py index 9e68d33257..0e6a8756a6 100644 --- a/apps/editors/forms.py +++ b/apps/editors/forms.py @@ -127,7 +127,7 @@ class QueueSearchForm(happyforms.Form): w.attrs['data-url'] = reverse('editors.application_versions_json') def version_choices_for_app_id(self, app_id): - versions = AppVersion.objects.filter(application__id=app_id) + versions = AppVersion.objects.filter(application=app_id) return [('', '')] + [(v.version, v.version) for v in versions] def clean_addon_type_ids(self): diff --git a/apps/editors/tests/test_models.py b/apps/editors/tests/test_models.py index afb8a92d94..370386e028 100644 --- a/apps/editors/tests/test_models.py +++ b/apps/editors/tests/test_models.py @@ -12,7 +12,7 @@ from amo.tests import addon_factory from addons.models import Addon from versions.models import Version, version_uploaded, ApplicationsVersions from files.models import File -from applications.models import Application, AppVersion +from applications.models import AppVersion from editors.models import (EditorSubscription, RereviewQueueTheme, ReviewerScore, send_notifications, ViewFastTrackQueue, ViewFullReviewQueue, @@ -28,10 +28,8 @@ def create_addon_file(name, version_str, addon_status, file_status, file_kw = {} if version_kw is None: version_kw = {} - app, created_ = Application.objects.get_or_create(id=application.id, - guid=application.guid) - app_vr, created_ = AppVersion.objects.get_or_create(application=app, - version='1.0') + app_vr, created_ = AppVersion.objects.get_or_create( + application=application.id, version='1.0') try: ad = Addon.objects.get(name__localized_string=name) except Addon.DoesNotExist: @@ -43,7 +41,7 @@ def create_addon_file(name, version_str, addon_status, file_status, if not created_: vr.update(**version_kw) va, created_ = ApplicationsVersions.objects.get_or_create( - version=vr, application=app, min=app_vr, max=app_vr) + version=vr, application=application.id, min=app_vr, max=app_vr) file_ = File.objects.create(version=vr, filename=u"%s.xpi" % name, platform=platform.id, status=file_status, **file_kw) diff --git a/apps/editors/tests/test_views.py b/apps/editors/tests/test_views.py index 2d2f8da4df..82d4f7d717 100644 --- a/apps/editors/tests/test_views.py +++ b/apps/editors/tests/test_views.py @@ -22,7 +22,6 @@ from addons.models import Addon, AddonDependency, AddonUser from amo.tests import check_links, formset, initial from amo.urlresolvers import reverse from amo.utils import urlparams -from applications.models import Application from devhub.models import ActivityLog from editors.models import EditorSubscription, ReviewerScore from files.models import File @@ -1105,7 +1104,7 @@ class SearchTest(EditorTest): class TestQueueSearch(SearchTest): - fixtures = ['base/users', 'base/apps', 'base/appversion'] + fixtures = ['base/users', 'base/appversion'] def setUp(self): super(TestQueueSearch, self).setUp() @@ -1318,10 +1317,10 @@ class TestQueueSearch(SearchTest): d = create_addon_file('Bieber For Mobile 4.0b2pre', '0.1', amo.STATUS_NOMINATED, amo.STATUS_UNREVIEWED, application=amo.MOBILE) - app = Application.objects.get(pk=amo.MOBILE.id) - max = AppVersion.objects.get(application=app, version='4.0b2pre') - (ApplicationsVersions.objects - .filter(application=app, version=d['version']).update(max=max)) + max = AppVersion.objects.get(application=amo.MOBILE.id, + version='4.0b2pre') + (ApplicationsVersions.objects.filter( + application=amo.MOBILE.id, version=d['version']).update(max=max)) r = self.search(application_id=amo.MOBILE.id, max_version='4.0b2pre') eq_(self.named_addons(r), [u'Bieber For Mobile 4.0b2pre']) @@ -1679,16 +1678,14 @@ class TestReview(ReviewBase): self.addon_file(u'something', u'0.2', amo.STATUS_PUBLIC, amo.STATUS_UNREVIEWED) - a1, c = Application.objects.get_or_create(id=amo.THUNDERBIRD.id) - a2, c = Application.objects.get_or_create(id=amo.SEAMONKEY.id) av = AppVersion.objects.all()[0] v = self.addon.versions.all()[0] ApplicationsVersions.objects.create(version=v, - application=a1, min=av, max=av) + application=amo.THUNDERBIRD.id, min=av, max=av) ApplicationsVersions.objects.create(version=v, - application=a2, min=av, max=av) + application=amo.SEAMONKEY.id, min=av, max=av) eq_(self.addon.versions.count(), 1) url = reverse('editors.review', args=[self.addon.slug]) diff --git a/apps/files/models.py b/apps/files/models.py index 16a0751d9d..cfcc36af1f 100644 --- a/apps/files/models.py +++ b/apps/files/models.py @@ -30,7 +30,7 @@ from amo.decorators import use_master from amo.storage_utils import copy_stored_file, move_stored_file from amo.urlresolvers import reverse from amo.helpers import user_media_path, user_media_url -from applications.models import Application, AppVersion +from applications.models import AppVersion import devhub.signals from devhub.utils import limit_validation_results, escape_validation from files.utils import SafeUnzip @@ -513,8 +513,8 @@ class FileUpload(amo.models.ModelBase): validation = models.TextField(null=True) _escaped_validation = models.TextField( null=True, db_column='escaped_validation') - compat_with_app = models.ForeignKey( - Application, null=True, related_name='uploads_compat_for_app') + compat_with_app = models.PositiveIntegerField( + db_column="compat_with_app_id", null=True) compat_with_appver = models.ForeignKey( AppVersion, null=True, related_name='uploads_compat_for_appver') task_error = models.TextField(null=True) diff --git a/apps/files/tasks.py b/apps/files/tasks.py index 8e9aa70889..d9f6e35c23 100644 --- a/apps/files/tasks.py +++ b/apps/files/tasks.py @@ -161,7 +161,7 @@ def repackage_jetpack(builder_data, **kw): # Sync the compatible apps of the new version with data from the old # version if the repack didn't specify compat info. for app in old_version.apps.values(): - sync_app = amo.APP_IDS[app['application_id']] + sync_app = amo.APP_IDS[app['application']] new_compat = new_version.compatible_apps if sync_app not in new_compat: app.update(version_id=new_version.id, id=None) diff --git a/apps/files/tests/test_helpers.py b/apps/files/tests/test_helpers.py index 9648607723..88948760dc 100644 --- a/apps/files/tests/test_helpers.py +++ b/apps/files/tests/test_helpers.py @@ -201,7 +201,7 @@ class TestFileHelper(amo.tests.TestCase): class TestSearchEngineHelper(amo.tests.TestCase): - fixtures = ['base/addon_4594_a9', 'base/apps'] + fixtures = ['base/addon_4594_a9'] def setUp(self): self.left = File.objects.get(pk=25753) diff --git a/apps/files/tests/test_models.py b/apps/files/tests/test_models.py index 6ccfaa8e2e..3c169beef7 100644 --- a/apps/files/tests/test_models.py +++ b/apps/files/tests/test_models.py @@ -22,7 +22,7 @@ import devhub.signals from amo.utils import rm_local_tmp_dir from addons.models import Addon -from applications.models import Application, AppVersion +from applications.models import AppVersion from files.models import File, FileUpload, FileValidation, nfd_str from files.helpers import copyfileobj from files.utils import check_xpi_info, JetpackUpgrader, parse_addon, parse_xpi @@ -33,7 +33,6 @@ class UploadTest(amo.tests.TestCase, amo.tests.AMOPaths): """ Base for tests that mess with file uploads, safely using temp directories. """ - fixtures = ['applications/all_apps.json', 'base/appversion'] def setUp(self): # The validator task (post Addon upload) loads apps.json @@ -295,11 +294,10 @@ class TestFile(amo.tests.TestCase, amo.tests.AMOPaths): class TestParseXpi(amo.tests.TestCase): - fixtures = ['base/apps'] def setUp(self): for version in ('3.0', '3.6.*'): - AppVersion.objects.create(application_id=amo.FIREFOX.id, + AppVersion.objects.create(application=amo.FIREFOX.id, version=version) def parse(self, addon=None, filename='extension.xpi'): @@ -330,8 +328,8 @@ class TestParseXpi(amo.tests.TestCase): AppVersion.objects.all().delete() eq_(self.parse()['apps'], []) + @mock.patch.object(amo.FIREFOX, 'guid', 'iamabadguid') def test_parse_apps_bad_guid(self): - Application.objects.all().delete() eq_(self.parse()['apps'], []) def test_guid_match(self): @@ -432,27 +430,13 @@ class TestParseXpi(amo.tests.TestCase): result = self.parse(filename='strict-compat.xpi') eq_(result['strict_compatibility'], True) - def test_unsupported_version_only(self): - guid = '{aa3c5121-dab2-40e2-81ca-7ea25febc110}' - android = Application.objects.get(guid=guid) - # Make sure supported application and version exist. - AppVersion.objects.create(application=android, version="30.0") - AppVersion.objects.create(application=android, version="32.0") - android.update(supported=True) - result = self.parse(filename='unsupported_version_only.xpi') - eq_(result['apps'][0].appdata.guid, guid) - android.update(supported=False) - result = self.parse(filename='unsupported_version_only.xpi') - eq_(result['apps'], []) - class TestParseAlternateXpi(amo.tests.TestCase, amo.tests.AMOPaths): # This install.rdf is completely different from our other xpis. - fixtures = ['base/apps'] def setUp(self): for version in ('3.0', '4.0b3pre'): - AppVersion.objects.create(application_id=amo.FIREFOX.id, + AppVersion.objects.create(application=amo.FIREFOX.id, version=version) def parse(self, filename='alt-rdf.xpi'): @@ -490,8 +474,7 @@ class TestParseAlternateXpi(amo.tests.TestCase, amo.tests.AMOPaths): class TestFileUpload(UploadTest): - fixtures = ['applications/all_apps.json', 'base/appversion', - 'base/addon_3615'] + fixtures = ['base/appversion', 'base/addon_3615'] def setUp(self): super(TestFileUpload, self).setUp() @@ -775,7 +758,6 @@ class TestFileUpload(UploadTest): class TestFileFromUpload(UploadTest): - fixtures = ['base/apps'] def setUp(self): super(TestFileFromUpload, self).setUp() @@ -783,7 +765,7 @@ class TestFileFromUpload(UploadTest): amo.MOBILE: ['0.1', '2.0a1pre']} for app, versions in appver.items(): for version in versions: - AppVersion(application_id=app.id, version=version).save() + AppVersion(application=app.id, version=version).save() self.platform = amo.PLATFORM_MAC.id self.addon = Addon.objects.create(guid='guid@jetpack', type=amo.ADDON_EXTENSION, @@ -1094,6 +1076,7 @@ class TestCheckJetpackVersion(amo.tests.TestCase): class LanguagePackBase(UploadTest): + fixtures = ['base/appversion'] def setUp(self): super(LanguagePackBase, self).setUp() diff --git a/apps/files/tests/test_tasks.py b/apps/files/tests/test_tasks.py index 4758305060..fac751e1b1 100644 --- a/apps/files/tests/test_tasks.py +++ b/apps/files/tests/test_tasks.py @@ -207,9 +207,8 @@ class TestRepackageJetpack(amo.tests.TestCase): def test_supported_apps(self): # Create AppVersions to match what's in the xpi. - AppVersion.objects.create(application_id=amo.FIREFOX.id, version='3.6') - AppVersion.objects.create( - application_id=amo.FIREFOX.id, version='4.0b6') + AppVersion.objects.create(application=amo.FIREFOX.id, version='3.6') + AppVersion.objects.create(application=amo.FIREFOX.id, version='4.0b6') # Make sure the new appver matches the old appver. new = tasks.repackage_jetpack(self.builder_data()).version diff --git a/apps/files/tests/test_utils_.py b/apps/files/tests/test_utils_.py index cb84ac7ec4..987a939ae6 100644 --- a/apps/files/tests/test_utils_.py +++ b/apps/files/tests/test_utils_.py @@ -7,7 +7,7 @@ from nose.tools import eq_ import amo import amo.tests from addons.models import Addon -from applications.models import Application, AppVersion +from applications.models import AppVersion from files.models import File from files.utils import find_jetpacks, PackageJSONExtractor from versions.models import Version @@ -80,9 +80,8 @@ class TestPackageJSONExtractor(amo.tests.TestCase): yield PackageJSONExtractor(f.name) def create_appversion(self, name, version): - app_guid = amo.APPS[name].guid - app = Application.objects.supported().get(guid=app_guid) - return AppVersion.objects.create(application=app, version=version) + return AppVersion.objects.create(application=amo.APPS[name].id, + version=version) def test_guid(self): """Use id for the guid.""" diff --git a/apps/files/utils.py b/apps/files/utils.py index 173a4385bb..479bffed46 100644 --- a/apps/files/utils.py +++ b/apps/files/utils.py @@ -27,7 +27,7 @@ from tower import ugettext as _ import amo from amo.utils import rm_local_tmp_dir -from applications.models import AppVersion, Application +from applications.models import AppVersion from versions.compare import version_int as vint @@ -102,10 +102,6 @@ class PackageJSONExtractor(object): return self.data.get(key, default) def apps(self): - def supported_app(app): - return (Application.objects.supported() - .filter(guid=app.guid) - .exists()) def find_appversion(app, version_req): """ @@ -124,7 +120,7 @@ class PackageJSONExtractor(object): for engine, version in self.get('engines', {}).items(): name = 'android' if engine == 'fennec' else engine app = amo.APPS.get(name) - if app and supported_app(app): + if app and app.guid in amo.APP_GUIDS: appversion = find_appversion(app, version) yield Extractor.App( appdata=app, id=app.id, min=appversion, max=appversion) @@ -217,8 +213,7 @@ class RDFExtractor(object): app = amo.APP_GUIDS.get(self.find('id', ctx)) if not app: continue - if (not Application.objects.supported() - .filter(guid=app.guid).exists()): + if not app.guid in amo.APP_GUIDS: continue try: qs = AppVersion.objects.filter(application=app.id) diff --git a/apps/localizers/views.py b/apps/localizers/views.py index e647bb9e5c..f268482797 100644 --- a/apps/localizers/views.py +++ b/apps/localizers/views.py @@ -119,11 +119,11 @@ def categories(request, locale_code): category_objects = dict([(c.id, c) for c in cats]) # Initial data to pre-populate forms. initial = [dict(id=c.id, name=strings.get(c.name_id), - application=c.application_id) for c in cats] + application=c.application) for c in cats] # Group categories by application, and sort by name within app groups. categories = [] category_no_app = None - for key, group in groupby(cats, lambda c: c.application_id): + for key, group in groupby(cats, lambda c: c.application): sorted_cats = sorted(group, key=lambda c: c.name) if key: categories.append((key, sorted_cats)) diff --git a/apps/perf/tests.py b/apps/perf/tests.py index 20c7ba5dd1..0d7419047f 100644 --- a/apps/perf/tests.py +++ b/apps/perf/tests.py @@ -2,17 +2,14 @@ from django.conf import settings from mock import patch from nose.tools import eq_ -from pyquery import PyQuery as pq import amo.tests -from amo.urlresolvers import reverse from perf.models import Performance from addons.models import Addon class TestModels(amo.tests.TestCase): - fixtures = ['base/apps', 'base/addon_3615', 'base/addon_5299_gcal', - 'perf/index'] + fixtures = ['base/addon_3615', 'base/addon_5299_gcal', 'perf/index'] def setUp(self): self.addon = Addon.objects.get(pk=3615) diff --git a/apps/reviews/tests/test_models.py b/apps/reviews/tests/test_models.py index 044b94d95d..7aa041ea74 100644 --- a/apps/reviews/tests/test_models.py +++ b/apps/reviews/tests/test_models.py @@ -11,7 +11,7 @@ from users.models import UserProfile class TestReviewModel(amo.tests.TestCase): - fixtures = ['base/apps', 'reviews/test_models'] + fixtures = ['reviews/test_models'] def test_translations(self): translation.activate('en-US') @@ -36,7 +36,7 @@ class TestReviewModel(amo.tests.TestCase): class TestGroupedRating(amo.tests.TestCase): - fixtures = ['base/apps', 'reviews/dev-reply'] + fixtures = ['reviews/dev-reply'] grouped_ratings = [(1, 0), (2, 0), (3, 0), (4, 1), (5, 0)] def test_get_none(self): @@ -58,7 +58,7 @@ class TestGroupedRating(amo.tests.TestCase): class TestSpamTest(amo.tests.TestCase): - fixtures = ['base/apps', 'reviews/test_models'] + fixtures = ['reviews/test_models'] def test_create_not_there(self): Review.objects.all().delete() diff --git a/apps/reviews/tests/test_views.py b/apps/reviews/tests/test_views.py index dc8f9f9314..dafc58e6f0 100644 --- a/apps/reviews/tests/test_views.py +++ b/apps/reviews/tests/test_views.py @@ -14,7 +14,7 @@ from users.models import UserProfile class ReviewTest(amo.tests.TestCase): - fixtures = ['base/apps', 'reviews/dev-reply.json', 'base/admin'] + fixtures = ['reviews/dev-reply.json', 'base/admin'] def setUp(self): self.addon = Addon.objects.get(id=1865) @@ -452,8 +452,7 @@ class TestTranslate(ReviewTest): class TestMobileReviews(amo.tests.MobileTest, amo.tests.TestCase): - fixtures = ['base/apps', 'reviews/dev-reply.json', 'base/admin', - 'base/users'] + fixtures = ['reviews/dev-reply.json', 'base/admin', 'base/users'] def setUp(self): self.addon = Addon.objects.get(id=1865) diff --git a/apps/search/tests/test_views.py b/apps/search/tests/test_views.py index faa842b4a8..f30a76071a 100644 --- a/apps/search/tests/test_views.py +++ b/apps/search/tests/test_views.py @@ -127,7 +127,7 @@ class SearchBase(amo.tests.ESTestCase): class TestESSearch(SearchBase): - fixtures = ['base/apps', 'base/category'] + fixtures = ['base/category'] @classmethod def setUpClass(cls): @@ -462,7 +462,7 @@ class TestESSearch(SearchBase): self.check_cat_filters(dict(cat=999)) def test_defaults_atype_foreign_cat(self): - cat = Category.objects.create(application_id=amo.THUNDERBIRD.id, + cat = Category.objects.create(application=amo.THUNDERBIRD.id, type=amo.ADDON_EXTENSION) self.check_cat_filters(dict(atype=amo.ADDON_EXTENSION, cat=cat.id)) @@ -616,7 +616,6 @@ class TestESSearch(SearchBase): class TestPersonaSearch(SearchBase): - fixtures = ['base/apps'] @classmethod def setUpClass(cls): @@ -778,7 +777,6 @@ class TestPersonaSearch(SearchBase): class TestCollectionSearch(SearchBase): - fixtures = ['base/apps'] @classmethod def setUpClass(cls): @@ -977,9 +975,9 @@ class TestCollectionSearch(SearchBase): def test_results_other_applications(self): tb_collection = amo.tests.collection_factory( - application_id=amo.THUNDERBIRD.id) + application=amo.THUNDERBIRD.id) sm_collection = amo.tests.collection_factory( - application_id=amo.SEAMONKEY.id) + application=amo.SEAMONKEY.id) self.refresh() r = self.client.get(self.url) diff --git a/apps/stats/fixtures/stats/test_models.json b/apps/stats/fixtures/stats/test_models.json index a635c32ed9..342d3d21a8 100644 --- a/apps/stats/fixtures/stats/test_models.json +++ b/apps/stats/fixtures/stats/test_models.json @@ -1,13 +1,4 @@ [ - { - "pk": 1, - "model": "applications.application", - "fields": { - "guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", - "modified": "2008-11-03 15:34:59", - "created": "2007-03-05 13:09:26" - } - }, { "pk": 282, "model": "applications.appversion", diff --git a/apps/stats/tests/test_cron.py b/apps/stats/tests/test_cron.py index face4c93fd..ea76ce73c0 100644 --- a/apps/stats/tests/test_cron.py +++ b/apps/stats/tests/test_cron.py @@ -58,8 +58,7 @@ class TestGoogleAnalytics(amo.tests.TestCase): class TestTotalContributions(amo.tests.TestCase): - fixtures = ['base/apps', 'base/appversion', 'base/users', - 'base/addon_3615'] + fixtures = ['base/appversion', 'base/users', 'base/addon_3615'] def test_total_contributions(self): diff --git a/apps/users/tests/test_models.py b/apps/users/tests/test_models.py index fbdc54206e..e0a5c46998 100644 --- a/apps/users/tests/test_models.py +++ b/apps/users/tests/test_models.py @@ -31,7 +31,7 @@ from users.utils import find_users class TestUserProfile(amo.tests.TestCase): fixtures = ('base/addon_3615', 'base/user_2519', 'base/user_4043307', - 'users/test_backends', 'base/apps',) + 'users/test_backends') def test_anonymize(self): u = UserProfile.objects.get(id='4043307') diff --git a/apps/users/tests/test_views.py b/apps/users/tests/test_views.py index 6cd6acab95..2fdb439475 100644 --- a/apps/users/tests/test_views.py +++ b/apps/users/tests/test_views.py @@ -1133,10 +1133,7 @@ class TestProfileView(UserViewBase): class TestProfileLinks(UserViewBase): - fixtures = ['base/apps', - 'base/appversion', - 'base/featured', - 'users/test_backends'] + fixtures = ['base/appversion', 'base/featured', 'users/test_backends'] def test_edit_buttons(self): """Ensure admin/user edit buttons are shown.""" @@ -1190,7 +1187,7 @@ class TestProfileLinks(UserViewBase): class TestProfileSections(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/addon_3615', + fixtures = ['base/users', 'base/addon_3615', 'base/addon_5299_gcal', 'base/collections', 'reviews/dev-reply'] diff --git a/apps/versions/forms.py b/apps/versions/forms.py index 23a96be95e..16229d514e 100644 --- a/apps/versions/forms.py +++ b/apps/versions/forms.py @@ -93,7 +93,7 @@ class XPIForm(happyforms.Form): for app in apps: av = ApplicationsVersions.objects.create(version=version, - min=app.min, max=app.max, application_id=app.id) + min=app.min, max=app.max, application=app.id) amo.log(amo.LOG.ADD_APPVERSION, version, version.addon, app.appdata.short, av) diff --git a/apps/versions/models.py b/apps/versions/models.py index b1a82cfca8..076ffba1b4 100644 --- a/apps/versions/models.py +++ b/apps/versions/models.py @@ -126,7 +126,7 @@ class Version(amo.models.ModelBase): AV = ApplicationsVersions for app in data.get('apps', []): AV(version=v, min=app.min, max=app.max, - application_id=app.id).save() + application=app.id).save() if addon.type == amo.ADDON_SEARCH: # Search extensions are always for all platforms. platforms = [amo.PLATFORM_ALL.id] @@ -244,9 +244,9 @@ class Version(amo.models.ModelBase): The result is based on which app(s) the version targets. """ - apps = set([a.application.id for a in self.apps.all()]) - targets_mobile = amo.MOBILE.id in apps - targets_other = any((a != amo.MOBILE.id) for a in apps) + app_ids = [a.application for a in self.apps.all()] + targets_mobile = amo.MOBILE.id in app_ids + targets_other = any((id_ != amo.MOBILE.id) for id_ in app_ids) all_plats = {} if targets_other: all_plats.update(amo.DESKTOP_PLATFORMS) @@ -388,7 +388,7 @@ class Version(amo.models.ModelBase): def _compat_map(cls, avs): apps = {} for av in avs: - app_id = av.application_id + app_id = av.application if app_id in amo.APP_IDS: apps[amo.APP_IDS[app_id]] = av return apps @@ -613,7 +613,7 @@ class VersionComment(amo.models.ModelBase): class ApplicationsVersions(caching.base.CachingMixin, models.Model): - application = models.ForeignKey(Application) + application = models.PositiveIntegerField(db_column='application_id') version = models.ForeignKey(Version, related_name='apps') min = models.ForeignKey(AppVersion, db_column='min', related_name='min_set') @@ -626,9 +626,15 @@ class ApplicationsVersions(caching.base.CachingMixin, models.Model): db_table = u'applications_versions' unique_together = (("application", "version"),) + def get_application_display(self): + return unicode(amo.APPS_ALL[self.application].pretty) + def __unicode__(self): if (self.version.is_compatible[0] and - self.version.is_compatible_app(amo.APP_IDS[self.application.id])): - return _(u'{app} {min} and later').format(app=self.application, - min=self.min) - return u'%s %s - %s' % (self.application, self.min, self.max) + self.version.is_compatible_app(amo.APP_IDS[self.application])): + return _(u'{app} {min} and later').format( + app=self.get_application_display(), + min=self.min + ) + return u'%s %s - %s' % (self.get_application_display(), + self.min, self.max) diff --git a/apps/versions/tests.py b/apps/versions/tests.py index 2c12f235af..a9038a1c00 100644 --- a/apps/versions/tests.py +++ b/apps/versions/tests.py @@ -22,7 +22,7 @@ from amo.tests import addon_factory from amo.urlresolvers import reverse from addons.models import Addon, CompatOverride, CompatOverrideRange from addons.tests.test_views import TestMobile -from applications.models import AppVersion, Application +from applications.models import AppVersion from devhub.models import ActivityLog from files.models import File from files.tests.test_models import UploadTest @@ -85,7 +85,7 @@ def test_dict_from_int(): class TestVersion(amo.tests.TestCase): - fixtures = ['base/apps', 'base/addon_3615', 'base/admin'] + fixtures = ['base/addon_3615', 'base/admin'] def setUp(self): self.version = Version.objects.get(pk=81551) @@ -94,7 +94,7 @@ class TestVersion(amo.tests.TestCase): return [amo.PLATFORMS[i].shortname for i in ids] def target_mobile(self): - app = Application.objects.get(pk=amo.MOBILE.id) + app = amo.MOBILE.id app_vr = AppVersion.objects.create(application=app, version='1.0') ApplicationsVersions.objects.create(version=self.version, application=app, @@ -390,22 +390,20 @@ class TestVersion(amo.tests.TestCase): eq_(version.is_compatible_app(amo.UNKNOWN_APP), False) def test_compat_override_app_versions(self): - app = Application.objects.get(pk=1) addon = Addon.objects.get(id=3615) version = amo.tests.version_factory(addon=addon) co = CompatOverride.objects.create(addon=addon) - CompatOverrideRange.objects.create(compat=co, app=app, min_version='0', + CompatOverrideRange.objects.create(compat=co, app=1, min_version='0', max_version=version.version, min_app_version='10.0a1', max_app_version='10.*') eq_(version.compat_override_app_versions(), [('10.0a1', '10.*')]) def test_compat_override_app_versions_wildcard(self): - app = Application.objects.get(pk=1) addon = Addon.objects.get(id=3615) version = amo.tests.version_factory(addon=addon) co = CompatOverride.objects.create(addon=addon) - CompatOverrideRange.objects.create(compat=co, app=app, min_version='0', + CompatOverrideRange.objects.create(compat=co, app=1, min_version='0', max_version='*', min_app_version='10.0a1', max_app_version='10.*') @@ -425,7 +423,7 @@ class TestVersion(amo.tests.TestCase): class TestViews(amo.tests.TestCase): - fixtures = ['addons/eula+contrib-addon', 'base/apps'] + fixtures = ['addons/eula+contrib-addon'] def setUp(self): self.old_perpage = views.PER_PAGE @@ -480,7 +478,7 @@ class TestViews(amo.tests.TestCase): class TestFeeds(amo.tests.TestCase): - fixtures = ['addons/eula+contrib-addon', 'base/apps'] + fixtures = ['addons/eula+contrib-addon'] def test_feed_elements_present(self): """specific elements are present and reasonably well formed""" @@ -508,7 +506,7 @@ class TestFeeds(amo.tests.TestCase): class TestDownloadsBase(amo.tests.TestCase): - fixtures = ['base/apps', 'base/addon_5299_gcal', 'base/users'] + fixtures = ['base/addon_5299_gcal', 'base/users'] def setUp(self): self.addon = Addon.objects.get(id=5299) @@ -780,7 +778,7 @@ class TestDownloadSource(amo.tests.TestCase): class TestVersionFromUpload(UploadTest, amo.tests.TestCase): - fixtures = ['base/apps', 'base/addon_3615', 'base/users'] + fixtures = ['base/addon_3615', 'base/users'] def setUp(self): super(TestVersionFromUpload, self).setUp() @@ -789,7 +787,7 @@ class TestVersionFromUpload(UploadTest, amo.tests.TestCase): self.addon.update(guid='guid@xpi') self.platform = amo.PLATFORM_MAC.id for version in ('3.0', '3.6.*'): - AppVersion.objects.create(application_id=1, version=version) + AppVersion.objects.create(application=1, version=version) class TestExtensionVersionFromUpload(TestVersionFromUpload): diff --git a/apps/zadmin/forms.py b/apps/zadmin/forms.py index 3017f7bb80..e5ab161a61 100644 --- a/apps/zadmin/forms.py +++ b/apps/zadmin/forms.py @@ -19,7 +19,7 @@ from quieter_formset.formset import BaseModelFormSet import amo from addons.models import Addon from amo.urlresolvers import reverse -from applications.models import Application, AppVersion +from applications.models import AppVersion from bandwagon.models import Collection, FeaturedCollection, MonthlyPick from compat.forms import CompatForm as BaseCompatForm from files.models import File @@ -44,16 +44,17 @@ class DevMailerForm(happyforms.Form): class BulkValidationForm(happyforms.ModelForm): application = forms.ChoiceField( - label=_lazy(u'Application'), - choices=[(a.id, a.pretty) for a in amo.APPS_ALL.values()]) + label=_lazy(u'Application'), + choices=amo.APPS_CHOICES) curr_max_version = forms.ChoiceField( - label=_lazy(u'Current Max. Version'), - choices=[('', _lazy(u'Select an application first'))]) + label=_lazy(u'Current Max. Version'), + choices=[('', _lazy(u'Select an application first'))]) target_version = forms.ChoiceField( - label=_lazy(u'Target Version'), - choices=[('', _lazy(u'Select an application first'))]) - finish_email = forms.CharField(required=False, - label=_lazy(u'Email when finished')) + label=_lazy(u'Target Version'), + choices=[('', _lazy(u'Select an application first'))]) + finish_email = forms.CharField( + required=False, + label=_lazy(u'Email when finished')) class Meta: model = ValidationJob @@ -69,13 +70,12 @@ class BulkValidationForm(happyforms.ModelForm): w.attrs['data-url'] = reverse('zadmin.application_versions_json') def version_choices_for_app_id(self, app_id): - versions = AppVersion.objects.filter(application__id=app_id) + versions = AppVersion.objects.filter(application=app_id) return [(v.id, v.version) for v in versions] def clean_application(self): app_id = int(self.cleaned_data['application']) - app = Application.objects.get(pk=app_id) - self.cleaned_data['application'] = app + self.cleaned_data['application'] = app_id choices = self.version_choices_for_app_id(app_id) self.fields['target_version'].choices = choices self.fields['curr_max_version'].choices = choices @@ -136,7 +136,11 @@ class FeaturedCollectionForm(happyforms.ModelForm): (i, product_details.languages[i]['native']) for i in settings.AMO_LANGUAGES) - application = forms.ModelChoiceField(Application.objects.all()) + application = forms.ChoiceField( + amo.APPS_CHOICES, + error_messages={'invalid_choice': _lazy(u'Select a valid choice. That ' + u'choice is not one of the ' + u'available choices.')}) collection = forms.CharField(widget=forms.HiddenInput) locale = forms.ChoiceField(choices=LOCALES, required=False) diff --git a/apps/zadmin/models.py b/apps/zadmin/models.py index e244c3ad05..a008a45dd6 100644 --- a/apps/zadmin/models.py +++ b/apps/zadmin/models.py @@ -9,7 +9,7 @@ from django.utils.functional import memoize import amo import amo.models from amo.urlresolvers import reverse -from applications.models import Application, AppVersion +from applications.models import AppVersion from files.models import File _config_cache = {} @@ -49,7 +49,7 @@ def set_config(conf, value): class ValidationJob(amo.models.ModelBase): - application = models.ForeignKey(Application) + application = models.PositiveIntegerField(db_column='application_id') curr_max_version = models.ForeignKey(AppVersion, related_name='validation_current_set') target_version = models.ForeignKey(AppVersion, diff --git a/apps/zadmin/tasks.py b/apps/zadmin/tasks.py index cf3aa2f8d4..a5c3d84c9d 100644 --- a/apps/zadmin/tasks.py +++ b/apps/zadmin/tasks.py @@ -67,7 +67,7 @@ def tally_job_results(job_id, **kw): job.update(completed=datetime.now()) if job.finish_email: send_mail(u'Behold! Validation results for %s %s->%s' - % (amo.APP_IDS[job.application.id].pretty, + % (amo.APP_IDS[job.application].pretty, job.curr_max_version.version, job.target_version.version), textwrap.dedent(""" @@ -89,15 +89,14 @@ def bulk_validate_file(result_id, **kw): log.info('[1@None] Validating file %s (%s) for result_id %s' % (res.file, file_base, res.id)) target = res.validation_job.target_version - ver = {target.application.guid: [target.version]} + guid = amo.APP_IDS[target.application].guid + ver = {guid: [target.version]} # Set min/max so the validator only tests for compatibility with # the target version. Note that previously we explicitly checked # for compatibility with older versions. See bug 675306 for # the old behavior. - overrides = {'targetapp_minVersion': - {target.application.guid: target.version}, - 'targetapp_maxVersion': - {target.application.guid: target.version}} + overrides = {'targetapp_minVersion': {guid: target.version}, + 'targetapp_maxVersion': {guid: target.version}} validation = run_validator(res.file.file_path, for_appversions=ver, test_all_tiers=True, overrides=overrides, compat=True) @@ -148,7 +147,7 @@ def add_validation_jobs(pks, job_pk, **kw): prelim_app = list(amo.UNDER_REVIEW_STATUSES) + [amo.STATUS_BETA] for addon in Addon.objects.filter(pk__in=pks): ids = [] - base = addon.versions.filter(apps__application=job.application.id, + base = addon.versions.filter(apps__application=job.application, apps__max__version_int__gte=curr_ver, apps__max__version_int__lt=target_ver) @@ -159,7 +158,7 @@ def add_validation_jobs(pks, job_pk, **kw): log.info('Addon %s already has a public version %r which is ' 'compatible with target version of app %s %s (or newer)' % (addon.pk, [v.pk for v in already_compat.all()], - job.application.id, job.target_version)) + job.application, job.target_version)) continue try: @@ -226,7 +225,7 @@ def update_maxversions(version_pks, job_pk, data, **kw): job = ValidationJob.objects.get(pk=job_pk) set_user(get_task_user()) dry_run = data['preview_only'] - app_id = job.target_version.application.pk + app_id = job.target_version.application stats = collections.defaultdict(int) stats['processed'] = 0 stats['is_dry_run'] = int(dry_run) @@ -278,7 +277,7 @@ def notify_compatibility(users, job, data, **kw): % (len(users), notify_compatibility.rate_limit, job.pk)) set_user(get_task_user()) dry_run = data['preview_only'] - app_id = job.target_version.application.pk + app_id = job.target_version.application stats = collections.defaultdict(int) stats['processed'] = 0 stats['is_dry_run'] = int(dry_run) @@ -307,7 +306,7 @@ def notify_compatibility(users, job, data, **kw): context = Context({ - 'APPLICATION': str(job.application), + 'APPLICATION': unicode(amo.APP_IDS[job.application].pretty), 'VERSION': job.target_version.version, 'PASSING_ADDONS': user.passing_addons, 'FAILING_ADDONS': user.failing_addons, diff --git a/apps/zadmin/templates/zadmin/validation.html b/apps/zadmin/templates/zadmin/validation.html index daa2d3b7cf..cf916fa085 100644 --- a/apps/zadmin/templates/zadmin/validation.html +++ b/apps/zadmin/templates/zadmin/validation.html @@ -60,7 +60,7 @@ {{ job.pk }} {{ job.created }} {{ job.completed }} - {{ amo.APPS_ALL[job.application.id].pretty }} + {{ amo.APPS_ALL[job.application].pretty }} {{ job.curr_max_version.version }} {{ job.target_version.version }} {{ job.stats['total'] }} diff --git a/apps/zadmin/tests/test_views.py b/apps/zadmin/tests/test_views.py index 632231a8ba..2022d11bd5 100644 --- a/apps/zadmin/tests/test_views.py +++ b/apps/zadmin/tests/test_views.py @@ -143,7 +143,7 @@ class TestFlagged(amo.tests.TestCase): class BulkValidationTest(amo.tests.TestCase): - fixtures = ['base/apps', 'base/addon_3615', 'base/appversion', 'base/users'] + fixtures = ['base/addon_3615', 'base/appversion', 'base/users'] def setUp(self): assert self.client.login(username='admin@mozilla.com', @@ -172,7 +172,7 @@ class BulkValidationTest(amo.tests.TestCase): version=version) def create_job(self, **kwargs): - kw = dict(application_id=amo.FIREFOX.id, + kw = dict(application=amo.FIREFOX.id, curr_max_version=kwargs.pop('current', self.curr_max), target_version=kwargs.pop('target', self.appversion('3.7a3')), @@ -228,7 +228,7 @@ class TestBulkValidation(BulkValidationTest): self.assertNoFormErrors(r) self.assertRedirects(r, reverse('zadmin.validation')) job = ValidationJob.objects.get() - eq_(job.application_id, amo.FIREFOX.id) + eq_(job.application, amo.FIREFOX.id) eq_(job.curr_max_version.version, self.curr_max.version) eq_(job.target_version.version, new_max.version) eq_(job.finish_email, 'fliggy@mozilla.com') @@ -378,7 +378,7 @@ class TestBulkUpdate(BulkValidationTest): appver = AppVersion.objects.get(application=1, version='3.7a1pre') for v in self.version_one, self.version_two: ApplicationsVersions.objects.create( - application_id=amo.FIREFOX.id, version=v, + application=amo.FIREFOX.id, version=v, min=appver, max=appver) def test_no_update_link(self): @@ -478,7 +478,7 @@ class TestBulkUpdate(BulkValidationTest): def test_update_different_app(self): self.create_result(self.job, self.create_file(self.version)) target = self.version.apps.all()[0] - target.application_id = amo.FIREFOX.id + target.application = amo.FIREFOX.id target.save() eq_(self.version.apps.all()[0].max, self.curr_max) @@ -1151,7 +1151,7 @@ class TestEmailPreview(amo.tests.TestCase): class TestMonthlyPick(amo.tests.TestCase): - fixtures = ['base/addon_3615', 'base/apps', 'base/users'] + fixtures = ['base/addon_3615', 'base/users'] def setUp(self): assert self.client.login(username='admin@mozilla.com', @@ -1225,14 +1225,13 @@ class TestMonthlyPick(amo.tests.TestCase): class TestFeatures(amo.tests.TestCase): - fixtures = ['base/apps', 'base/users', 'base/collections', - 'base/addon_3615.json'] + fixtures = ['base/users', 'base/collections', 'base/addon_3615.json'] def setUp(self): assert self.client.login(username='admin@mozilla.com', password='password') self.url = reverse('zadmin.features') - FeaturedCollection.objects.create(application_id=amo.FIREFOX.id, + FeaturedCollection.objects.create(application=amo.FIREFOX.id, locale='zh-CN', collection_id=80) self.f = self.client.get(self.url).context['form'].initial_forms[0] self.initial = self.f.initial @@ -1716,7 +1715,7 @@ class TestCompat(amo.tests.ESTestCase): # Add an override for this current app version. compat = CompatOverride.objects.create(addon=addon, guid=addon.guid) CompatOverrideRange.objects.create(compat=compat, - app_id=amo.FIREFOX.id, min_app_version=self.app_version + 'a1', + app=amo.FIREFOX.id, min_app_version=self.app_version + 'a1', max_app_version=self.app_version + '*') # Check that there is an override for this current app version. @@ -1892,7 +1891,7 @@ class TestEmailDevs(amo.tests.TestCase): class TestPerms(amo.tests.TestCase): - fixtures = ['base/users', 'base/apps', 'zadmin/tests/flagged'] + fixtures = ['base/users', 'zadmin/tests/flagged'] def test_admin_user(self): # Admin should see views with Django's perm decorator and our own. diff --git a/apps/zadmin/views.py b/apps/zadmin/views.py index 6e6bb44dcd..3af93e590a 100644 --- a/apps/zadmin/views.py +++ b/apps/zadmin/views.py @@ -225,7 +225,7 @@ def find_files(job): addons = (Addon.objects.filter( status__in=amo.VALID_STATUSES, disabled_by_user=False, - versions__apps__application=job.application.id, + versions__apps__application=job.application, versions__apps__max__version_int__gte=current, versions__apps__max__version_int__lt=target) # Exclude lang packs and themes. diff --git a/lib/settings_base.py b/lib/settings_base.py index 8166307ca0..ae8bdf3f58 100644 --- a/lib/settings_base.py +++ b/lib/settings_base.py @@ -1066,7 +1066,7 @@ CUSTOM_DUMPS = { 'current_version.apps.all.0', 'addonuser_set.all.0', ], - 'order': ('applications.application', 'translations.translation', + 'order': ('translations.translation', 'files.platform', 'addons.addon', 'versions.license', 'versions.version', 'files.file'), 'excludes': { diff --git a/services/update.py b/services/update.py index 7ca38e2083..57e7050eb8 100644 --- a/services/update.py +++ b/services/update.py @@ -146,8 +146,7 @@ class Update(object): sql = [""" SELECT addons.guid as guid, addons.addontype_id as type, - addons.inactive as disabled_by_user, - applications.guid as appguid, appmin.version as min, + addons.inactive as disabled_by_user, appmin.version as min, appmax.version as max, files.id as file_id, files.status as file_status, files.hash, files.filename, versions.id as version_id, @@ -160,13 +159,12 @@ class Update(object): ON addons.id = versions.addon_id AND addons.id = %(id)s INNER JOIN applications_versions ON applications_versions.version_id = versions.id - INNER JOIN applications - ON applications_versions.application_id = applications.id - AND applications.id = %(app_id)s INNER JOIN appversions appmin ON appmin.id = applications_versions.min + AND appmin.application_id = %(app_id)s INNER JOIN appversions appmax ON appmax.id = applications_versions.max + AND appmax.application_id = %(app_id)s INNER JOIN files ON files.version_id = versions.id AND (files.platform_id = 1 """] @@ -283,7 +281,7 @@ class Update(object): if result: row = dict(zip([ - 'guid', 'type', 'disabled_by_user', 'appguid', 'min', 'max', + 'guid', 'type', 'disabled_by_user', 'min', 'max', 'file_id', 'file_status', 'hash', 'filename', 'version_id', 'datestatuschanged', 'strict_compat', 'releasenotes', 'version', 'premium_type'], @@ -291,6 +289,7 @@ class Update(object): row['type'] = base.ADDON_SLUGS_UPDATE[row['type']] row['url'] = get_mirror(data['addon_status'], data['id'], row) + row['appguid'] = applications.APPS_ALL[data['app_id']].guid data['row'] = row return True