def test_unreviewed_files_plus_reviewed_file(self): # We upgrade unreviewed files up to the latest reviewed file. v = Version.objects.create(addon_id=3615) new_file = File.objects.create(version=v, jetpack_version='1.0') Version.objects.create(addon_id=3615) new_file2 = File.objects.create(version=v, jetpack_version='1.0') eq_(new_file.status, amo.STATUS_UNREVIEWED) eq_(new_file2.status, amo.STATUS_UNREVIEWED) files = utils.find_jetpacks('1.0', '1.1') eq_(files, [self.file, new_file, new_file2]) assert all(f.needs_upgrade for f in files) # Now self.file will not need an upgrade since we skip old versions. new_file.update(status=amo.STATUS_PUBLIC) files = utils.find_jetpacks('1.0', '1.1') eq_(files, [self.file, new_file, new_file2]) eq_(files[0].needs_upgrade, False) assert all(f.needs_upgrade for f in files[1:])
def jetpack(request): upgrader = JetpackUpgrader() minver, maxver = upgrader.jetpack_versions() form = JetpackUpgradeForm(request.POST) if request.method == "POST": if form.is_valid(): if "minver" in request.POST: data = form.cleaned_data upgrader.jetpack_versions(data["minver"], data["maxver"]) elif "upgrade" in request.POST: if upgrader.version(maxver): start_upgrade(minver, maxver) elif "cancel" in request.POST: upgrader.cancel() return redirect("zadmin.jetpack") else: messages.error(request, form.errors.as_text()) jetpacks = find_jetpacks(minver, maxver, from_builder_only=True) upgrading = upgrader.version() # Current Jetpack version upgrading to. repack_status = upgrader.files() # The files being repacked. show = request.GET.get("show", upgrading or minver) subset = filter(lambda f: not f.needs_upgrade and f.jetpack_version == show, jetpacks) need_upgrade = filter(lambda f: f.needs_upgrade, jetpacks) repacked = [] if upgrading: # Group the repacked files by status for this Jetpack upgrade. grouped_files = sorted_groupby(repack_status.values(), key=lambda f: f["status"]) for group, rows in grouped_files: rows = sorted(list(rows), key=lambda f: f["file"]) for idx, row in enumerate(rows): rows[idx]["file"] = File.objects.get(id=row["file"]) repacked.append((group, rows)) groups = sorted_groupby(jetpacks, "jetpack_version") by_version = dict((version, len(list(files))) for version, files in groups) return jingo.render( request, "zadmin/jetpack.html", dict( form=form, upgrader=upgrader, by_version=by_version, upgrading=upgrading, need_upgrade=need_upgrade, subset=subset, show=show, repacked=repacked, repack_status=repack_status, ), )
def jetpack(request): upgrader = JetpackUpgrader() minver, maxver = upgrader.jetpack_versions() form = JetpackUpgradeForm(request.POST) if request.method == 'POST': if form.is_valid(): if 'minver' in request.POST: data = form.cleaned_data upgrader.jetpack_versions(data['minver'], data['maxver']) elif 'upgrade' in request.POST: if upgrader.version(maxver): start_upgrade(minver, maxver) elif 'cancel' in request.POST: upgrader.cancel() return redirect('zadmin.jetpack') else: messages.error(request, form.errors.as_text()) jetpacks = find_jetpacks(minver, maxver, from_builder_only=True) upgrading = upgrader.version() # Current Jetpack version upgrading to. repack_status = upgrader.files() # The files being repacked. show = request.GET.get('show', upgrading or minver) subset = filter( lambda f: not f.needs_upgrade and f.jetpack_version == show, jetpacks) need_upgrade = filter(lambda f: f.needs_upgrade, jetpacks) repacked = [] if upgrading: # Group the repacked files by status for this Jetpack upgrade. grouped_files = sorted_groupby(repack_status.values(), key=lambda f: f['status']) for group, rows in grouped_files: rows = sorted(list(rows), key=lambda f: f['file']) for idx, row in enumerate(rows): rows[idx]['file'] = File.objects.get(id=row['file']) repacked.append((group, rows)) groups = sorted_groupby(jetpacks, 'jetpack_version') by_version = dict((version, len(list(files))) for version, files in groups) return render( request, 'zadmin/jetpack.html', dict(form=form, upgrader=upgrader, by_version=by_version, upgrading=upgrading, need_upgrade=need_upgrade, subset=subset, show=show, repacked=repacked, repack_status=repack_status))
def test_skip_autorepackage(self): Addon.objects.update(auto_repackage=False) eq_(utils.find_jetpacks('1.0', '1.1'), [])
def test_find_builder_jetpacks_only(self): File.objects.update(builder_version='2.0.1') files = find_jetpacks('.1', '1.0', from_builder_only=True) eq_(files, [self.file])
def test_ignore_non_builder_jetpacks(self): File.objects.update(builder_version=None) files = find_jetpacks('.1', '1.0', from_builder_only=True) eq_(files, [])
def test_minver(self): files = find_jetpacks('1.1', '1.2') eq_(files, [self.file]) eq_(files[0].needs_upgrade, False)
def start_upgrade(minver, maxver): jetpacks = find_jetpacks(minver, maxver, from_builder_only=True) ids = [f.id for f in jetpacks if f.needs_upgrade] log.info('Starting a jetpack upgrade to %s [%s files].' % (maxver, len(ids))) start_upgrade_task.delay(ids, sdk_version=maxver)
def test_skip_autorepackage(self): Addon.objects.update(auto_repackage=False) eq_(find_jetpacks("1.0", "1.1"), [])
def test_success(self): files = utils.find_jetpacks('1.0', '1.1') eq_(files, [self.file])
def test_maxver(self): files = utils.find_jetpacks('.1', '1.0') eq_(files, [self.file]) eq_(files[0].needs_upgrade, False)
def test_maxver(self): files = find_jetpacks(".1", "1.0") eq_(files, [self.file]) eq_(files[0].needs_upgrade, False)
def test_success(self): files = find_jetpacks("1.0", "1.1") eq_(files, [self.file])