Browse files

move hide disabled file off signal and cope with beta (bug 637863)

  • Loading branch information...
1 parent 31baebf commit 4c19b37657fe112fa8f8bfd03f117489c9250bc4 @andymckay andymckay committed Mar 21, 2011
Showing with 52 additions and 9 deletions.
  1. +11 −8 apps/versions/models.py
  2. +41 −1 apps/versions/tests.py
View
19 apps/versions/models.py
@@ -80,6 +80,8 @@ def from_upload(cls, upload, addon, platforms):
platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)]
for platform in platforms:
File.from_upload(upload, v, platform, parse_data=data)
+
+ v.disable_old_files()
# After the upload has been copied to all
# platforms, remove the upload.
upload.path.unlink()
@@ -200,6 +202,15 @@ def rollup(xs):
version.compatible_apps = cls._compat_map(av_dict.get(v_id, []))
version.all_files = file_dict.get(v_id, [])
+ def disable_old_files(self):
+ if not self.files.filter(status=amo.STATUS_BETA).exists():
+ qs = File.objects.filter(version__addon=self.addon_id,
+ version__lt=self,
+ status=amo.STATUS_UNREVIEWED)
+ # Use File.update so signals are triggered.
+ for f in qs:
+ f.update(status=amo.STATUS_DISABLED)
+
def update_status(sender, instance, **kw):
if not kw.get('raw'):
@@ -208,14 +219,6 @@ def update_status(sender, instance, **kw):
instance.addon.update_version()
except models.ObjectDoesNotExist:
pass
- if kw.get('created'):
- # Disable older unreviewed files for this add-on.
- qs = File.objects.filter(version__addon=instance.addon_id,
- version__lt=instance,
- status=amo.STATUS_UNREVIEWED)
- # Use File.update so signals are triggered.
- for f in qs:
- f.update(status=amo.STATUS_DISABLED)
models.signals.post_save.connect(update_status, sender=Version,
View
42 apps/versions/tests.py
@@ -205,11 +205,22 @@ def test_new_version_disable_old_unreviewed(self, hide_mock):
assert not hide_mock.called
qs.update(status=amo.STATUS_UNREVIEWED)
- Version.objects.create(addon=addon)
+ version = Version.objects.create(addon=addon)
+ version.disable_old_files()
eq_(qs.all()[0].status, amo.STATUS_DISABLED)
addon.current_version.all_files[0]
assert hide_mock.called
+ def test_new_version_beta(self):
+ addon = Addon.objects.get(id=3615)
+ qs = File.objects.filter(version=addon.current_version)
+ qs.update(status=amo.STATUS_UNREVIEWED)
+
+ version = Version.objects.create(addon=addon)
+ File.objects.create(version=version, status=amo.STATUS_BETA)
+ version.disable_old_files()
+ eq_(qs.all()[0].status, amo.STATUS_UNREVIEWED)
+
def test_version_int(self):
version = Version.objects.get(pk=81551)
version.save()
@@ -626,6 +637,35 @@ def test_file_platform_is_always_all(self):
eq_(files[0].platform.id, amo.PLATFORM_ALL.id)
+class TestStatusFromUpload(TestVersionFromUpload):
+ filename = 'extension.xpi'
+
+ def setUp(self):
+ super(TestStatusFromUpload, self).setUp()
+ self.current = self.addon.current_version
+ # We need one public file to stop the addon update signal
+ # moving the addon away from public. Only public addons check
+ # for beta status on from_upload.
+ self.current.files.all().update(status=amo.STATUS_UNREVIEWED)
+ File.objects.create(version=self.current, status=amo.STATUS_PUBLIC)
+ self.addon.update(status=amo.STATUS_PUBLIC)
+
+ def test_status(self):
+ qs = File.objects.filter(version=self.current)
+ Version.from_upload(self.upload, self.addon, [self.platform])
+ eq_(sorted([q.status for q in qs.all()]),
+ [amo.STATUS_PUBLIC, amo.STATUS_DISABLED])
+
+ @mock.patch('files.utils.parse_addon')
+ def test_status_beta(self, parse_addon):
+ parse_addon.return_value = {'version': u'0.1beta'}
+
+ qs = File.objects.filter(version=self.current)
+ Version.from_upload(self.upload, self.addon, [self.platform])
+ eq_(sorted([q.status for q in qs.all()]),
+ [amo.STATUS_UNREVIEWED, amo.STATUS_PUBLIC])
+
+
class TestMobileVersions(TestMobile):
def test_versions(self):

0 comments on commit 4c19b37

Please sign in to comment.