Add task to fix missing icons on existing apps (bug 879342)
This commit is contained in:
Родитель
01d96bb20a
Коммит
807b279e06
|
@ -11,9 +11,10 @@ from amo.utils import chunked
|
|||
from devhub.tasks import convert_purified, flag_binary, get_preview_sizes
|
||||
from market.tasks import check_paypal, check_paypal_multiple
|
||||
|
||||
from mkt.webapps.tasks import (add_uuids, dump_apps, update_developer_name,
|
||||
update_features, update_manifests,
|
||||
update_supported_locales, zip_apps)
|
||||
from mkt.webapps.tasks import (add_uuids, dump_apps, fix_missing_icons,
|
||||
update_developer_name, update_features,
|
||||
update_manifests, update_supported_locales,
|
||||
zip_apps)
|
||||
|
||||
|
||||
tasks = {
|
||||
|
@ -63,6 +64,12 @@ tasks = {
|
|||
amo.STATUS_PUBLIC,
|
||||
amo.STATUS_PUBLIC_WAITING],
|
||||
disabled_by_user=False)]},
|
||||
'fix_missing_icons': {'method': fix_missing_icons,
|
||||
'qs': [Q(type=amo.ADDON_WEBAPP,
|
||||
status__in=[amo.STATUS_PENDING,
|
||||
amo.STATUS_PUBLIC,
|
||||
amo.STATUS_PUBLIC_WAITING],
|
||||
disabled_by_user=False)]},
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@ from lib.es.utils import get_indices
|
|||
from users.utils import get_task_user
|
||||
|
||||
from mkt.constants.regions import WORLDWIDE
|
||||
from mkt.developers.tasks import _fetch_manifest, run_validator, validator
|
||||
from mkt.developers.tasks import (fetch_icon, _fetch_manifest, run_validator,
|
||||
validator)
|
||||
from mkt.webapps.models import Webapp, WebappIndexer
|
||||
from mkt.webapps.utils import get_locale_properties
|
||||
|
||||
|
@ -439,3 +440,28 @@ def _update_developer_name(id):
|
|||
def update_developer_name(ids, **kw):
|
||||
for id in ids:
|
||||
_update_developer_name(id)
|
||||
|
||||
|
||||
def _fix_missing_icons(id):
|
||||
try:
|
||||
webapp = Webapp.objects.get(pk=id)
|
||||
except Webapp.DoesNotExist:
|
||||
_log(id, u'Webapp does not exist')
|
||||
return
|
||||
|
||||
# Check for missing icons. If we find one important size missing, call
|
||||
# fetch_icon for this app.
|
||||
dirname = webapp.get_icon_dir()
|
||||
destination = os.path.join(dirname, '%s' % webapp.id)
|
||||
for size in (64, 128):
|
||||
filename = '%s-%s.png' % (destination, size)
|
||||
if not storage.exists(filename):
|
||||
_log(id, u'Webapp is missing icon size %d' % (size, ))
|
||||
return fetch_icon(webapp)
|
||||
|
||||
|
||||
@task
|
||||
@write
|
||||
def fix_missing_icons(ids, **kw):
|
||||
for id in ids:
|
||||
_fix_missing_icons(id)
|
||||
|
|
|
@ -621,3 +621,49 @@ class TestUpdateDeveloperName(amo.tests.TestCase):
|
|||
|
||||
version = self.app.current_version.reload()
|
||||
eq_(version._developer_name, '')
|
||||
|
||||
|
||||
class TestFixMissingIcons(amo.tests.TestCase):
|
||||
fixtures = fixture('webapp_337141')
|
||||
|
||||
def setUp(self):
|
||||
self.app = Webapp.objects.get(pk=337141)
|
||||
|
||||
@mock.patch('mkt.webapps.tasks._fix_missing_icons')
|
||||
def test_ignore_not_webapp(self, mock_):
|
||||
self.app.update(type=amo.ADDON_EXTENSION)
|
||||
call_command('process_addons', task='fix_missing_icons')
|
||||
assert not mock_.called
|
||||
|
||||
@mock.patch('mkt.webapps.tasks._fix_missing_icons')
|
||||
def test_pending(self, mock_):
|
||||
self.app.update(status=amo.STATUS_PENDING)
|
||||
call_command('process_addons', task='fix_missing_icons')
|
||||
assert mock_.called
|
||||
|
||||
@mock.patch('mkt.webapps.tasks._fix_missing_icons')
|
||||
def test_public_waiting(self, mock_):
|
||||
self.app.update(status=amo.STATUS_PUBLIC_WAITING)
|
||||
call_command('process_addons', task='fix_missing_icons')
|
||||
assert mock_.called
|
||||
|
||||
@mock.patch('mkt.webapps.tasks._fix_missing_icons')
|
||||
def test_ignore_disabled(self, mock_):
|
||||
self.app.update(status=amo.STATUS_DISABLED)
|
||||
call_command('process_addons', task='fix_missing_icons')
|
||||
assert not mock_.called
|
||||
|
||||
@mock.patch('mkt.webapps.tasks.fetch_icon')
|
||||
@mock.patch('mkt.webapps.tasks._log')
|
||||
@mock.patch('mkt.webapps.tasks.storage.exists')
|
||||
def test_for_missing_size(self, exists, _log, fetch_icon):
|
||||
exists.return_value = False
|
||||
call_command('process_addons', task='fix_missing_icons')
|
||||
|
||||
# We are checking two sizes, but since the 64 has already failed for
|
||||
# this app, we should only have called exists() once, and we should
|
||||
# never have logged that the 128 icon is missing.
|
||||
eq_(exists.call_count, 1)
|
||||
assert _log.any_call(337141, 'Webapp is missing icon size 64')
|
||||
assert _log.any_call(337141, 'Webapp is missing icon size 128')
|
||||
assert fetch_icon.called
|
||||
|
|
Загрузка…
Ссылка в новой задаче