Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Add task to fix missing icons on existing apps (bug 879342)
Browse files Browse the repository at this point in the history
  • Loading branch information
diox committed Jun 21, 2013
1 parent 01d96bb commit 807b279
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
13 changes: 10 additions & 3 deletions apps/addons/management/commands/process_addons.py
Expand Up @@ -11,9 +11,10 @@
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 = {
Expand Down Expand Up @@ -63,6 +64,12 @@
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)]},
}


Expand Down
28 changes: 27 additions & 1 deletion mkt/webapps/tasks.py
Expand Up @@ -28,7 +28,8 @@
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

Expand Down Expand Up @@ -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)
46 changes: 46 additions & 0 deletions mkt/webapps/tests/test_tasks.py
Expand Up @@ -621,3 +621,49 @@ def test_update_developer_name_validation_error(self, _log, mock_parser):

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

0 comments on commit 807b279

Please sign in to comment.