diff --git a/apps/addons/management/commands/process_addons.py b/apps/addons/management/commands/process_addons.py index c3dfb19dc6..50888d13ff 100644 --- a/apps/addons/management/commands/process_addons.py +++ b/apps/addons/management/commands/process_addons.py @@ -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)]}, } diff --git a/mkt/webapps/tasks.py b/mkt/webapps/tasks.py index 7b9144f0f8..c0c81feaaf 100644 --- a/mkt/webapps/tasks.py +++ b/mkt/webapps/tasks.py @@ -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) diff --git a/mkt/webapps/tests/test_tasks.py b/mkt/webapps/tests/test_tasks.py index 0a780f195d..95780749e3 100644 --- a/mkt/webapps/tests/test_tasks.py +++ b/mkt/webapps/tests/test_tasks.py @@ -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