Skip to content

Commit

Permalink
Merge pull request mozilla#256 from yohanboniface/1062958-rm-platform
Browse files Browse the repository at this point in the history
Remove files.Platform model (bug 1062958)
  • Loading branch information
magopian committed Sep 17, 2014
2 parents d4f3e33 + ff8dfd4 commit 8138776
Show file tree
Hide file tree
Showing 66 changed files with 233 additions and 551 deletions.
2 changes: 1 addition & 1 deletion apps/addons/buttons.py
Expand Up @@ -174,7 +174,7 @@ def links(self):
return rv

def file_details(self, file):
platform = file.platform_id
platform = file.platform
if self.latest and (
self.addon.status == file.status == amo.STATUS_PUBLIC):
url = file.latest_xpi_url()
Expand Down
8 changes: 0 additions & 8 deletions apps/addons/fixtures/addons/eula+contrib-addon.json
Expand Up @@ -84,14 +84,6 @@
"_current_version": 68776
}
},
{
"pk": 1,
"model": "files.platform",
"fields": {
"modified": "2008-04-07 08:16:55",
"created": "2007-03-05 13:09:27"
}
},
{
"pk": 68776,
"model": "versions.version",
Expand Down
24 changes: 0 additions & 24 deletions apps/addons/fixtures/addons/invalid_latest_version.json
Expand Up @@ -58,14 +58,6 @@
"the_reason": null
}
},
{
"pk": 1,
"model": "files.platform",
"fields": {
"modified": "2008-04-07 08:16:55",
"created": "2007-03-05 13:09:27"
}
},
{
"pk": 98217,
"model": "versions.version",
Expand All @@ -78,22 +70,6 @@
"addon": 3895
}
},
{
"pk": 2,
"model": "files.platform",
"fields": {
"modified": "2008-04-07 08:16:55",
"created": "2007-03-05 13:09:27"
}
},
{
"pk": 5,
"model": "files.platform",
"fields": {
"modified": "2008-04-07 08:16:56",
"created": "2007-03-05 13:09:27"
}
},
{
"pk": 78829,
"model": "versions.version",
Expand Down
8 changes: 0 additions & 8 deletions apps/addons/fixtures/addons/test_manager.json
Expand Up @@ -215,14 +215,6 @@
"addon": 1
}
},
{
"pk": 1,
"model": "files.platform",
"fields": {
"modified": "2008-04-07 08:16:55",
"created": "2007-03-05 13:09:27"
}
},
{
"pk": 11993,
"model": "files.file",
Expand Down
23 changes: 12 additions & 11 deletions apps/addons/tests/test_buttons.py
Expand Up @@ -44,10 +44,10 @@ def setUp(self):
v.version = 'v1'
self.addon.current_version = v

self.file = self.get_file(amo.PLATFORM_ALL)
self.file = self.get_file(amo.PLATFORM_ALL.id)
v.all_files = [self.file]

self.platforms = amo.PLATFORM_MAC, amo.PLATFORM_LINUX
self.platforms = amo.PLATFORM_MAC.id, amo.PLATFORM_LINUX.id
self.platform_files = map(self.get_file, self.platforms)

self.request = Mock()
Expand Down Expand Up @@ -79,7 +79,7 @@ def render(self, **kwargs):

def get_file(self, platform):
file = Mock()
file.platform_id = platform.id
file.platform = platform
file.latest_xpi_url.return_value = 'xpi.latest'
file.get_url_path.return_value = 'xpi.url'
file.eula_url.return_value = 'eula.url'
Expand Down Expand Up @@ -278,7 +278,7 @@ def test_after_no_show_contrib(self):
eq_(b.attrs(), {})

def test_file_details(self):
file = self.get_file(amo.PLATFORM_ALL)
file = self.get_file(amo.PLATFORM_ALL.id)
self.addon.meet_the_dev_url.return_value = 'meet.dev'
b = self.get_button()

Expand All @@ -289,7 +289,7 @@ def test_file_details(self):
eq_(os, None)

# Platformer.
file = self.get_file(amo.PLATFORM_MAC)
file = self.get_file(amo.PLATFORM_MAC.id)
_, _, os = b.file_details(file)
eq_(os, amo.PLATFORM_MAC)

Expand All @@ -306,7 +306,7 @@ def test_file_details(self):
'/en-US/firefox/addon/2/contribute/roadblock/?version=v1')

def test_file_details_unreviewed(self):
file = self.get_file(amo.PLATFORM_ALL)
file = self.get_file(amo.PLATFORM_ALL.id)
file.status = amo.STATUS_UNREVIEWED
b = self.get_button()

Expand All @@ -333,7 +333,7 @@ def test_links(self):
links = self.get_button().links()

eq_(len(links), len(self.platforms))
eq_([x.os for x in links], list(self.platforms))
eq_([x.os.id for x in links], list(self.platforms))

def test_link_with_invalid_file(self):
self.version.all_files = self.platform_files
Expand All @@ -342,7 +342,7 @@ def test_link_with_invalid_file(self):

expected_platforms = self.platforms[1:]
eq_(len(links), len(expected_platforms))
eq_([x.os for x in links], list(expected_platforms))
eq_([x.os.id for x in links], list(expected_platforms))

def test_no_version(self):
self.addon.current_version = None
Expand Down Expand Up @@ -434,8 +434,9 @@ def test_multi_platform(self):
eq_(doc('.button').length, 2)

for platform in self.platforms:
os = doc('.button.%s .os' % platform.shortname).attr('data-os')
eq_(platform.name, os)
os = doc('.button.%s .os' %
amo.PLATFORMS[platform].shortname).attr('data-os')
eq_(amo.PLATFORMS[platform].name, os)

def test_compatible_apps(self):
compat = Mock()
Expand Down Expand Up @@ -538,7 +539,7 @@ def setUp(self):

def get_backup_file(self):
file = Mock()
file.platform_id = amo.PLATFORM_ALL.id
file.platform = amo.PLATFORM_ALL.id
file.latest_xpi_url.return_value = 'xpi.backup'
file.get_url_path.return_value = 'xpi.backup.url'
file.status = amo.STATUS_PUBLIC
Expand Down
7 changes: 2 additions & 5 deletions apps/addons/tests/test_cron.py
@@ -1,18 +1,15 @@
import os
import datetime

from nose.exc import SkipTest
from nose.tools import eq_
import mock

from django.conf import settings

import amo
import amo.tests
from addons import cron
from addons.models import Addon, AppSupport
from django.core.management.base import CommandError
from files.models import File, Platform
from files.models import File
from lib.es.utils import flag_reindexing_amo, unflag_reindexing_amo
from stats.models import UpdateCount
from versions.models import Version
Expand Down Expand Up @@ -119,7 +116,7 @@ class TestHideDisabledFiles(amo.tests.TestCase):
msg = 'Moving disabled file: %s => %s'

def setUp(self):
p = Platform.objects.create(id=amo.PLATFORM_ALL.id)
p = amo.PLATFORM_ALL.id
self.addon = Addon.objects.create(type=amo.ADDON_EXTENSION)
self.version = Version.objects.create(addon=self.addon)
self.f1 = File.objects.create(version=self.version, platform=p,
Expand Down
2 changes: 1 addition & 1 deletion apps/addons/tests/test_forms.py
Expand Up @@ -86,7 +86,7 @@ def test_slug_isdigit(self):


class TestTagsForm(amo.tests.TestCase):
fixtures = ['base/addon_3615', 'base/platforms', 'base/users']
fixtures = ['base/addon_3615', 'base/users']

def setUp(self):
self.addon = Addon.objects.get(pk=3615)
Expand Down
26 changes: 10 additions & 16 deletions apps/addons/tests/test_models.py
Expand Up @@ -31,7 +31,7 @@
from constants.applications import DEVICE_TYPES
from devhub.models import ActivityLog, AddonLog, RssKey, SubmitStep
from editors.models import EscalationQueue
from files.models import File, Platform
from files.models import File
from files.tests.test_models import UploadTest
from reviews.models import Review, ReviewFlag
from translations.models import Translation, TranslationSequence
Expand Down Expand Up @@ -300,7 +300,6 @@ class TestAddonModels(amo.tests.TestCase):
'base/appversion',
'base/collections',
'base/featured',
'base/platforms',
'base/users',
'base/addon_5299_gcal',
'base/addon_3615',
Expand Down Expand Up @@ -1504,7 +1503,6 @@ def test_review_delete(self):


class TestUpdateStatus(amo.tests.TestCase):
fixtures = ['base/platforms', ]

def test_no_file_ends_with_NULL(self):
addon = Addon.objects.create(type=amo.ADDON_EXTENSION)
Expand Down Expand Up @@ -1624,8 +1622,7 @@ def test_featured_random(self):


class TestBackupVersion(amo.tests.TestCase):
fixtures = ['addons/update', 'base/apps', 'base/appversion',
'base/platforms']
fixtures = ['addons/update', 'base/apps', 'base/appversion']

def setUp(self):
self.version_1_2_0 = 105387
Expand Down Expand Up @@ -1823,7 +1820,6 @@ def test_scores(self):
class TestAddonDependencies(amo.tests.TestCase):
fixtures = ['base/apps',
'base/appversion',
'base/platforms',
'base/users',
'base/addon_5299_gcal',
'base/addon_3615',
Expand Down Expand Up @@ -1863,7 +1859,6 @@ def test_listed_two_versions(self):
class TestFlushURLs(amo.tests.TestCase):
fixtures = ['base/apps',
'base/appversion',
'base/platforms',
'base/users',
'base/addon_5579',
'base/previews',
Expand Down Expand Up @@ -1915,7 +1910,7 @@ def setUp(self):
super(TestAddonFromUpload, self).setUp()
u = UserProfile.objects.get(pk=999)
set_user(u)
self.platform = Platform.objects.create(id=amo.PLATFORM_MAC.id)
self.platform = amo.PLATFORM_MAC.id
for version in ('3.0', '3.6.*'):
AppVersion.objects.create(application_id=1, version=version)
self.addCleanup(translation.deactivate)
Expand Down Expand Up @@ -1948,17 +1943,16 @@ def test_xpi_version(self):
[self.platform])
v = addon.versions.get()
eq_(v.version, '0.1')
eq_(v.files.get().platform_id, self.platform.id)
eq_(v.files.get().platform, self.platform)
eq_(v.files.get().status, amo.STATUS_UNREVIEWED)

def test_xpi_for_multiple_platforms(self):
platforms = [Platform.objects.get(pk=amo.PLATFORM_LINUX.id),
Platform.objects.get(pk=amo.PLATFORM_MAC.id)]
platforms = [amo.PLATFORM_LINUX.id, amo.PLATFORM_MAC.id]
addon = Addon.from_upload(self.get_upload('extension.xpi'),
platforms)
v = addon.versions.get()
eq_(sorted([f.platform.id for f in v.all_files]),
sorted([p.id for p in platforms]))
eq_(sorted([f.platform for f in v.all_files]),
sorted(platforms))

def test_search_attributes(self):
addon = Addon.from_upload(self.get_upload('search.xml'),
Expand All @@ -1977,7 +1971,7 @@ def test_search_version(self):
[self.platform])
v = addon.versions.get()
eq_(v.version, datetime.now().strftime('%Y%m%d'))
eq_(v.files.get().platform_id, amo.PLATFORM_ALL.id)
eq_(v.files.get().platform, amo.PLATFORM_ALL.id)
eq_(v.files.get().status, amo.STATUS_UNREVIEWED)

def test_no_homepage(self):
Expand Down Expand Up @@ -2226,8 +2220,8 @@ def setUp(self):
super(TestLanguagePack, self).setUp()
self.addon = amo.tests.addon_factory(type=amo.ADDON_LPAPP,
status=amo.STATUS_PUBLIC)
self.platform_all = Platform.objects.get(id=amo.PLATFORM_ALL.id)
self.platform_mob = Platform.objects.create(id=amo.PLATFORM_ANDROID.id)
self.platform_all = amo.PLATFORM_ALL.id
self.platform_mob = amo.PLATFORM_ANDROID.id
self.version = self.addon.current_version

def test_extract(self):
Expand Down

0 comments on commit 8138776

Please sign in to comment.