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

Commit f20cb91

Browse files
author
Rob Hudson
committed
Cleaned up status handling on version changes (bug 800086)
1 parent 1059014 commit f20cb91

File tree

4 files changed

+112
-3
lines changed

4 files changed

+112
-3
lines changed

apps/addons/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ def get_icon_url(self, size, use_default=True):
819819

820820
def update_status(self, using=None):
821821
if (self.status in [amo.STATUS_NULL, amo.STATUS_DELETED]
822-
or self.is_disabled or self.is_persona()):
822+
or self.is_disabled or self.is_persona() or self.is_webapp()):
823823
return
824824

825825
def logit(reason, old=self.status):

mkt/developers/tests/test_views_versions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import amo.tests
77
from addons.models import Addon, AddonUser
88
from devhub.models import ActivityLog
9+
from files.models import File
910
from users.models import UserProfile
1011
from versions.models import Version
1112

@@ -156,6 +157,20 @@ def test_unique_version(self):
156157
self.assertFormError(res, 'upload_form', 'upload',
157158
'Version 1.0 already exists')
158159

160+
def test_pending_on_new_version(self):
161+
# Test app rejection, then new version, updates app status to pending.
162+
self.app.current_version.update(version='0.9',
163+
created=self.days_ago(1))
164+
self.app.update(status=amo.STATUS_REJECTED)
165+
files = File.objects.filter(version__addon=self.app)
166+
files.update(status=amo.STATUS_DISABLED)
167+
self._post(302)
168+
version = self.app.versions.latest()
169+
eq_(version.version, '1.0')
170+
eq_(version.all_files[0].status, amo.STATUS_PENDING)
171+
self.app.update_status()
172+
eq_(self.app.status, amo.STATUS_PENDING)
173+
159174

160175
class TestEditVersion(amo.tests.TestCase):
161176
fixtures = ['base/users']

mkt/webapps/models.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,38 @@ def mark_done(self):
372372
"""When the submission process is done, update status accordingly."""
373373
self.update(status=amo.WEBAPPS_UNREVIEWED_STATUS)
374374

375+
def update_status(self, using=None):
376+
if self.is_deleted or self.is_disabled:
377+
return
378+
379+
def _log(reason, old=self.status):
380+
log.info(u'Update app status [%s]: %s => %s (%s).' % (
381+
self.id, old, self.status, reason))
382+
amo.log(amo.LOG.CHANGE_STATUS, self.get_status_display(), self)
383+
384+
# Handle the case of no versions.
385+
if not self.versions.exists():
386+
self.update(status=amo.STATUS_NULL)
387+
_log('no versions')
388+
return
389+
390+
# Handle the case of versions with no files.
391+
if not self.versions.filter(files__isnull=False).exists():
392+
self.update(status=amo.STATUS_NULL)
393+
_log('no versions with files')
394+
return
395+
396+
# If there are no public versions and at least one pending, set status
397+
# to pending.
398+
has_public = (
399+
self.versions.filter(files__status=amo.STATUS_PUBLIC).exists())
400+
has_pending = (
401+
self.versions.filter(files__status=amo.STATUS_PENDING).exists())
402+
if not has_public and has_pending:
403+
self.update(status=amo.STATUS_PENDING)
404+
_log('has pending but no public files')
405+
return
406+
375407
def authors_other_addons(self, app=None):
376408
"""Return other apps by the same author."""
377409
return (self.__class__.objects.visible()

mkt/webapps/tests/test_models.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import zipfile
55

66
from django.conf import settings
7+
from django.db.models.signals import post_delete, post_save
78

89
import mock
910
import waffle
@@ -12,7 +13,8 @@
1213

1314
import amo
1415
from addons.models import (Addon, AddonCategory, AddonDeviceType, AddonPremium,
15-
BlacklistedSlug, Category, Preview)
16+
BlacklistedSlug, Category, Preview, version_changed)
17+
from addons.signals import version_changed as version_changed_signal
1618
from amo.tests import app_factory, version_factory
1719
from constants.applications import DEVICE_TYPES
1820
from editors.models import RereviewQueue
@@ -21,7 +23,7 @@
2123
from lib.crypto.tests import mock_sign
2224
from market.models import Price
2325
from users.models import UserProfile
24-
from versions.models import Version
26+
from versions.models import update_status, Version
2527

2628
import mkt
2729
from mkt.submit.tests.test_views import BasePackagedAppTest, BaseWebAppTest
@@ -928,3 +930,63 @@ def test_packaged_reviewer(self, sign):
928930
reviewer=True)
929931
eq_(sign.call_args[0][0], self.app.current_version.pk)
930932
eq_(sign.call_args[1]['reviewer'], True)
933+
934+
935+
class TestUpdateStatus(amo.tests.TestCase):
936+
937+
def setUp(self):
938+
# Disabling signals to simplify these tests and because create doesn't
939+
# call the signals anyway.
940+
version_changed_signal.disconnect(version_changed,
941+
dispatch_uid='version_changed')
942+
post_save.disconnect(update_status, sender=Version,
943+
dispatch_uid='version_update_status')
944+
post_delete.disconnect(update_status, sender=Version,
945+
dispatch_uid='version_update_status')
946+
947+
def tearDown(self):
948+
version_changed_signal.connect(version_changed,
949+
dispatch_uid='version_changed')
950+
post_save.connect(update_status, sender=Version,
951+
dispatch_uid='version_update_status')
952+
post_delete.connect(update_status, sender=Version,
953+
dispatch_uid='version_update_status')
954+
955+
def test_no_versions(self):
956+
app = Webapp.objects.create(status=amo.STATUS_PUBLIC)
957+
app.update_status()
958+
eq_(app.status, amo.STATUS_NULL)
959+
960+
def test_version_no_files(self):
961+
app = Webapp.objects.create(status=amo.STATUS_PUBLIC)
962+
Version(addon=app).save()
963+
app.update_status()
964+
eq_(app.status, amo.STATUS_NULL)
965+
966+
def test_only_version_deleted(self):
967+
app = amo.tests.app_factory(status=amo.STATUS_REJECTED)
968+
app.current_version.delete()
969+
app.update_status()
970+
eq_(app.status, amo.STATUS_NULL)
971+
972+
def test_other_version_deleted(self):
973+
app = amo.tests.app_factory(status=amo.STATUS_REJECTED)
974+
amo.tests.version_factory(addon=app)
975+
app.current_version.delete()
976+
app.update_status()
977+
eq_(app.status, amo.STATUS_REJECTED)
978+
979+
def test_one_version_pending(self):
980+
app = amo.tests.app_factory(status=amo.STATUS_REJECTED,
981+
file_kw=dict(status=amo.STATUS_DISABLED))
982+
amo.tests.version_factory(addon=app,
983+
file_kw=dict(status=amo.STATUS_PENDING))
984+
app.update_status()
985+
eq_(app.status, amo.STATUS_PENDING)
986+
987+
def test_one_version_public(self):
988+
app = amo.tests.app_factory(status=amo.STATUS_PUBLIC)
989+
amo.tests.version_factory(addon=app,
990+
file_kw=dict(status=amo.STATUS_DISABLED))
991+
app.update_status()
992+
eq_(app.status, amo.STATUS_PUBLIC)

0 commit comments

Comments
 (0)